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.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 @@ private static String getFormattedTime( long time )
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;
@ -112,49 +114,98 @@ public void sessionEnded( LifecycleEvent event )
{ {
if ( logger.isInfoEnabled() ) if ( logger.isInfoEnabled() )
{ {
logger.info( chars( '-', LINE_LENGTH ) ); if ( event.getSession().getProjects().size() > 1 )
logger.info( "Reactor Summary:" );
logger.info( chars( '-', LINE_LENGTH ) );
MavenExecutionResult result = event.getSession().getResult();
for ( MavenProject project : event.getSession().getProjects() )
{ {
StringBuilder buffer = new StringBuilder( 128 ); logReactorSummary( event.getSession() );
buffer.append( project.getName() );
while ( buffer.length() < LINE_LENGTH - 22 )
{
buffer.append( '.' );
}
BuildSummary buildSummary = result.getBuildSummary( project );
if ( buildSummary == null )
{
buffer.append( "SKIPPED" );
}
else if ( buildSummary instanceof BuildSuccess )
{
buffer.append( "SUCCESS [" );
buffer.append( getFormattedTime( buildSummary.getTime() ) );
buffer.append( "]" );
}
else if ( buildSummary instanceof BuildFailure )
{
buffer.append( "FAILURE [" );
buffer.append( getFormattedTime( buildSummary.getTime() ) );
buffer.append( "]" );
}
logger.info( buffer.toString() );
} }
logResult( event.getSession() );
logStats( event.getSession() );
logger.info( chars( '-', LINE_LENGTH ) ); logger.info( chars( '-', LINE_LENGTH ) );
} }
} }
private void logReactorSummary( MavenSession session )
{
logger.info( chars( '-', LINE_LENGTH ) );
logger.info( "Reactor Summary:" );
logger.info( chars( '-', LINE_LENGTH ) );
MavenExecutionResult result = session.getResult();
for ( MavenProject project : session.getProjects() )
{
StringBuilder buffer = new StringBuilder( 128 );
buffer.append( project.getName() );
buffer.append( ' ' );
while ( buffer.length() < LINE_LENGTH - 21 )
{
buffer.append( '.' );
}
buffer.append( ' ' );
BuildSummary buildSummary = result.getBuildSummary( project );
if ( buildSummary == null )
{
buffer.append( "SKIPPED" );
}
else if ( buildSummary instanceof BuildSuccess )
{
buffer.append( "SUCCESS [" );
buffer.append( getFormattedTime( buildSummary.getTime() ) );
buffer.append( "]" );
}
else if ( buildSummary instanceof BuildFailure )
{
buffer.append( "FAILURE [" );
buffer.append( getFormattedTime( buildSummary.getTime() ) );
buffer.append( "]" );
}
logger.info( buffer.toString() );
}
}
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
public void projectSkipped( LifecycleEvent event ) public void projectSkipped( LifecycleEvent event )
{ {
@ -170,7 +221,9 @@ public void projectStarted( LifecycleEvent event )
{ {
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 ) );
} }
} }