[MNG-7203] Introduce a long option --verbose and deprecate --debug

This closes #519
This commit is contained in:
Michael Osipov 2021-08-01 21:15:10 +02:00
parent 750cb6cb15
commit a2a3df3d02
8 changed files with 37 additions and 19 deletions

View File

@ -97,7 +97,7 @@ public boolean isActive( Profile profile )
else
{
logger.warn( "Failed to interpolate missing file location for profile activator: " + fileString
+ ". Run in debug mode (-X) for more information." );
+ ", enable verbose output (-X) for more details" );
}
}
}

View File

@ -128,7 +128,7 @@ public void artifactDescriptorInvalid( RepositoryEvent event )
}
else
{
logger.warn( buffer + ", enable debug logging for more details" );
logger.warn( buffer + ", enable verbose output (-X) for more details" );
}
}

View File

@ -157,7 +157,8 @@ public MavenExecutionPlan resolveBuildPlan( MavenSession session, MavenProject p
{
logger.warn( unsafePlugin.getId() );
}
logger.warn( "Enable debug to see more precisely which goals are not marked @threadSafe." );
logger.warn( "Enable verbose output (-X) to see more precisely which goals are not marked"
+ " @threadSafe." );
}
logger.warn( "*****************************************************************" );
}

View File

@ -623,7 +623,7 @@ else if ( isNonTransferrablePom( e ) )
message =
"Invalid POM for " + artifact.getId()
+ ", transitive dependencies (if any) will not be available"
+ ", enable debug logging for more details";
+ ", enable verbose output (-X) for more details";
}
if ( logger.isDebugEnabled() )

View File

@ -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,11 @@ 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 +127,7 @@ public 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 +158,9 @@ public 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 )

View File

@ -42,7 +42,7 @@ public class CliRequest
File multiModuleProjectDirectory;
boolean debug;
boolean verbose;
boolean quiet;
@ -86,9 +86,9 @@ public File getMultiModuleProjectDirectory()
return multiModuleProjectDirectory;
}
public boolean isDebug()
public boolean isVerbose()
{
return debug;
return verbose;
}
public boolean isQuiet()

View File

@ -497,14 +497,15 @@ private CommandLine cliMerge( CommandLine mavenArgs, CommandLine mavenConfig )
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,17 @@ else if ( cliRequest.commandLine.hasOption( CLIManager.BATCH_MODE )
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() );
}
@ -1029,12 +1036,12 @@ private int execute( CliRequest cliRequest )
if ( !cliRequest.showErrors )
{
slf4jLogger.error( "To see the full stack trace of the errors, re-run Maven with the '{}' switch.",
slf4jLogger.error( "To see the full stack trace of the errors, re-run Maven with the '{}' switch",
buffer().strong( "-e" ) );
}
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 verbose output",
buffer().strong( "-X" ) );
}
@ -1368,6 +1375,7 @@ private MavenExecutionRequest populateRequest( CliRequest cliRequest, MavenExecu
CommandLine commandLine = cliRequest.commandLine;
String workingDirectory = cliRequest.workingDirectory;
boolean quiet = cliRequest.quiet;
boolean verbose = cliRequest.verbose;
request.setShowErrors( cliRequest.showErrors ); // default: false
File baseDirectory = new File( workingDirectory, "" ).getAbsoluteFile();
@ -1384,7 +1392,7 @@ private MavenExecutionRequest populateRequest( CliRequest cliRequest, MavenExecu
request.setUserProperties( cliRequest.userProperties );
request.setMultiModuleProjectDirectory( cliRequest.multiModuleProjectDirectory );
request.setPom( determinePom( commandLine, workingDirectory, baseDirectory ) );
request.setTransferListener( determineTransferListener( quiet, commandLine, request ) );
request.setTransferListener( determineTransferListener( quiet, verbose, commandLine, request ) );
request.setExecutionListener( determineExecutionListener() );
if ( ( request.getPom() != null ) && ( request.getPom().getParentFile() != null ) )
@ -1593,6 +1601,7 @@ else if ( commandLine.hasOption( CLIManager.FAIL_NEVER ) )
}
private TransferListener determineTransferListener( final boolean quiet,
final boolean verbose,
final CommandLine commandLine,
final MavenExecutionRequest request )
{
@ -1606,7 +1615,7 @@ else if ( request.isInteractiveMode() && !commandLine.hasOption( CLIManager.LOG_
// 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( verbose );
}
else
{

View File

@ -42,7 +42,7 @@ public void spacedOptions()
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" ) );
}