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 java.io.InputStream; 22 import java.io.OutputStream; 23 import java.nio.file.Path; 24 import java.util.List; 25 import java.util.Map; 26 import java.util.Optional; 27 28 import org.apache.maven.api.annotations.Experimental; 29 import org.apache.maven.api.annotations.Immutable; 30 import org.apache.maven.api.annotations.Nonnull; 31 import org.apache.maven.api.cli.extensions.CoreExtension; 32 import org.apache.maven.api.services.Lookup; 33 import org.apache.maven.api.services.MessageBuilderFactory; 34 35 /** 36 * Represents a Maven execution request, encapsulating all necessary information 37 * for invoking a Maven build or command. 38 * 39 * @param <O> the type of {@link Options} used for this request, extending the base {@link Options} interface 40 * 41 * @since 4.0.0 42 */ 43 @Immutable 44 @Experimental 45 public interface InvokerRequest<O extends Options> { 46 /** 47 * The parser request this instance was created from. 48 */ 49 @Nonnull 50 ParserRequest parserRequest(); 51 52 /** 53 * Shorthand for {@link Logger} to use. 54 */ 55 default Logger logger() { 56 return parserRequest().logger(); 57 } 58 59 /** 60 * Shorthand for {@link MessageBuilderFactory}. 61 */ 62 default MessageBuilderFactory messageBuilderFactory() { 63 return parserRequest().messageBuilderFactory(); 64 } 65 66 /** 67 * Shorthand for {@link Lookup}. 68 */ 69 default Lookup lookup() { 70 return parserRequest().lookup(); 71 } 72 73 /** 74 * Returns the current working directory for the Maven execution. 75 * This is typically the directory from which Maven was invoked. 76 * 77 * @return the current working directory path 78 */ 79 @Nonnull 80 Path cwd(); 81 82 /** 83 * Returns the Maven installation directory. 84 * This is usually set by the Maven launcher script using the "maven.home" system property. 85 * 86 * @return the Maven installation directory path 87 */ 88 @Nonnull 89 Path installationDirectory(); 90 91 /** 92 * Returns the user's home directory. 93 * This is typically obtained from the "user.home" system property. 94 * 95 * @return the user's home directory path 96 */ 97 @Nonnull 98 Path userHomeDirectory(); 99 100 /** 101 * Returns a map of user-defined properties for the Maven execution. 102 * These properties can be set using the -D command-line option. 103 * 104 * @return an unmodifiable map of user properties 105 */ 106 @Nonnull 107 Map<String, String> userProperties(); 108 109 /** 110 * Returns a map of system properties for the Maven execution. 111 * These include both Java system properties and Maven-specific system properties. 112 * 113 * @return an unmodifiable map of system properties 114 */ 115 @Nonnull 116 Map<String, String> systemProperties(); 117 118 /** 119 * Returns the top-level directory of the Maven invocation. 120 * This is typically the directory containing the POM file being executed. 121 * 122 * @return the top-level directory path 123 */ 124 @Nonnull 125 Path topDirectory(); 126 127 /** 128 * Returns the root directory of the Maven invocation, if found. This is determined by the presence of a 129 * {@code .mvn} directory or a POM with the root="true" property but is not always applicable (ie invocation 130 * from outside a checkout). 131 * 132 * @return the root directory path, if present 133 */ 134 @Nonnull 135 Optional<Path> rootDirectory(); 136 137 /** 138 * Returns the input stream for the Maven execution, if running in embedded mode. 139 * 140 * @return an {@link Optional} containing the input stream, or empty if not applicable 141 */ 142 @Nonnull 143 Optional<InputStream> in(); 144 145 /** 146 * Returns the output stream for the Maven execution, if running in embedded mode. 147 * 148 * @return an {@link Optional} containing the output stream, or empty if not applicable 149 */ 150 @Nonnull 151 Optional<OutputStream> out(); 152 153 /** 154 * Returns the error stream for the Maven execution, if running in embedded mode. 155 * 156 * @return an {@link Optional} containing the error stream, or empty if not applicable 157 */ 158 @Nonnull 159 Optional<OutputStream> err(); 160 161 /** 162 * Returns a list of core extensions, if configured in the .mvn/extensions.xml file. 163 * 164 * @return an {@link Optional} containing the list of core extensions, or empty if not configured 165 */ 166 @Nonnull 167 Optional<List<CoreExtension>> coreExtensions(); 168 169 /** 170 * Returns the options associated with this invocation request. 171 * 172 * @return the options object 173 */ 174 @Nonnull 175 O options(); 176 }