1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.maven.api.cli; 20 21 import org.apache.maven.api.annotations.Experimental; 22 import org.apache.maven.api.annotations.Nonnull; 23 24 /** 25 * Defines the contract for a component responsible for invoking a Maven application 26 * using the information provided in an {@link InvokerRequest}. This interface is central 27 * to the construction and invocation of Maven commands and builds, and it fully parses arguments. 28 * 29 * <p>The Invoker is designed to be flexible, allowing for different implementations 30 * that can handle various types of {@link InvokerRequest InvokerRequests}. It also implements 31 * {@link AutoCloseable} to ensure proper resource management.</p> 32 * 33 * @since 4.0.0 34 */ 35 @Experimental 36 public interface Invoker extends AutoCloseable { 37 /** 38 * Invokes the Maven application using the provided {@link InvokerRequest}. 39 * This method is responsible for executing the Maven command or build 40 * process based on the information contained in the request. 41 * 42 * @param invokerRequest the request containing all necessary information for the invocation 43 * @return an integer representing the exit code of the invocation (0 typically indicates success) 44 * @throws InvokerException if an error occurs during the invocation process 45 */ 46 int invoke(@Nonnull InvokerRequest invokerRequest) throws InvokerException; 47 48 /** 49 * Closes and disposes of this {@link Invoker} instance, releasing any resources it may hold. 50 * This method is called automatically when using try-with-resources statements. 51 * 52 * <p>The default implementation does nothing. Subclasses should override this method 53 * if they need to perform cleanup operations.</p> 54 * 55 * @throws InvokerException if an error occurs while closing the {@link Invoker} 56 */ 57 @Override 58 default void close() throws InvokerException {} 59 }