From f98e632108f2b9496e306dc4630fa24ca5ca45b9 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 21 Jan 2021 18:22:18 +0100 Subject: [PATCH] [MNG-7080] Add a --color option to simplify color support --- .../src/main/java/org/apache/maven/cli/CLIManager.java | 4 ++++ .../src/main/java/org/apache/maven/cli/MavenCli.java | 2 ++ .../org/apache/maven/cli/CLIManagerDocumentationTest.java | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java index 1e95010690..a0d54d3bf9 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java @@ -103,6 +103,8 @@ public class CLIManager public static final String NO_TRANSFER_PROGRESS = "ntp"; + public static final String COLOR = "color"; + protected Options options; @SuppressWarnings( { "static-access", "checkstyle:linelength" } ) @@ -149,6 +151,8 @@ public class CLIManager options.addOption( Option.builder( "cpu" ).longOpt( "check-plugin-updates" ).desc( "Ineffective, only kept for backward compatibility" ).build() ); options.addOption( Option.builder( "up" ).longOpt( "update-plugins" ).desc( "Ineffective, only kept for backward compatibility" ).build() ); options.addOption( Option.builder( "npu" ).longOpt( "no-plugin-updates" ).desc( "Ineffective, only kept for backward compatibility" ).build() ); + + options.addOption( Option.builder().longOpt( COLOR ).hasArg().desc( "Defines the color mode of the output. Available options are auto/always/never" ).build() ); } public CommandLine parse( String[] args ) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 9c7c4d2537..474a139f84 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -113,6 +113,7 @@ import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.apache.maven.cli.CLIManager.COLOR; import static org.apache.maven.cli.ResolveFile.resolveFile; import static org.apache.maven.shared.utils.logging.MessageUtils.buffer; @@ -504,6 +505,7 @@ public class MavenCli // LOG COLOR String styleColor = cliRequest.getUserProperties().getProperty( STYLE_COLOR_PROPERTY, "auto" ); + styleColor = cliRequest.commandLine.getOptionValue( COLOR, styleColor ); if ( "always".equals( styleColor ) ) { MessageUtils.setColorEnabled( true ); diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java index 2c82a72e23..7b136066e4 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerDocumentationTest.java @@ -46,7 +46,9 @@ public class CLIManagerDocumentationTest { public int compare( Option opt1, Option opt2 ) { - return opt1.getOpt().compareToIgnoreCase( opt2.getOpt() ); + String s1 = opt1.getOpt() != null ? opt1.getOpt() : opt1.getLongOpt(); + String s2 = opt2.getOpt() != null ? opt2.getOpt() : opt2.getLongOpt(); + return s1.compareToIgnoreCase( s2 ); } }