Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import java.util.Optional;

import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.cli.extensions.CoreExtension;
import org.apache.maven.api.services.Lookup;
import org.apache.maven.api.services.MessageBuilderFactory;

/**
Expand All @@ -38,15 +40,35 @@
*
* @since 4.0.0
*/
@Immutable
@Experimental
public interface InvokerRequest<O extends Options> {
/**
* Returns the command to be executed.
*
* @return the command string
* The parser request this instance was created from.
*/
@Nonnull
String command();
ParserRequest parserRequest();

/**
* Shorthand for {@link Logger} to use.
*/
default Logger logger() {
return parserRequest().logger();
}

/**
* Shorthand for {@link MessageBuilderFactory}.
*/
default MessageBuilderFactory messageBuilderFactory() {
return parserRequest().messageBuilderFactory();
}

/**
* Shorthand for {@link Lookup}.
*/
default Lookup lookup() {
return parserRequest().lookup();
}

/**
* Returns the current working directory for the Maven execution.
Expand Down Expand Up @@ -93,24 +115,6 @@ public interface InvokerRequest<O extends Options> {
@Nonnull
Map<String, String> systemProperties();

/**
* Returns the logger to be used during the early phases of Maven execution,
* before the main Maven logger is initialized.
*
* @return the early-phase logger
*/
@Nonnull
Logger logger();

/**
* Returns the factory for creating message builders.
* Message builders are used for constructing formatted log messages.
*
* @return the message builder factory
*/
@Nonnull
MessageBuilderFactory messageBuilderFactory();

/**
* Returns the top-level directory of the Maven invocation.
* This is typically the directory containing the POM file being executed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ public interface Options {
*
* @param printWriter the PrintWriter to use for output
*/
default void warnAboutDeprecatedOptions(@Nonnull PrintWriter printWriter) {}
default void warnAboutDeprecatedOptions(@Nonnull ParserRequest request, @Nonnull PrintWriter printWriter) {}

/**
* Displays help information for these options.
*
* @param printWriter the PrintWriter to use for output
*/
void displayHelp(@Nonnull String command, @Nonnull PrintWriter printWriter);
void displayHelp(@Nonnull ParserRequest request, @Nonnull PrintWriter printWriter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
@Experimental
public interface Parser<R extends InvokerRequest<? extends Options>> {
/**
* Parses the given command and arguments to create an InvokerRequest.
* This is a convenience method that internally creates a ParserRequest.
* Parses the given Maven arguments to create an InvokerRequest.
* This is a convenience method that internally creates a ParserRequest using
* {@link ParserRequest#mvn(String[], Logger, MessageBuilderFactory)}.
*
* @param command the Maven command to execute
* @param args the command-line arguments
* @param logger the logger to use during parsing
* @param messageBuilderFactory the factory for creating message builders
Expand All @@ -48,14 +48,9 @@ public interface Parser<R extends InvokerRequest<? extends Options>> {
* @throws IOException if there's an I/O error during the parsing process
*/
@Nonnull
default R parse(
@Nonnull String command,
@Nonnull String[] args,
@Nonnull Logger logger,
@Nonnull MessageBuilderFactory messageBuilderFactory)
default R mvn(@Nonnull String[] args, @Nonnull Logger logger, @Nonnull MessageBuilderFactory messageBuilderFactory)
throws ParserException, IOException {
return parse(ParserRequest.builder(command, args, logger, messageBuilderFactory)
.build());
return parse(ParserRequest.mvn(args, logger, messageBuilderFactory).build());
}

/**
Expand Down
Loading