maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From schu...@apache.org
Subject [16/20] maven git commit: [MNG-3507] added color to Maven execution output messages
Date Fri, 17 Jun 2016 19:36:13 GMT
[MNG-3507] added color to Maven execution output messages

o Updated to stop combining color and bold and to provide more colored
  execution messages. The idea behind this is to distinguish between messages
  logged by Maven core and logged by plugins based on the color of the message.
  This means there are a lot of 'Logger.xyz' calls in core still to be ANSIfied.
  There really should be a separate 'Logger' used by Maven core and passed to
  Maven plugins to make this easier. Also things already are loosing the
  eye-catching effect the colors are good for. Everything beyond green,red and
  yellow already is too much, in my opinion. Feel free to revert the last two
  commits or improve on how Maven presents itself to users starting with 3.4
  until things reach a point everyone agrees to.


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/7e1b961e
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/7e1b961e
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/7e1b961e

Branch: refs/heads/MNG-6006
Commit: 7e1b961edd44c7d2843b1b7cd01cea5a1cd1a70d
Parents: 71e4ff8
Author: Christian Schulte <schulte@apache.org>
Authored: Thu Jun 16 19:54:01 2016 +0200
Committer: Christian Schulte <schulte@apache.org>
Committed: Thu Jun 16 20:01:56 2016 +0200

----------------------------------------------------------------------
 .../lifecycle/LifecycleExecutionException.java  |  16 +--
 .../maven/cli/event/ExecutionEventLogger.java   | 104 +++++++++++--------
 .../apache/maven/cli/logging/Slf4jLogger.java   |  13 +--
 .../cli/logging/impl/gossip/ColorRenderer.java  |  25 ++---
 4 files changed, 87 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/7e1b961e/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java
b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java
index b94a7bc..35c7032 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutionException.java
@@ -80,27 +80,27 @@ public class LifecycleExecutionException
     {
         Ansi buffer = ansi( /*256*/ );
 
-        buffer.a( "Failed to execute goal" ).reset();
+        buffer.fgRed().a( "Failed to execute goal" );
 
         if ( execution != null )
         {
-            buffer.a( ' ' ).a( execution.getGroupId() ).a( ':' ).a( execution.getArtifactId()
);
-            buffer.a( ':' ).a( execution.getVersion() ).a( ':' ).a( execution.getGoal() ).reset();
-            buffer.bold().a( " (" ).a( execution.getExecutionId() ).a( ')' ).reset();
+            buffer.a( ' ' ).a( execution.getGroupId() ).a( ':' ).a( execution.getArtifactId()
).
+                a( ':' ).a( execution.getVersion() ).a( ':' ).a( execution.getGoal() ).
+                a( " (" ).a( execution.getExecutionId() ).a( ')' );
+
         }
 
         if ( project != null )
         {
-            buffer.a( " on project " );
-            buffer.fgCyan().a( project.getArtifactId() ).reset();
+            buffer.a( " on project " ).a( project.getArtifactId() );
         }
 
         if ( cause != null )
         {
-            buffer.a( ": " ).bold().fgRed().a( cause.getMessage() ).reset();
+            buffer.a( ": " ).a( cause.getMessage() );
         }
 
-        return buffer.toString();
+        return buffer.reset().toString();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/7e1b961e/maven-embedder/src/main/java/org/apache/maven/cli/event/ExecutionEventLogger.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/event/ExecutionEventLogger.java
b/maven-embedder/src/main/java/org/apache/maven/cli/event/ExecutionEventLogger.java
index 7f5d65a..7180a43 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/event/ExecutionEventLogger.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/event/ExecutionEventLogger.java
@@ -51,7 +51,7 @@ public class ExecutionEventLogger
 
     private static final int LINE_LENGTH = 72;
     private static final int MAX_PADDED_BUILD_TIME_DURATION_LENGTH = 9;
-    private static final int MAX_PROJECT_NAME_LENGTH = 52;
+    private static final int MAX_PROJECT_NAME_LENGTH = LINE_LENGTH - MAX_PADDED_BUILD_TIME_DURATION_LENGTH
- 12;
 
     public ExecutionEventLogger()
     {
@@ -83,7 +83,7 @@ public class ExecutionEventLogger
 
     private void infoMain( String msg )
     {
-        logger.info( ansi().bold().a( msg ).reset().toString() );
+        logger.info( ansi().fgBlue().a( msg ).reset().toString() );
     }
 
     @Override
@@ -91,7 +91,7 @@ public class ExecutionEventLogger
     {
         if ( logger.isInfoEnabled() )
         {
-            logger.info( "Scanning for projects..." );
+            logger.info( ansi().fgBlue().a( "Scanning for projects..." ).reset().toString()
);
         }
     }
 
@@ -108,7 +108,7 @@ public class ExecutionEventLogger
 
             for ( MavenProject project : event.getSession().getProjects() )
             {
-                logger.info( project.getName() );
+                logger.info( ansi().fgBlue().a( project.getName() ).reset().toString() );
             }
         }
     }
