o Improved logging

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@805351 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-08-18 10:41:12 +00:00
parent 7cae21ebf5
commit 284693bf7e
1 changed files with 89 additions and 36 deletions

View File

@ -29,6 +29,7 @@ import org.apache.maven.execution.BuildFailure;
import org.apache.maven.execution.BuildSuccess; import org.apache.maven.execution.BuildSuccess;
import org.apache.maven.execution.BuildSummary; import org.apache.maven.execution.BuildSummary;
import org.apache.maven.execution.MavenExecutionResult; import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.AbstractLifecycleListener; import org.apache.maven.lifecycle.AbstractLifecycleListener;
import org.apache.maven.lifecycle.LifecycleEvent; import org.apache.maven.lifecycle.LifecycleEvent;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -77,6 +78,7 @@ class LifecycleEventLogger
if ( time / 60000L > 0 ) if ( time / 60000L > 0 )
{ {
pattern = "m:s" + pattern; pattern = "m:s" + pattern;
if ( time / 3600000L > 0 ) if ( time / 3600000L > 0 )
{ {
pattern = "H:m" + pattern; pattern = "H:m" + pattern;
@ -111,23 +113,40 @@ class LifecycleEventLogger
public void sessionEnded( LifecycleEvent event ) public void sessionEnded( LifecycleEvent event )
{ {
if ( logger.isInfoEnabled() ) if ( logger.isInfoEnabled() )
{
if ( event.getSession().getProjects().size() > 1 )
{
logReactorSummary( event.getSession() );
}
logResult( event.getSession() );
logStats( event.getSession() );
logger.info( chars( '-', LINE_LENGTH ) );
}
}
private void logReactorSummary( MavenSession session )
{ {
logger.info( chars( '-', LINE_LENGTH ) ); logger.info( chars( '-', LINE_LENGTH ) );
logger.info( "Reactor Summary:" ); logger.info( "Reactor Summary:" );
logger.info( chars( '-', LINE_LENGTH ) ); logger.info( chars( '-', LINE_LENGTH ) );
MavenExecutionResult result = event.getSession().getResult(); MavenExecutionResult result = session.getResult();
for ( MavenProject project : event.getSession().getProjects() ) for ( MavenProject project : session.getProjects() )
{ {
StringBuilder buffer = new StringBuilder( 128 ); StringBuilder buffer = new StringBuilder( 128 );
buffer.append( project.getName() ); buffer.append( project.getName() );
while ( buffer.length() < LINE_LENGTH - 22 ) buffer.append( ' ' );
while ( buffer.length() < LINE_LENGTH - 21 )
{ {
buffer.append( '.' ); buffer.append( '.' );
} }
buffer.append( ' ' );
BuildSummary buildSummary = result.getBuildSummary( project ); BuildSummary buildSummary = result.getBuildSummary( project );
@ -150,9 +169,41 @@ class LifecycleEventLogger
logger.info( buffer.toString() ); logger.info( buffer.toString() );
} }
logger.info( chars( '-', LINE_LENGTH ) );
} }
private void logResult( MavenSession session )
{
logger.info( chars( '-', LINE_LENGTH ) );
if ( session.getResult().hasExceptions() )
{
logger.info( "BUILD FAILURE" );
}
else
{
logger.info( "BUILD SUCCESS" );
}
}
private void logStats( MavenSession session )
{
logger.info( chars( '-', LINE_LENGTH ) );
Date finish = new Date();
long time = finish.getTime() - session.getRequest().getStartTime().getTime();
logger.info( "Total time: " + getFormattedTime( time ) );
logger.info( "Finished at: " + finish );
System.gc();
Runtime r = Runtime.getRuntime();
long MB = 1024 * 1024;
logger.info( "Final Memory: " + ( r.totalMemory() - r.freeMemory() ) / MB + "M/" + r.totalMemory() / MB + "M" );
} }
@Override @Override
@ -170,7 +221,9 @@ class LifecycleEventLogger
{ {
if ( logger.isInfoEnabled() ) if ( logger.isInfoEnabled() )
{ {
logger.info( chars( '-', LINE_LENGTH ) );
logger.info( "Building " + event.getProject().getName() ); logger.info( "Building " + event.getProject().getName() );
logger.info( chars( '-', LINE_LENGTH ) );
} }
} }