You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2021/08/01 19:15:50 UTC

[maven] 01/01: [MNG-7203] Introduce a long option --verbose and deprecate --debug

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch MNG-7203
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 76ee1d6d496691ac90962d9e6b7e22832481524c
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun Aug 1 21:15:10 2021 +0200

    [MNG-7203] Introduce a long option --verbose and deprecate --debug
    
    This closes #519
---
 .../main/java/org/apache/maven/cli/CLIManager.java | 11 +++++++++--
 .../main/java/org/apache/maven/cli/CliRequest.java |  6 +++---
 .../main/java/org/apache/maven/cli/MavenCli.java   | 23 ++++++++++++++--------
 .../java/org/apache/maven/cli/CLIManagerTest.java  |  2 +-
 4 files changed, 28 insertions(+), 14 deletions(-)

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 fec2bda..70a9516 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
@@ -46,7 +46,7 @@ public class CLIManager
 
     public static final char QUIET = 'q';
 
-    public static final char DEBUG = 'X';
+    public static final char VERBOSE = 'X';
 
     public static final char ERRORS = 'e';
 
@@ -110,6 +110,10 @@ public class CLIManager
 
     public static final String COLOR = "color";
 
+    /** This option is deprecated and may be repurposed as Java debug in a future version. Use {@code -X/--verbose} instead. */
+    @Deprecated
+    public static final String DEBUG = "debug";
+
     protected Options options;
 
     @SuppressWarnings( "checkstyle:linelength" )
@@ -122,7 +126,7 @@ public class CLIManager
         options.addOption( Option.builder( Character.toString( OFFLINE ) ).longOpt( "offline" ).desc( "Work offline" ).build() );
         options.addOption( Option.builder( Character.toString( VERSION ) ).longOpt( "version" ).desc( "Display version information" ).build() );
         options.addOption( Option.builder( Character.toString( QUIET ) ).longOpt( "quiet" ).desc( "Quiet output - only show errors" ).build() );
-        options.addOption( Option.builder( Character.toString( DEBUG ) ).longOpt( "debug" ).desc( "Produce execution debug output" ).build() );
+        options.addOption( Option.builder( Character.toString( VERBOSE ) ).longOpt( "verbose" ).longOpt( "verbose" ).desc( "Produce execution verbose output" ).build() );
         options.addOption( Option.builder( Character.toString( ERRORS ) ).longOpt( "errors" ).desc( "Produce execution error messages" ).build() );
         options.addOption( Option.builder( Character.toString( NON_RECURSIVE ) ).longOpt( "non-recursive" ).desc( "Do not recurse into sub-projects. When used together with -pl, do not recurse into sub-projects of selected aggregators" ).build() );
         options.addOption( Option.builder( Character.toString( UPDATE_SNAPSHOTS ) ).longOpt( "update-snapshots" ).desc( "Forces a check for missing releases and updated snapshots on remote repositories" ).build() );
@@ -153,6 +157,9 @@ public class CLIManager
         options.addOption( Option.builder( BUILDER ).longOpt( "builder" ).hasArg().desc( "The id of the build strategy to use" ).build() );
         options.addOption( Option.builder( NO_TRANSFER_PROGRESS ).longOpt( "no-transfer-progress" ).desc( "Do not display transfer progress when downloading or uploading" ).build() );
         options.addOption( Option.builder().longOpt( COLOR ).hasArg().optionalArg( true ).desc( "Defines the color mode of the output. Supported are 'auto', 'always', 'never'." ).build() );
+
+        // Deprecated
+        options.addOption( Option.builder().longOpt( DEBUG ).desc( "Produce execution verbose output (deprecated; only kept for backward compatibility)" ).build() );
     }
 
     public CommandLine parse( String[] args )
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CliRequest.java b/maven-embedder/src/main/java/org/apache/maven/cli/CliRequest.java
index 7dca591..166d1a1 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/CliRequest.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/CliRequest.java
@@ -42,7 +42,7 @@ public class CliRequest
 
     File multiModuleProjectDirectory;
 
-    boolean debug;
+    boolean verbose;
 
     boolean quiet;
 
@@ -86,9 +86,9 @@ public class CliRequest
         return multiModuleProjectDirectory;
     }
 
