|
| 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 execution of Maven commands and builds. |
| 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 | + * @param <R> The specific type of {@link InvokerRequest} this {@code Invoker} can handle, extending {@link InvokerRequest} |
| 34 | + * |
| 35 | + * @since 4.0.0 |
| 36 | + */ |
| 37 | +@Experimental |
| 38 | +public interface Invoker<R extends InvokerRequest<? extends Options>> extends AutoCloseable { |
| 39 | + /** |
| 40 | + * Invokes the Maven application using the provided {@link InvokerRequest}. |
| 41 | + * This method is responsible for executing the Maven command or build |
| 42 | + * process based on the information contained in the request. |
| 43 | + * |
| 44 | + * @param invokerRequest the request containing all necessary information for the invocation |
| 45 | + * @return an integer representing the exit code of the invocation (0 typically indicates success) |
| 46 | + * @throws InvokerException if an error occurs during the invocation process |
| 47 | + */ |
| 48 | + int invoke(@Nonnull R invokerRequest) throws InvokerException; |
| 49 | + |
| 50 | + /** |
| 51 | + * Closes and disposes of this {@link Invoker} instance, releasing any resources it may hold. |
| 52 | + * This method is called automatically when using try-with-resources statements. |
| 53 | + * |
| 54 | + * <p>The default implementation does nothing. Subclasses should override this method |
| 55 | + * if they need to perform cleanup operations.</p> |
| 56 | + * |
| 57 | + * @throws InvokerException if an error occurs while closing the {@link Invoker} |
| 58 | + */ |
| 59 | + @Override |
| 60 | + default void close() throws InvokerException {} |
| 61 | +} |
0 commit comments