From 84ca089376de0b015e0a498c35d76982df7d43cf Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Mon, 17 Aug 2009 13:33:39 +0000 Subject: [PATCH] o Restored reactor summary git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@804980 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/cli/LifecycleEventLogger.java | 90 ++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/LifecycleEventLogger.java b/maven-embedder/src/main/java/org/apache/maven/cli/LifecycleEventLogger.java index 9e9f26ba62..45583e81b3 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/LifecycleEventLogger.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/LifecycleEventLogger.java @@ -19,7 +19,16 @@ package org.apache.maven.cli; * under the License. */ +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; + import org.apache.maven.embedder.MavenEmbedderLogger; +import org.apache.maven.execution.BuildFailure; +import org.apache.maven.execution.BuildSuccess; +import org.apache.maven.execution.BuildSummary; +import org.apache.maven.execution.MavenExecutionResult; import org.apache.maven.lifecycle.AbstractLifecycleListener; import org.apache.maven.lifecycle.LifecycleEvent; import org.apache.maven.plugin.descriptor.MojoDescriptor; @@ -37,6 +46,8 @@ class LifecycleEventLogger private final MavenEmbedderLogger logger; + private static final int LINE_LENGTH = 72; + public LifecycleEventLogger( MavenEmbedderLogger logger ) { if ( logger == null ) @@ -47,7 +58,36 @@ class LifecycleEventLogger this.logger = logger; } - // TODO: log the events + private static String chars( char c, int count ) + { + StringBuilder buffer = new StringBuilder( count ); + + for ( int i = count; i > 0; i-- ) + { + buffer.append( c ); + } + + return buffer.toString(); + } + + private static String getFormattedTime( long time ) + { + String pattern = "s.SSS's'"; + + if ( time / 60000L > 0 ) + { + pattern = "m:s" + pattern; + if ( time / 3600000L > 0 ) + { + pattern = "H:m" + pattern; + } + } + + DateFormat fmt = new SimpleDateFormat( pattern ); + fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); + + return fmt.format( new Date( time ) ); + } @Override public void sessionStarted( LifecycleEvent event ) @@ -67,6 +107,54 @@ class LifecycleEventLogger } } + @Override + public void sessionEnded( LifecycleEvent event ) + { + if ( logger.isInfoEnabled() ) + { + logger.info( chars( '-', LINE_LENGTH ) ); + 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 ); + + 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() ); + } + + logger.info( chars( '-', LINE_LENGTH ) ); + } + } + @Override public void projectSkipped( LifecycleEvent event ) {