From b80915b8822b51aafa962a9ef53a61c0ac59033d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sun, 5 Jun 2016 13:11:45 +0200 Subject: [PATCH] [MNG-3507] added color to Maven execution output messages --- apache-maven/pom.xml | 4 + apache-maven/src/bin/mvn | 1 + apache-maven/src/bin/mvn.cmd | 2 +- maven-core/pom.xml | 4 + .../LifecycleExecutionException.java | 27 ++-- .../resources/META-INF/maven/extension.xml | 3 + maven-embedder/pom.xml | 4 + .../java/org/apache/maven/cli/CLIManager.java | 4 +- .../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(-) diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index 735e5b8127..f7c28edf9f 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -91,6 +91,10 @@ org.slf4j slf4j-simple + + org.fusesource.jansi + jansi + diff --git a/apache-maven/src/bin/mvn b/apache-maven/src/bin/mvn index 6875628599..f3acb73e6c 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} "$@" diff --git a/apache-maven/src/bin/mvn.cmd b/apache-maven/src/bin/mvn.cmd index d35c1d2047..5ad99aefdb 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 diff --git a/maven-core/pom.xml b/maven-core/pom.xml index ac1968b53b..efff5c11da 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -75,6 +75,10 @@ org.eclipse.aether aether-util + + org.apache.maven.shared + maven-shared-utils + org.eclipse.sisu 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 349576cdc9..62ae269ea7 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 Jason van Zyl @@ -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(); 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 e3af5a0876..07e60aa914 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. org.slf4j.spi.* org.slf4j.helpers.* + + org.fusesource.jansi.* @@ -156,6 +158,7 @@ under the License. javax.inject:javax.inject org.slf4j:slf4j-api + org.fusesource.jansi:jansi