maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject [3/4] maven git commit: [MNG-3507] added color to Maven execution output messages
Date Mon, 23 Jan 2017 07:32:43 GMT
[MNG-3507] added color to Maven execution output messages

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

Branch: refs/heads/MNG-3507
Commit: 5295a27191df49e24c79fe10c74141e187c4a4a4
Parents: c516ef7
Author: Hervé Boutemy <hboutemy@apache.org>
Authored: Sun Jun 5 13:11:45 2016 +0200
Committer: Hervé Boutemy <hboutemy@apache.org>
Committed: Mon Jan 23 08:28:36 2017 +0100

----------------------------------------------------------------------
 apache-maven/pom.xml                            |   4 +
 apache-maven/src/bin/mvn                        |   1 +
 apache-maven/src/bin/mvn.cmd                    |   2 +-
 maven-core/pom.xml                              |   4 +
 .../lifecycle/LifecycleExecutionException.java  |  27 ++---
 .../main/resources/META-INF/maven/extension.xml |   3 +
 maven-embedder/pom.xml                          |   4 +
 .../java/org/apache/maven/cli/CLIManager.java   |   4 +-
 .../org/apache/maven/cli/CLIReportingUtils.java |   6 +-
 .../java/org/apache/maven/cli/MavenCli.java     |  87 ++++++++++++--
 .../maven/cli/event/ExecutionEventLogger.java   | 117 ++++++++++---------
 maven-embedder/src/site/apt/index.apt.vm        |   5 +
 pom.xml                                         |  10 ++
 13 files changed, 192 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/5295a271/apache-maven/pom.xml
----------------------------------------------------------------------
diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml
index 2db95cf..436aa9d 100644
--- a/apache-maven/pom.xml
+++ b/apache-maven/pom.xml
@@ -91,6 +91,10 @@
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-simple</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.fusesource.jansi</groupId>
+      <artifactId>jansi</artifactId>
+    </dependency>
   </dependencies>
 
   <build>

http://git-wip-us.apache.org/repos/asf/maven/blob/5295a271/apache-maven/src/bin/mvn
----------------------------------------------------------------------
diff --git a/apache-maven/src/bin/mvn b/apache-maven/src/bin/mvn
index 6875628..f3acb73 100755
--- a/apache-maven/src/bin/mvn
+++ b/apache-maven/src/bin/mvn
@@ -241,4 +241,5 @@ exec "$JAVACMD" \
   -classpath "${M2_HOME}"/boot/plexus-classworlds-*.jar \
   "-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
   "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}"
\
+  "-Dlibrary.jansi.path=${MAVEN_HOME}/lib/ext" \
   ${CLASSWORLDS_LAUNCHER} "$@"

http://git-wip-us.apache.org/repos/asf/maven/blob/5295a271/apache-maven/src/bin/mvn.cmd
----------------------------------------------------------------------
diff --git a/apache-maven/src/bin/mvn.cmd b/apache-maven/src/bin/mvn.cmd
index d35c1d2..5ad99ae 100644
--- a/apache-maven/src/bin/mvn.cmd
+++ b/apache-maven/src/bin/mvn.cmd
@@ -154,7 +154,7 @@ for %%i in ("%M2_HOME%"\boot\plexus-classworlds-*) do set CLASSWORLDS_JAR="%%i"
 
 set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
 
-%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %CLASSWORLDS_JAR%
"-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Dmaven.home=%M2_HOME%" "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%"
%CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
+%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %CLASSWORLDS_JAR%
"-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Dmaven.home=%M2_HOME%" "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%"
"-Dlibrary.jansi.path=%MAVEN_HOME%\lib\ext" %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
 if ERRORLEVEL 1 goto error
 goto end
 