@@ -143,61 +143,74 @@ public class ExecutionEventLogger
 
         for ( MavenProject project : session.getProjects() )
         {
-            StringBuilder buffer = new StringBuilder( 128 );
+            BuildSummary buildSummary = result.getBuildSummary( project );
+            Ansi ansi = ansi();
 
-            buffer.append( project.getName() );
-            buffer.append( ' ' );
+            if ( buildSummary == null )
+            {
+                ansi.fgYellow();
+            }
+            else if ( buildSummary instanceof BuildSuccess )
+            {
+                ansi.fgGreen();
+            }
+            else if ( buildSummary instanceof BuildFailure )
+            {
+                ansi.fgRed();
+            }
 
-            if ( buffer.length() <= MAX_PROJECT_NAME_LENGTH )
+            ansi.a( project.getName() );
+            ansi.a( ' ' );
+
+            int dots = MAX_PROJECT_NAME_LENGTH - project.getName().length();
+
+            for ( int i = 0; i < dots; i++ )
             {
-                while ( buffer.length() < MAX_PROJECT_NAME_LENGTH )
-                {
-                    buffer.append( '.' );
-                }
-                buffer.append( ' ' );
+                ansi.a( '.' );
             }
 
-            BuildSummary buildSummary = result.getBuildSummary( project );
+            ansi.a( ' ' );
 
             if ( buildSummary == null )
             {
-                buffer.append( ansi().bold().fgYellow().a( "SKIPPED" ).reset() );
+                ansi.a( "SKIPPED" );
             }
             else if ( buildSummary instanceof BuildSuccess )
             {
-                buffer.append( ansi().bold().fgGreen().a( "SUCCESS" ).reset() );
-                buffer.append( " [" );
+                ansi.a( "SUCCESS" );
+                ansi.a( " [" );
                 String buildTimeDuration = formatDuration( buildSummary.getTime() );
                 int padSize = MAX_PADDED_BUILD_TIME_DURATION_LENGTH - buildTimeDuration.length();
                 if ( padSize > 0 )
                 {
-                    buffer.append( chars( ' ', padSize ) );
+                    ansi.a( chars( ' ', padSize ) );
                 }
-                buffer.append( buildTimeDuration );
-                buffer.append( ']' );
+                ansi.a( buildTimeDuration );
+                ansi.a( ']' );
             }
             else if ( buildSummary instanceof BuildFailure )
             {
-                buffer.append( ansi().bold().fgRed().a( "FAILURE" ).reset() );
-                buffer.append( " [" );
+                ansi.a( "FAILURE" );
+                ansi.a( " [" );
                 String buildTimeDuration = formatDuration( buildSummary.getTime() );
                 int padSize = MAX_PADDED_BUILD_TIME_DURATION_LENGTH - buildTimeDuration.length();
                 if ( padSize > 0 )
                 {
-                    buffer.append( chars( ' ', padSize ) );
+                    ansi.a( chars( ' ', padSize ) );
                 }
-                buffer.append( buildTimeDuration );
-                buffer.append( ']' );
+                ansi.a( buildTimeDuration );
+                ansi.a( ']' );
             }
 
-            logger.info( buffer.toString() );
+            ansi.reset();
+            logger.info( ansi.toString() );
         }
     }
 
     private void logResult( MavenSession session )
     {
         infoLine( '-' );
-        Ansi ansi = ansi().bold();
+        Ansi ansi = ansi();
 
         if ( session.getResult().hasExceptions() )
         {
@@ -220,9 +233,9 @@ public class ExecutionEventLogger
 
         String wallClock = session.getRequest().getDegreeOfConcurrency() > 1 ? " (Wall
Clock)" : "";
 
-        logger.info( "Total time: " + formatDuration( time ) + wallClock );
+        logger.info( ansi().fgBlue().a( "Total time: " + formatDuration( time ) + wallClock
).reset().toString() );
 
-        logger.info( "Finished at: " + formatTimestamp( finish ) );
+        logger.info( ansi().fgBlue().a( "Finished at: " + formatTimestamp( finish ) ).reset().toString()
);
 
         System.gc();
 
@@ -230,7 +243,8 @@ public class ExecutionEventLogger
 
         long mb = 1024 * 1024;
 
-        logger.info( "Final Memory: " + ( r.totalMemory() - r.freeMemory() ) / mb + "M/"
+ r.totalMemory() / mb + "M" );
+        logger.info( ansi().fgBlue().a( "Final Memory: " + ( r.totalMemory() - r.freeMemory()
) / mb + "M/"
+                                            + r.totalMemory() / mb + "M" ).reset().toString()
);
     }
 
     @Override
