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.shared.invoker; 20 21 import java.io.File; 22 import java.io.InputStream; 23 24 /** 25 * Provides a facade to invoke Maven. 26 * 27 */ 28 public interface Invoker { 29 30 /** 31 * The role name used to register implementations of this interface within Plexus. 32 */ 33 String ROLE = Invoker.class.getName(); 34 35 /** 36 * Executes Maven using the parameters specified by the given invocation request. Parameters not specified by the 37 * invocation request will be derived from the state of this invoker instance. In case both the invoker instance and 38 * the invocation request provide a value for a particular option, the value from the invocation request dominates. 39 * 40 * @param request The invocation request to execute, must not be <code>null</code>. 41 * @return The result of the Maven invocation, never <code>null</code>. 42 * @throws MavenInvocationException if cannot configure correctly execution parameters 43 */ 44 InvocationResult execute(InvocationRequest request) throws MavenInvocationException; 45 46 /** 47 * Gets the path to the base directory of the local repository to use for the Maven invocation. 48 * 49 * @return The path to the base directory of the local repository or <code>null</code> to use the location from 50 * the <code>settings.xml</code>. 51 */ 52 File getLocalRepositoryDirectory(); 53 54 /** 55 * Gets the working directory for the Maven invocation. 56 * 57 * @return The working directory for the Maven invocation or <code>null</code> if the working directory is derived 58 * from the base directory of the processed POM. 59 */ 60 File getWorkingDirectory(); 61 62 /** 63 * Gets the logger used by this invoker to output diagnostic messages. 64 * 65 * @return The logger used by this invoker to output diagnostic messages, never <code>null</code>. 66 */ 67 InvokerLogger getLogger(); 68 69 /** 70 * Gets the path to the base directory of the Maven installation used to invoke Maven. 71 * 72 * @return The path to the base directory of the Maven installation or <code>null</code> if using the default 73 * Maven installation. 74 */ 75 File getMavenHome(); 76 77 /** 78 * Sets the path to the base directory of the Maven installation used to invoke Maven. This parameter may be left 79 * unspecified to use the default Maven installation which will be discovered by evaluating the system property 80 * <code>maven.home</code>. 81 * 82 * @param mavenHome The path to the base directory of the Maven installation, may be <code>null</code> to use the 83 * default Maven installation. 84 * @return This invoker instance. 85 */ 86 Invoker setMavenHome(File mavenHome); 87 88 /** 89 * Get the customized File of the Maven executable. 90 * 91 * @return the custom Maven executable, otherwise {@code null} 92 */ 93 File getMavenExecutable(); 94 95 /** 96 * {@code mavenExecutable} can either be a file relative to ${maven.home}/bin/ or an absolute file. 97 * 98 * @param mavenExecutable the executable 99 * @return This invoker instance 100 */ 101 Invoker setMavenExecutable(File mavenExecutable); 102 103 /** 104 * Sets the path to the base directory of the local repository to use for the Maven invocation. 105 * 106 * @param localRepositoryDirectory The path to the base directory of the local repository or <code>null</code> to 107 * use the location from the <code>settings.xml</code>. 108 * @return This invoker instance. 109 */ 110 Invoker setLocalRepositoryDirectory(File localRepositoryDirectory); 111 112 /** 113 * Sets the logger used by this invoker to output diagnostic messages. 114 * 115 * @param logger The logger used by this invoker to output diagnostic messages, may be <code>null</code> to use a 116 * default logger. 117 * @return This invoker instance. 118 */ 119 Invoker setLogger(InvokerLogger logger); 120 121 /** 122 * Sets the working directory for the Maven invocation. 123 * 124 * @param workingDirectory The working directory for the Maven invocation, may be <code>null</code> to derive the 125 * working directory from the base directory of the processed POM. 126 * @return This invoker instance. 127 * 128 * @deprecated Please use {@link InvocationRequest#setBaseDirectory(File)} 129 */ 130 @Deprecated 131 Invoker setWorkingDirectory(File workingDirectory); 132 133 /** 134 * Sets the input stream used to provide input for the invoked Maven build. This is in particular useful when 135 * invoking Maven in interactive mode. 136 * 137 * @param inputStream The input stream used to provide input for the invoked Maven build, may be <code>null</code> 138 * if not required. 139 * @return This invoker instance. 140 * 141 * @deprecated Please use {@link InvocationRequest#setInputStream(InputStream)} 142 */ 143 @Deprecated 144 Invoker setInputStream(InputStream inputStream); 145 146 /** 147 * Sets the handler used to capture the standard output from the Maven build. 148 * 149 * @param outputHandler The output handler, may be <code>null</code> if the output is not of interest. 150 * @return This invoker instance. 151 * 152 * @deprecated Please use {@link InvocationRequest#setOutputHandler(InvocationOutputHandler)} 153 */ 154 @Deprecated 155 Invoker setOutputHandler(InvocationOutputHandler outputHandler); 156 157 /** 158 * Sets the handler used to capture the error output from the Maven build. 159 * 160 * @param errorHandler The error handler, may be <code>null</code> if the output is not of interest. 161 * @return This invoker instance. 162 * 163 * @deprecated Pleas use {@link InvocationRequest#setErrorHandler(InvocationOutputHandler)} 164 */ 165 @Deprecated 166 Invoker setErrorHandler(InvocationOutputHandler errorHandler); 167 }