http://git-wip-us.apache.org/repos/asf/maven/blob/5295a271/maven-core/pom.xml
----------------------------------------------------------------------
diff --git a/maven-core/pom.xml b/maven-core/pom.xml
index ac1968b..efff5c1 100644
--- a/maven-core/pom.xml
+++ b/maven-core/pom.xml
@@ -75,6 +75,10 @@
       <groupId>org.eclipse.aether</groupId>
       <artifactId>aether-util</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-shared-utils</artifactId>
+    </dependency>
     <!-- Plexus -->
     <dependency>
       <groupId>org.eclipse.sisu</groupId>

http://git-wip-us.apache.org/repos/asf/maven/blob/5295a271/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 349576c..62ae269 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
@@ -19,8 +19,11 @@ package org.apache.maven.lifecycle;
  * under the License.
  */
 
+import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
+
 import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.utils.logging.MessageBuilder;
 
 /**
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@@ -75,34 +78,26 @@ public class LifecycleExecutionException
 
     private static String createMessage( MojoExecution execution, MavenProject project, Throwable
cause )
     {
-        StringBuilder buffer = new StringBuilder( 256 );
+        MessageBuilder buffer = buffer( 256 );
 
-        buffer.append( "Failed to execute goal" );
+        buffer.a( "Failed to execute goal" );
 
         if ( execution != null )
         {
-            buffer.append( ' ' );
-            buffer.append( execution.getGroupId() );
-            buffer.append( ':' );
-            buffer.append( execution.getArtifactId() );
-            buffer.append( ':' );
-            buffer.append( execution.getVersion() );
-            buffer.append( ':' );
-            buffer.append( execution.getGoal() );
-            buffer.append( " (" );
-            buffer.append( execution.getExecutionId() );
-            buffer.append( ")" );
+            buffer.a( ' ' ).a( execution.getGroupId() ).a( ':' );
+            buffer.mojo( execution.getArtifactId() + ':' + execution.getVersion() + ':' +
execution.getGoal() );
+            buffer.a( ' ' ).strong( '(' + execution.getExecutionId() + ')' );
         }
 
         if ( project != null )
         {
-            buffer.append( " on project " );
-            buffer.append( project.getArtifactId() );
+            buffer.a( " on project " );
+            buffer.project( project.getArtifactId() );
         }
 
         if ( cause != null )
         {
-            buffer.append( ": " ).append( cause.getMessage() );
+            buffer.a( ": " ).failure( cause.getMessage() );
         }
 
         return buffer.toString();

http://git-wip-us.apache.org/repos/asf/maven/blob/5295a271/maven-core/src/main/resources/META-INF/maven/extension.xml
----------------------------------------------------------------------
diff --git a/maven-core/src/main/resources/META-INF/maven/extension.xml b/maven-core/src/main/resources/META-INF/maven/extension.xml
index e3af5a0..07e60aa 100644
--- a/maven-core/src/main/resources/META-INF/maven/extension.xml
+++ b/maven-core/src/main/resources/META-INF/maven/extension.xml
@@ -118,6 +118,8 @@ under the License.
     <exportedPackage>org.slf4j.spi.*</exportedPackage>
     <exportedPackage>org.slf4j.helpers.*</exportedPackage>
 
+    <!-- JAnsi -->
+    <exportedPackage>org.fusesource.jansi.*</exportedPackage>
   </exportedPackages>
 
   <exportedArtifacts>
@@ -156,6 +158,7 @@ under the License.
 
     <exportedArtifact>javax.inject:javax.inject</exportedArtifact>
     <exportedArtifact>org.slf4j:slf4j-api</exportedArtifact>
+    <exportedArtifact>org.fusesource.jansi:jansi</exportedArtifact>
 
     <!--
       | We must also filter out the old or NoClassDefFoundErrors will surface  

http://git-wip-us.apache.org/repos/asf/maven/blob/5295a271/maven-embedder/pom.xml
----------------------------------------------------------------------
diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml
index e02e43d..04b8da6 100644
--- a/maven-embedder/pom.xml
+++ b/maven-embedder/pom.xml
@@ -47,6 +47,10 @@
       <scope>runtime</scope>
     </dependency>
     <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-shared-utils</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
     </dependency>

http://git-wip-us.apache.org/repos/asf/maven/blob/5295a271/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
index f461835..673f52d 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
@@ -108,7 +108,7 @@ public class CLIManager
     {
         options = new Options();
         options.addOption( OptionBuilder.withLongOpt( "help" ).withDescription( "Display
help information" ).create( HELP ) );
-        options.addOption( OptionBuilder.withLongOpt( "file" ).hasArg().withDescription(
"Force the use of an alternate POM file (or directory with pom.xml)." ).create( ALTERNATE_POM_FILE
) );
+        options.addOption( OptionBuilder.withLongOpt( "file" ).hasArg().withDescription(
"Force the use of an alternate POM file (or directory with pom.xml, disables output color)"
).create( ALTERNATE_POM_FILE ) );
         options.addOption( OptionBuilder.withLongOpt( "define" ).hasArg().withDescription(
"Define a system property" ).create( SET_SYSTEM_PROPERTY ) );
         options.addOption( OptionBuilder.withLongOpt( "offline" ).withDescription( "Work
offline" ).create( OFFLINE ) );
         options.addOption( OptionBuilder.withLongOpt( "version" ).withDescription( "Display
version information" ).create( VERSION ) );
@@ -118,7 +118,7 @@ public class CLIManager
         options.addOption( OptionBuilder.withLongOpt( "non-recursive" ).withDescription(
"Do not recurse into sub-projects" ).create( NON_RECURSIVE ) );
         options.addOption( OptionBuilder.withLongOpt( "update-snapshots" ).withDescription(
"Forces a check for missing releases and updated snapshots on remote repositories" ).create(
UPDATE_SNAPSHOTS ) );
         options.addOption( OptionBuilder.withLongOpt( "activate-profiles" ).withDescription(
"Comma-delimited list of profiles to activate" ).hasArg().create( ACTIVATE_PROFILES ) );
-        options.addOption( OptionBuilder.withLongOpt( "batch-mode" ).withDescription( "Run
in non-interactive (batch) mode" ).create( BATCH_MODE ) );
+        options.addOption( OptionBuilder.withLongOpt( "batch-mode" ).withDescription( "Run
in non-interactive (batch) mode (disables output color)" ).create( BATCH_MODE ) );
         options.addOption( OptionBuilder.withLongOpt( "no-snapshot-updates" ).withDescription(
"Suppress SNAPSHOT updates" ).create( SUPRESS_SNAPSHOT_UPDATES ) );
         options.addOption( OptionBuilder.withLongOpt( "strict-checksums" ).withDescription(
"Fail the build if checksums don't match" ).create( CHECKSUM_FAILURE_POLICY ) );
         options.addOption( OptionBuilder.withLongOpt( "lax-checksums" ).withDescription(
"Warn if checksums don't match" ).create( CHECKSUM_WARNING_POLICY ) );

http://git-wip-us.apache.org/repos/asf/maven/blob/5295a271/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java
index 2397d5d..8c1e58a 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java
@@ -19,6 +19,8 @@ package org.apache.maven.cli;
  * under the License.
  */
 
