Skip to content

Commit

Permalink
[MNG-8283] Maven CLIng smaller bugfixes and improvements (#1772)
Browse files Browse the repository at this point in the history
This PR adopts CLIng for use in mvnd, and adds several improvements to CLIng overall.

Major topics:
* ability to pass in per-request Lookup for customization
* makes parser request creation a bit friendlier
* removes a log of redundancy (same stuff copied over)
* ability to alter rootDirectory detection in parsers
* resident invoker bugfix
* adds UTs for 3 invoker implementations

---

https://issues.apache.org/jira/browse/MNG-8283
  • Loading branch information
cstamas authored Oct 4, 2024
1 parent 1f1a0f9 commit 533790b
Show file tree
Hide file tree
Showing 29 changed files with 856 additions and 493 deletions.
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

0 comments on commit 533790b

Please sign in to comment.