@@ -242,7 +256,8 @@ public class ExecutionEventLogger
             infoLine( '-' );
 
             infoMain( "Skipping " + event.getProject().getName() );
-            logger.info( "This project has been banned from the build due to previous failures."
);
+            logger.info( ansi().fgBlue().a( "This project has been banned from the build
due to previous failures." ).
+                reset().toString() );
 
             infoLine( '-' );
         }
@@ -267,8 +282,11 @@ public class ExecutionEventLogger
     {
         if ( logger.isWarnEnabled() )
         {
-            logger.warn( "Goal " + event.getMojoExecution().getGoal()
-                + " requires online mode for execution but Maven is currently offline, skipping"
);
+            logger.warn( ansi().fgYellow().
+                a( "Goal " + event.getMojoExecution().getGoal()
+                       + " requires online mode for execution but Maven is currently offline,
skipping" ).
+                reset().toString() );
+
         }
     }
 
@@ -282,10 +300,10 @@ public class ExecutionEventLogger
         {
             logger.info( "" );
 
-            Ansi ansi = ansi().bold().a( "--- " ).reset();
+            Ansi ansi = ansi().fgBlue().a( "--- " ).reset();
             append( ansi, event.getMojoExecution() );
             append( ansi, event.getProject() );
-            ansi.bold().a( " ---" ).reset();
+            ansi.fgBlue().a( " ---" ).reset();
 
             logger.info( ansi.toString() );
         }
@@ -302,12 +320,12 @@ public class ExecutionEventLogger
         {
             logger.info( "" );
 
-            Ansi ansi = ansi().bold().a( ">>> " ).reset();
+            Ansi ansi = ansi().fgBlue().a( ">>> " ).reset();
             append( ansi, event.getMojoExecution() );
-            ansi.bold().a( " > " ).reset();
+            ansi.fgBlue().a( " > " ).reset();
             appendForkInfo( ansi, event.getMojoExecution().getMojoDescriptor() );
             append( ansi, event.getProject() );
-            ansi.bold().a( " >>>" ).reset();
+            ansi.fgBlue().a( " >>>" ).reset();
 
             logger.info( ansi.toString() );
         }
@@ -326,12 +344,12 @@ public class ExecutionEventLogger
         {
             logger.info( "" );
 
-            Ansi ansi = ansi().bold().a( "<<< " ).reset();
+            Ansi ansi = ansi().fgBlue().a( "<<< " ).reset();
             append( ansi, event.getMojoExecution() );
-            ansi.bold().a( " < " ).reset();
+            ansi.fgBlue().a( " < " ).reset();
             appendForkInfo( ansi, event.getMojoExecution().getMojoDescriptor() );
             append( ansi, event.getProject() );
-            ansi.bold().a( " <<<" ).reset();
+            ansi.fgBlue().a( " <<<" ).reset();
 
             logger.info( ansi.toString() );
         }
@@ -343,13 +361,13 @@ public class ExecutionEventLogger
         ansi.a( ':' ).a( me.getGoal() ).reset();
         if ( me.getExecutionId() != null )
         {
-            ansi.fgBlue().bold().a( " (" ).a( me.getExecutionId() ).a( ')' ).reset();
+            ansi.fgBlue().a( " (" ).a( me.getExecutionId() ).a( ')' ).reset();
         }
     }
 
     private void appendForkInfo( Ansi ansi, MojoDescriptor md )
     {
-        ansi.bold();
+        ansi.fgBlue();
         if ( StringUtils.isNotEmpty( md.getExecutePhase() ) )
         {
             // forked phase

http://git-wip-us.apache.org/repos/asf/maven/blob/7e1b961e/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jLogger.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jLogger.java b/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jLogger.java
index 3957464..485395e 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jLogger.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jLogger.java
@@ -20,6 +20,7 @@ package org.apache.maven.cli.logging;
  */
 
 import org.codehaus.plexus.logging.Logger;
+import static org.fusesource.jansi.Ansi.ansi;
 
 /**
  * Adapt an SLF4J logger to a Plexus logger, ignoring Plexus logger API parts that are not
classical and
@@ -71,12 +72,12 @@ public class Slf4jLogger
 
     public void warn( String message )
     {
-        logger.warn( message );
+        logger.warn( ansi().fgYellow().a( message ).reset().toString() );
     }
 
     public void warn( String message, Throwable throwable )
     {
-        logger.warn( message, throwable );
+        logger.warn( ansi().fgYellow().a( message ).reset().toString(), throwable );
     }
 
     public boolean isWarnEnabled()
@@ -86,12 +87,12 @@ public class Slf4jLogger
 
     public void error( String message )
     {
-        logger.error( message );
+        logger.error( ansi().fgRed().a( message ).reset().toString() );
     }
 
     public void error( String message, Throwable throwable )
     {
-        logger.error( message, throwable );
+        logger.error( ansi().fgRed().a( message ).reset().toString(), throwable );
     }
 
     public boolean isErrorEnabled()
@@ -101,12 +102,12 @@ public class Slf4jLogger
 
     public void fatalError( String message )
     {
-        logger.error( message );
+        logger.error( ansi().fgRed().a( message ).reset().toString() );
     }
 
     public void fatalError( String message, Throwable throwable )
     {
-        logger.error( message, throwable );
+        logger.error( ansi().fgRed().a( message ).reset().toString(), throwable );
     }
 
     public boolean isFatalErrorEnabled()

http://git-wip-us.apache.org/repos/asf/maven/blob/7e1b961e/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/gossip/ColorRenderer.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/gossip/ColorRenderer.java
b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/gossip/ColorRenderer.java
index 0f135dd..f18af9e 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/gossip/ColorRenderer.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/gossip/ColorRenderer.java
@@ -46,20 +46,20 @@ extends com.planet57.gossip.render.PatternRenderer
         {
             case TRACE:
             case DEBUG:
-                buff.append( ansi().bold().fgCyan().a( level.name() ).reset() );
+                buff.append( ansi().fgCyan().a( level.name() ).reset() );
                 break;
 
             case INFO:
-                buff.append( ansi().bold().fgBlue().a( level.name() ).reset() );
+                buff.append( ansi().fgBlue().a( level.name() ).reset() );
                 break;
 
             case WARN:
                 // Maven uses WARNING instead of WARN
-                buff.append( ansi().bold().fgYellow().a( WARNING ).reset() );
+                buff.append( ansi().fgYellow().a( WARNING ).reset() );
                 break;
 
             case ERROR:
-                buff.append( ansi().bold().fgRed().a( level.name() ).reset() );
+                buff.append( ansi().fgRed().a( level.name() ).reset() );
                 break;
 
             default:
@@ -88,11 +88,11 @@ extends com.planet57.gossip.render.PatternRenderer
             return;
         }
 
-        buff.append( ansi().bold().fgRed().a( cause.getClass().getName() ).reset() );
+        buff.append( ansi().fgRed().a( cause.getClass().getName() ).reset() );
         if ( cause.getMessage() != null )
         {
-            buff.append( ": " );
-            buff.append( ansi().bold().fgRed().a( cause.getMessage() ).reset() );
+            buff.append( ansi().fgRed().a( ": " ).reset() );
+            buff.append( ansi().fgRed().a( cause.getMessage() ).reset() );
         }
         renderNewLine( buff );
 
@@ -101,21 +101,18 @@ extends com.planet57.gossip.render.PatternRenderer
             for ( StackTraceElement e : cause.getStackTrace() )
             {
                 buff.append( "    " );
-                buff.append( ansi().bold().a( "at" ).reset().a( " " )
-                        .a( e.getClassName() ).a( "." ).a( e.getMethodName() ) );
-                buff.append( ansi().a( " (" ).bold().a( getLocation( e ) ).reset().a( ")"
) );
+                buff.append( ansi().a( "at " ).a( e.getClassName() ).a( "." ).a( e.getMethodName()
) );
+                buff.append( ansi().a( " (" ).a( getLocation( e ) ).a( ")" ).reset() );
                 renderNewLine( buff );
             }
 
             cause = cause.getCause();
             if ( cause != null )
             {
-                buff.append( ansi().bold().a( "Caused by" ).reset().a( ": " )
-                        .a( cause.getClass().getName() ) );
+                buff.append( ansi().fgRed().a( "Caused by: " ).a( cause.getClass().getName()
) );
                 if ( cause.getMessage() != null )
                 {
-                    buff.append( ": " );
-                    buff.append( ansi().bold().fgRed().a( cause.getMessage() ).reset() );
+                    buff.append( ansi().fgRed().a( ": " ).a( cause.getMessage() ).reset()
);
                 }
                 renderNewLine( buff );
             }


Mime
View raw message