o Revised logging

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@804195 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-08-14 12:35:34 +00:00
parent d8b2070350
commit 977d3bccdc
3 changed files with 46 additions and 34 deletions

View File

@ -28,8 +28,6 @@ public final class CLIReportingUtils
public static final int SEC_PER_MIN = 60;
private static final String NEWLINE = System.getProperty( "line.separator" );
public static void showVersion()
{
Properties properties = getBuildProperties();
@ -165,22 +163,24 @@ static Properties getBuildProperties()
return properties;
}
public static void showError( String message, Exception e, boolean showStackTrace )
public static void showError( MavenEmbedderLogger logger, String message, Exception e, boolean showStackTrace )
{
System.err.println( message );
if ( showStackTrace )
{
e.printStackTrace();
logger.error( message, e );
}
else
{
System.err.println( e.getMessage() );
logger.error( message );
for ( Throwable cause = e.getCause(); cause != null; cause = cause.getCause() )
if ( e != null )
{
System.err.print( "Caused by: " );
System.err.println( cause.getMessage() );
logger.error( e.getMessage() );
for ( Throwable cause = e.getCause(); cause != null; cause = cause.getCause() )
{
logger.error( "Caused by: " + cause.getMessage() );
}
}
}
}

View File

@ -123,16 +123,10 @@ else if ( commandLine.hasOption( CLIManager.FAIL_NEVER ) )
if ( commandLine.hasOption( CLIManager.CHECKSUM_FAILURE_POLICY ) )
{
// todo; log
System.out.println( "+ Enabling strict checksum verification on all artifact downloads." );
globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_FAIL;
}
else if ( commandLine.hasOption( CLIManager.CHECKSUM_WARNING_POLICY ) )
{
// todo: log
System.out.println( "+ Disabling strict checksum verification on all artifact downloads." );
globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN;
}

View File

@ -26,6 +26,7 @@
import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.embedder.MavenEmbedderFileLogger;
import org.apache.maven.embedder.MavenEmbedderLogger;
import org.apache.maven.exception.ExceptionSummary;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
@ -87,11 +88,6 @@ public int doMain( String[] args, ClassWorld classWorld )
boolean showErrors = debug || commandLine.hasOption( CLIManager.ERRORS );
if ( showErrors )
{
System.out.println( "+ Error stacktraces are turned on." );
}
// ----------------------------------------------------------------------
// Process particular command line options
// ----------------------------------------------------------------------
@ -109,10 +105,6 @@ public int doMain( String[] args, ClassWorld classWorld )
return 0;
}
else if ( debug || commandLine.hasOption( CLIManager.SHOW_VERSION ) )
{
CLIReportingUtils.showVersion();
}
// Make sure the Maven home directory is an absolute path to save us from confusion with say drive-relative
// Windows paths.
@ -126,18 +118,41 @@ else if ( debug || commandLine.hasOption( CLIManager.SHOW_VERSION ) )
Configuration configuration = buildEmbedderConfiguration( request, commandLine, classWorld );
MavenEmbedderLogger logger = configuration.getMavenEmbedderLogger();
if ( debug || commandLine.hasOption( CLIManager.SHOW_VERSION ) )
{
CLIReportingUtils.showVersion();
}
if ( showErrors )
{
logger.info( "Error stacktraces are turned on." );
}
if ( MavenExecutionRequest.CHECKSUM_POLICY_WARN.equals( request.getGlobalChecksumPolicy() ) )
{
logger.info( "Disabling strict checksum verification on all artifact downloads." );
}
else if ( MavenExecutionRequest.CHECKSUM_POLICY_FAIL.equals( request.getGlobalChecksumPolicy() ) )
{
logger.info( "Enabling strict checksum verification on all artifact downloads." );
}
ConfigurationValidationResult cvr = MavenEmbedder.validateConfiguration( configuration );
if ( cvr.isUserSettingsFilePresent() && !cvr.isUserSettingsFileParses() )
{
CLIReportingUtils.showError( "Error reading user settings: ", cvr.getUserSettingsException(), showErrors );
CLIReportingUtils.showError( logger, "Error reading user settings: ", cvr.getUserSettingsException(),
showErrors );
return 1;
}
if ( cvr.isGlobalSettingsFilePresent() && !cvr.isGlobalSettingsFileParses() )
{
CLIReportingUtils.showError( "Error reading global settings: ", cvr.getGlobalSettingsException(), showErrors );
CLIReportingUtils.showError( logger, "Error reading global settings: ", cvr.getGlobalSettingsException(),
showErrors );
return 1;
}
@ -160,7 +175,7 @@ else if ( debug || commandLine.hasOption( CLIManager.SHOW_VERSION ) )
}
catch ( MavenEmbedderException e )
{
CLIReportingUtils.showError( "Unable to start the embedder: ", e, showErrors );
CLIReportingUtils.showError( logger, "Unable to start the embedder: ", e, showErrors );
return 1;
}
@ -217,7 +232,8 @@ else if ( commandLine.hasOption( CLIManager.ENCRYPT_PASSWORD ) )
}
catch ( Exception e )
{
CLIReportingUtils.showError( "FATAL ERROR: " + "Error encrypting password: " + e.getMessage(), e, showErrors );
System.err.println( "FATAL ERROR: " + "Error encrypting password: " + e.getMessage() );
e.printStackTrace();
return 1;
}
@ -241,21 +257,23 @@ else if ( commandLine.hasOption( CLIManager.ENCRYPT_PASSWORD ) )
if ( es == null )
{
result.getExceptions().get( 0 ).printStackTrace();
logger.error( "", result.getExceptions().get( 0 ) );
}
else
{
System.out.println( es.getMessage() );
if ( showErrors )
{
es.getException().printStackTrace();
logger.error( es.getMessage(), es.getException() );
}
else
{
logger.error( es.getMessage() );
}
}
if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( request.getReactorFailureBehavior() ) )
{
System.out.println( "+ Build failures were ignored." );
logger.info( "Build failures were ignored." );
return 0;
}