-    public boolean isDebug()
+    public boolean isVerbose()
     {
-        return debug;
+        return verbose;
     }
 
     public boolean isQuiet()
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 07a9c78..cbb3572 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
@@ -497,14 +497,15 @@ public class MavenCli
     void logging( CliRequest cliRequest )
     {
         // LOG LEVEL
-        cliRequest.debug = cliRequest.commandLine.hasOption( CLIManager.DEBUG );
-        cliRequest.quiet = !cliRequest.debug && cliRequest.commandLine.hasOption( CLIManager.QUIET );
-        cliRequest.showErrors = cliRequest.debug || cliRequest.commandLine.hasOption( CLIManager.ERRORS );
+        cliRequest.verbose = cliRequest.commandLine.hasOption( CLIManager.VERBOSE )
+                             || cliRequest.commandLine.hasOption( CLIManager.DEBUG );
+        cliRequest.quiet = !cliRequest.verbose && cliRequest.commandLine.hasOption( CLIManager.QUIET );
+        cliRequest.showErrors = cliRequest.verbose || cliRequest.commandLine.hasOption( CLIManager.ERRORS );
 
         slf4jLoggerFactory = LoggerFactory.getILoggerFactory();
         Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration( slf4jLoggerFactory );
 
-        if ( cliRequest.debug )
+        if ( cliRequest.verbose )
         {
             cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_DEBUG );
             slf4jConfiguration.setRootLoggerLevel( Slf4jConfiguration.Level.DEBUG );
@@ -582,11 +583,16 @@ public class MavenCli
                         MavenSlf4jWrapperFactory.class.getName(), slf4jLoggerFactory.getClass().getName() );
             }
         }
+
+        if ( cliRequest.commandLine.hasOption( CLIManager.DEBUG ) )
+        {
+            slf4jLogger.warn("The option '--debug' is deprecated and may be repurposed as Java debug in a future version. Use -X/--verbose instead.");
+        }
     }
 
     private void version( CliRequest cliRequest )
     {
-        if ( cliRequest.debug || cliRequest.commandLine.hasOption( CLIManager.SHOW_VERSION ) )
+        if ( cliRequest.verbose || cliRequest.commandLine.hasOption( CLIManager.SHOW_VERSION ) )
         {
             System.out.println( CLIReportingUtils.showVersion() );
         }
@@ -615,7 +621,7 @@ public class MavenCli
             {
                 MessageBuilder buff = MessageUtils.buffer();
                 buff.a( "Message styles: " );
-                buff.a( MessageUtils.level().debug( "debug" ) ).a( ' ' );
+                buff.a( MessageUtils.level().debug( "verbose" ) ).a( ' ' );
                 buff.a( MessageUtils.level().info( "info" ) ).a( ' ' );
                 buff.a( MessageUtils.level().warning( "warning" ) ).a( ' ' );
                 buff.a( MessageUtils.level().error( "error" ) ).a( ' ' );
@@ -1034,7 +1040,7 @@ public class MavenCli
             }
             if ( !slf4jLogger.isDebugEnabled() )
             {
-                slf4jLogger.error( "Re-run Maven using the '{}' switch to enable full debug logging.",
+                slf4jLogger.error( "Re-run Maven using the '{}' switch to enable full verbose logging.",
                         buffer().strong( "-X" ) );
             }
 
@@ -1606,7 +1612,8 @@ public class MavenCli
             // If we're logging to a file then we don't want the console transfer listener as it will spew
             // download progress all over the place
             //
-            return getConsoleTransferListener( commandLine.hasOption( CLIManager.DEBUG ) );
+            return getConsoleTransferListener( commandLine.hasOption( CLIManager.VERBOSE )
+                                               || commandLine.hasOption( CLIManager.DEBUG ) );
         }
         else
         {
diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java
index a3aad6b..68e4c22 100644
--- a/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java
+++ b/maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java
@@ -42,7 +42,7 @@ public class CLIManagerTest
         throws Exception
     {
         CommandLine cmdLine = cliManager.parse( "-X -Dx=1 -D y=2 test".split( " " ) );
-        assertTrue( cmdLine.hasOption( CLIManager.DEBUG ) );
+        assertTrue( cmdLine.hasOption( CLIManager.VERBOSE ) );
         assertThat( cmdLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY )[0], is( "x=1" ) );
         assertThat( cmdLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY )[1], is( "y=2" ) );
     }