+import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
+
 import org.codehaus.plexus.util.Os;
 import org.slf4j.Logger;
 
@@ -54,8 +56,8 @@ public final class CLIReportingUtils
     {
         final String ls = System.getProperty( "line.separator" );
         Properties properties = getBuildProperties();
-        StringBuilder version = new StringBuilder();
-        version.append( createMavenVersionString( properties ) ).append( ls );
+        StringBuilder version = new StringBuilder( 256 );
+        version.append( buffer().strong( createMavenVersionString( properties ) ) ).append(
ls );
         version.append( reduce(
             properties.getProperty( "distributionShortName" ) + " home: " + System.getProperty(
"maven.home",
                                                                                         
       "<unknown Maven "

http://git-wip-us.apache.org/repos/asf/maven/blob/5295a271/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index 176ce4d..5551ff9 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -19,6 +19,8 @@ package org.apache.maven.cli;
  * under the License.
  */
 
+import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
+
 import com.google.common.base.Charsets;
 import com.google.common.io.Files;
 import com.google.inject.AbstractModule;
@@ -62,6 +64,8 @@ import org.apache.maven.model.building.ModelProcessor;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.properties.internal.EnvironmentUtils;
 import org.apache.maven.properties.internal.SystemProperties;
+import org.apache.maven.shared.utils.logging.MessageBuilder;
+import org.apache.maven.shared.utils.logging.MessageUtils;
 import org.apache.maven.toolchain.building.DefaultToolchainsBuildingRequest;
 import org.apache.maven.toolchain.building.ToolchainsBuilder;
 import org.apache.maven.toolchain.building.ToolchainsBuildingResult;
@@ -107,6 +111,8 @@ import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.Set;
 import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 // TODO: push all common bits back to plexus cli and prepare for transition to Guice. We
don't need 50 ways to make CLIs
 
@@ -196,7 +202,12 @@ public class MavenCli
     public static int main( String[] args, ClassWorld classWorld )
     {
         MavenCli cli = new MavenCli();
-        return cli.doMain( new CliRequest( args, classWorld ) );
+
+        MessageUtils.systemInstall();
+        int result = cli.doMain( new CliRequest( args, classWorld ) );
+        MessageUtils.systemUninstall();
+
+        return result;
     }
 
     // TODO: need to externalize CliRequest
@@ -206,7 +217,11 @@ public class MavenCli
         return cli.doMain( new CliRequest( args, classWorld ) );
     }
 
-    // This supports painless invocation by the Verifier during embedded execution of the
core ITs
+    /**
+     * This supports painless invocation by the Verifier during embedded execution of the
core ITs.
+     * See <a href="http://maven.apache.org/shared/maven-verifier/xref/org/apache/maven/it/Embedded3xLauncher.html">
+     * <code>Embedded3xLauncher</code> in <code>maven-verifier</code></a>
+     */
     public int doMain( String[] args, String workingDirectory, PrintStream stdout, PrintStream
stderr )
     {
         PrintStream oldout = System.out;
@@ -450,11 +465,18 @@ public class MavenCli
         // else fall back to default log level specified in conf
         // see https://issues.apache.org/jira/browse/MNG-2570
 
+        if ( cliRequest.commandLine.hasOption( CLIManager.BATCH_MODE ) )
+        {
+            MessageUtils.setColorEnabled( false );
+        }
+
         if ( cliRequest.commandLine.hasOption( CLIManager.LOG_FILE ) )
         {
             File logFile = new File( cliRequest.commandLine.getOptionValue( CLIManager.LOG_FILE
) );
             logFile = resolveFile( logFile, cliRequest.workingDirectory );
 
+            MessageUtils.setColorEnabled( false );
+
             // redirect stdout and stderr to file
             try
             {
@@ -499,6 +521,26 @@ public class MavenCli
         {
             slf4jLogger.info( "Enabling strict checksum verification on all artifact downloads."
);
         }
+
+        if ( slf4jLogger.isDebugEnabled() )
+        {
+            slf4jLogger.debug( "Message scheme: " + ( MessageUtils.isColorEnabled() ? "color"
: "plain" ) );
+            if ( MessageUtils.isColorEnabled() )
+            {
+                MessageBuilder buff = MessageUtils.buffer();
+                buff.a( "Message styles: " );
+                buff.debug( "debug" ).a( ' ' );
+                buff.info( "info" ).a( ' ' );
+                buff.warning( "warning" ).a( ' ' );
+                buff.error( "error" ).a( ' ' );
+                buff.success( "success" ).a( ' ' );
+                buff.failure( "failure" ).a( ' ' );
+                buff.strong( "strong" ).a( ' ' );
+                buff.mojo( "mojo" ).a( ' ' );
+                buff.project( "project" );
+                slf4jLogger.debug( buff.toString() );
+            }
+        }
     }
 
     private void properties( CliRequest cliRequest )
@@ -890,11 +932,13 @@ public class MavenCli
 
             if ( !cliRequest.showErrors )
             {
-                slf4jLogger.error( "To see the full stack trace of the errors, re-run Maven
with the -e switch." );
+                slf4jLogger.error( "To see the full stack trace of the errors, re-run Maven
with the "
+                    + buffer().strong( "-e" ) + " switch." );
             }
             if ( !slf4jLogger.isDebugEnabled() )
             {
-                slf4jLogger.error( "Re-run Maven using the -X switch to enable full debug
logging." );
+                slf4jLogger.error( "Re-run Maven using the " + buffer().strong( "-X" )
+                    + " switch to enable full debug logging." );
             }
 
             if ( !references.isEmpty() )
@@ -905,7 +949,7 @@ public class MavenCli
 
                 for ( Map.Entry<String, String> entry : references.entrySet() )
                 {
-                    slf4jLogger.error( entry.getValue() + " " + entry.getKey() );
+                    slf4jLogger.error( buffer().strong( entry.getValue() ) + " " + entry.getKey()
);
                 }
             }
 
@@ -913,7 +957,8 @@ public class MavenCli
             {
                 slf4jLogger.error( "" );
                 slf4jLogger.error( "After correcting the problems, you can resume the build
with the command" );
-                slf4jLogger.error( "  mvn <goals> -rf :" + project.getArtifactId()
);
+                slf4jLogger.error( buffer().a( "  " ).strong( "mvn <goals> -rf :"
+                                + project.getArtifactId() ).toString() );
             }
 
             if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( cliRequest.request.getReactorFailureBehavior()
) )
@@ -954,19 +999,37 @@ public class MavenCli
         {
             if ( msg.indexOf( '\n' ) < 0 )
             {
-                msg += " -> " + referenceKey;
+                msg += " -> " + buffer().strong( referenceKey );
             }
             else
             {
-                msg += "\n-> " + referenceKey;
+                msg += "\n-> " + buffer().strong( referenceKey );
             }
         }
 
         String[] lines = msg.split( "(\r\n)|(\r)|(\n)" );
+        String currentColor = "";
 
         for ( int i = 0; i < lines.length; i++ )
         {
-            String line = indent + lines[i].trim();
+            // add eventual current color inherited from previous line 
+            String line = currentColor + lines[i];
+
+            // look for last ANSI escape sequence to check if nextColor
+            Matcher matcher = LAST_ANSI_SEQUENCE.matcher( line );
+            String nextColor = "";
+            if ( matcher.find() )
+            {
+                nextColor = matcher.group( 1 );
+                if ( ANSI_RESET.equals( nextColor ) )
+                {
+                    // last ANSI escape code is reset: no next color
+                    nextColor = "";
+                }
+            }
+
+            // effective line, with indent and reset if end is colored
+            line = indent + line + ( "".equals( nextColor ) ? "" : ANSI_RESET );
 
             if ( ( i == lines.length - 1 ) && ( showErrors
                 || ( summary.getException() instanceof InternalErrorException ) ) )
@@ -977,6 +1040,8 @@ public class MavenCli
             {
                 slf4jLogger.error( line );
             }
+
+            currentColor = nextColor;
         }
 
         indent += "  ";
@@ -987,6 +1052,10 @@ public class MavenCli
         }
     }
 
+    private static final Pattern LAST_ANSI_SEQUENCE = Pattern.compile( "(\u001B\\[[;\\d]*[
-/]*[@-~])[^\u001B]*$" );
+
+    private static final String ANSI_RESET = "\u001B\u005Bm";
+
     @SuppressWarnings( "checkstyle:methodlength" )
     private void configure( CliRequest cliRequest )
         throws Exception

http://git-wip-us.apache.org/repos/asf/maven/blob/5295a271/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 a0eab13..25ec38d 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
@@ -21,6 +21,7 @@ package org.apache.maven.cli.event;
 
 import static org.apache.maven.cli.CLIReportingUtils.formatDuration;
 import static org.apache.maven.cli.CLIReportingUtils.formatTimestamp;
+import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
 
 import org.apache.commons.lang3.Validate;
 import org.apache.maven.execution.AbstractExecutionListener;
@@ -33,6 +34,7 @@ import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.utils.logging.MessageBuilder;
 import org.codehaus.plexus.util.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -74,6 +76,16 @@ public class ExecutionEventLogger
         return buffer.toString();
     }
 
+    private void infoLine( char c )
+    {
+        infoMain( chars( c, LINE_LENGTH ) );
+    }
+
+    private void infoMain( String msg )
+    {
+        logger.info( buffer().strong( msg ).toString() );
+    }
+
     @Override
     public void projectDiscoveryStarted( ExecutionEvent event )
     {
@@ -88,9 +100,9 @@ public class ExecutionEventLogger
     {
         if ( logger.isInfoEnabled() && event.getSession().getProjects().size() >
1 )
         {
-            logger.info( chars( '-', LINE_LENGTH ) );
+            infoLine( '-' );
 
-            logger.info( "Reactor Build Order:" );
+            infoMain( "Reactor Build Order:" );
 
             logger.info( "" );
 
@@ -115,15 +127,15 @@ public class ExecutionEventLogger
 
             logStats( event.getSession() );
 
-            logger.info( chars( '-', LINE_LENGTH ) );
+            infoLine( '-' );
         }
     }
 
     private void logReactorSummary( MavenSession session )
     {
-        logger.info( chars( '-', LINE_LENGTH ) );
+        infoLine( '-' );
 
-        logger.info( "Reactor Summary:" );
+        infoMain( "Reactor Summary:" );
 
         logger.info( "" );
 
@@ -149,11 +161,12 @@ public class ExecutionEventLogger
 
             if ( buildSummary == null )
             {
-                buffer.append( "SKIPPED" );
+                buffer.append( buffer().warning( "SKIPPED" ) );
             }
             else if ( buildSummary instanceof BuildSuccess )
             {
-                buffer.append( "SUCCESS [" );
+                buffer.append( buffer().success( "SUCCESS" ) );
+                buffer.append( " [" );
                 String buildTimeDuration = formatDuration( buildSummary.getTime() );
                 int padSize = MAX_PADDED_BUILD_TIME_DURATION_LENGTH - buildTimeDuration.length();
                 if ( padSize > 0 )
@@ -165,7 +178,8 @@ public class ExecutionEventLogger
             }
             else if ( buildSummary instanceof BuildFailure )
             {
-                buffer.append( "FAILURE [" );
+                buffer.append( buffer().failure( "FAILURE" ) );
+                buffer.append( " [" );
                 String buildTimeDuration = formatDuration( buildSummary.getTime() );
                 int padSize = MAX_PADDED_BUILD_TIME_DURATION_LENGTH - buildTimeDuration.length();
                 if ( padSize > 0 )
@@ -182,21 +196,23 @@ public class ExecutionEventLogger
 
     private void logResult( MavenSession session )
     {
-        logger.info( chars( '-', LINE_LENGTH ) );
+        infoLine( '-' );
+        MessageBuilder buffer = buffer();
 
         if ( session.getResult().hasExceptions() )
         {
-            logger.info( "BUILD FAILURE" );
+            buffer.failure( "BUILD FAILURE" );
         }
         else
         {
-            logger.info( "BUILD SUCCESS" );
+            buffer.success( "BUILD SUCCESS" );
         }
+        logger.info( buffer.toString() );
     }
 
     private void logStats( MavenSession session )
     {
-        logger.info( chars( '-', LINE_LENGTH ) );
+        infoLine( '-' );
 
         long finish = System.currentTimeMillis();
 
@@ -222,13 +238,13 @@ public class ExecutionEventLogger
     {
         if ( logger.isInfoEnabled() )
         {
-            logger.info( chars( ' ', LINE_LENGTH ) );
-            logger.info( chars( '-', LINE_LENGTH ) );
+            logger.info( "" );
+            infoLine( '-' );
 
-            logger.info( "Skipping " + event.getProject().getName() );
+            infoMain( "Skipping " + event.getProject().getName() );
             logger.info( "This project has been banned from the build due to previous failures."
);
 
-            logger.info( chars( '-', LINE_LENGTH ) );
+            infoLine( '-' );
         }
     }
 
@@ -237,12 +253,12 @@ public class ExecutionEventLogger
     {
         if ( logger.isInfoEnabled() )
         {
-            logger.info( chars( ' ', LINE_LENGTH ) );
-            logger.info( chars( '-', LINE_LENGTH ) );
+            logger.info( "" );
+            infoLine( '-' );
 
-            logger.info( "Building " + event.getProject().getName() + " " + event.getProject().getVersion()
);
+            infoMain( "Building " + event.getProject().getName() + " " + event.getProject().getVersion()
);
 
-            logger.info( chars( '-', LINE_LENGTH ) );
+            infoLine( '-' );
         }
     }
 
@@ -264,14 +280,13 @@ public class ExecutionEventLogger
     {
         if ( logger.isInfoEnabled() )
         {
-            StringBuilder buffer = new StringBuilder( 128 );
+            logger.info( "" );
 
-            buffer.append( "--- " );
+            MessageBuilder buffer = buffer().strong( "--- " );
             append( buffer, event.getMojoExecution() );
             append( buffer, event.getProject() );
-            buffer.append( " ---" );
+            buffer.strong( " ---" );
 
-            logger.info( "" );
             logger.info( buffer.toString() );
         }
     }
@@ -285,16 +300,15 @@ public class ExecutionEventLogger
     {
         if ( logger.isInfoEnabled() )
         {
-            StringBuilder buffer = new StringBuilder( 128 );
+            logger.info( "" );
 
-            buffer.append( ">>> " );
+            MessageBuilder buffer = buffer().strong( ">>> " );
             append( buffer, event.getMojoExecution() );
-            buffer.append( " > " );
+            buffer.strong( " > " );
             appendForkInfo( buffer, event.getMojoExecution().getMojoDescriptor() );
             append( buffer, event.getProject() );
-            buffer.append( " >>>" );
+            buffer.strong( " >>>" );
 
-            logger.info( "" );
             logger.info( buffer.toString() );
         }
     }
@@ -310,56 +324,56 @@ public class ExecutionEventLogger
     {
         if ( logger.isInfoEnabled() )
         {
-            StringBuilder buffer = new StringBuilder( 128 );
+            logger.info( "" );
 
-            buffer.append( "<<< " );
+            MessageBuilder buffer = buffer().strong( "<<< " );
             append( buffer, event.getMojoExecution() );
-            buffer.append( " < " );
+            buffer.strong( " < " );
             appendForkInfo( buffer, event.getMojoExecution().getMojoDescriptor() );
             append( buffer, event.getProject() );
-            buffer.append( " <<<" );
+            buffer.strong( " <<<" );
 
-            logger.info( "" );
             logger.info( buffer.toString() );
 
             logger.info( "" );
         }
     }
 
-    private void append( StringBuilder buffer, MojoExecution me )
+    private void append( MessageBuilder buffer, MojoExecution me )
     {
-        buffer.append( me.getArtifactId() ).append( ':' ).append( me.getVersion() );
-        buffer.append( ':' ).append( me.getGoal() );
+        buffer.mojo( me.getArtifactId() + ':' + me.getVersion() + ':' + me.getGoal() );
         if ( me.getExecutionId() != null )
         {
-            buffer.append( " (" ).append( me.getExecutionId() ).append( ')' );
+            buffer.a( ' ' ).strong( '(' + me.getExecutionId() + ')' );
         }
     }
 
-    private void appendForkInfo( StringBuilder buffer, MojoDescriptor md )
+    private void appendForkInfo( MessageBuilder buffer, MojoDescriptor md )
     {
+        StringBuilder buff = new StringBuilder();
         if ( StringUtils.isNotEmpty( md.getExecutePhase() ) )
         {
             // forked phase
             if ( StringUtils.isNotEmpty( md.getExecuteLifecycle() ) )
             {
-                buffer.append( '[' );
-                buffer.append( md.getExecuteLifecycle() );
-                buffer.append( ']' );
+                buff.append( '[' );
+                buff.append( md.getExecuteLifecycle() );
+                buff.append( ']' );
             }
-            buffer.append( md.getExecutePhase() );
+            buff.append( md.getExecutePhase() );
         }
         else
         {
             // forked goal
-            buffer.append( ':' );
-            buffer.append( md.getExecuteGoal() );
+            buff.append( ':' );
+            buff.append( md.getExecuteGoal() );
         }
+        buffer.strong( buff.toString() );
     }
 
-    private void append( StringBuilder buffer, MavenProject project )
+    private void append( MessageBuilder buffer, MavenProject project )
     {
-        buffer.append( " @ " ).append( project.getArtifactId() );
+        buffer.a( " @ " ).project( project.getArtifactId() );
     }
 
     @Override
@@ -367,13 +381,12 @@ public class ExecutionEventLogger
     {
         if ( logger.isInfoEnabled() && event.getMojoExecution().getForkedExecutions().size()
> 1 )
         {
-            logger.info( chars( ' ', LINE_LENGTH ) );
-            logger.info( chars( '>', LINE_LENGTH ) );
+            logger.info( "" );
+            infoLine( '>' );
 
-            logger.info( "Forking " + event.getProject().getName() + " " + event.getProject().getVersion()
);
+            infoMain( "Forking " + event.getProject().getName() + " " + event.getProject().getVersion()
);
 
-            logger.info( chars( '>', LINE_LENGTH ) );
+            infoLine( '>' );
         }
     }
-
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/5295a271/maven-embedder/src/site/apt/index.apt.vm
----------------------------------------------------------------------
diff --git a/maven-embedder/src/site/apt/index.apt.vm b/maven-embedder/src/site/apt/index.apt.vm
index 519fdae..17220c9 100644
--- a/maven-embedder/src/site/apt/index.apt.vm
+++ b/maven-embedder/src/site/apt/index.apt.vm
@@ -40,3 +40,8 @@ ${project.name}
    * <<<.mvn/maven.config>>> containing Maven command-line parameter,
 
    * <<<.mvn/extensions.xml>>> containing {{{./core-extensions.html}a list
of extensions}}.
+
+ * since 3.5.0, output is colorized by default, with color disabled in batch mode: see
+   {{{/shared/maven-shared-utils/apidocs/org/apache/maven/shared/utils/logging/package-summary.html}styled
message API}}
+   for more details.
+   
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/maven/blob/5295a271/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 8ea9b29..f8b67aa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -267,6 +267,16 @@
         <version>${plexusInterpolationVersion}</version>
       </dependency>
       <dependency>
+        <groupId>org.apache.maven.shared</groupId>
+        <artifactId>maven-shared-utils</artifactId>
+        <version>3.1.0</version>
+      </dependency>
+      <dependency>
+        <groupId>org.fusesource.jansi</groupId>
+        <artifactId>jansi</artifactId>
+        <version>1.13</version>
+      </dependency>
+      <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-api</artifactId>
         <version>${slf4jVersion}</version>


Mime
View raw message