Repository: maven Updated Branches: refs/heads/master 3d4cd9445 -> f381cd4f2
MNG-3507 added support for multi-lines error message with color Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/f381cd4f Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/f381cd4f Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/f381cd4f Branch: refs/heads/master Commit: f381cd4f2861461d97dfa8a7841212b0054a85ac Parents: 3d4cd94 Author: Hervé Boutemy <hbout...@apache.org> Authored: Sun Nov 13 22:37:01 2016 +0100 Committer: Hervé Boutemy <hbout...@apache.org> Committed: Sun Nov 13 22:38:01 2016 +0100 ---------------------------------------------------------------------- .../java/org/apache/maven/cli/MavenCli.java | 29 +++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/f381cd4f/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 b703aff..9e5e6b8 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 @@ -38,6 +38,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.Properties; import java.util.Set; import java.util.StringTokenizer; @@ -1119,10 +1121,29 @@ public class MavenCli } String[] lines = msg.split( "(\r\n)|(\r)|(\n)" ); + String currentColor = ""; + // TODO add multi-line color support: detect last ANSI code and if not EOC, add it to next line 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 ) ) ) @@ -1133,6 +1154,8 @@ public class MavenCli { slf4jLogger.error( line ); } + + currentColor = nextColor; } indent += " "; @@ -1143,6 +1166,10 @@ public class MavenCli } } + private static final Pattern LAST_ANSI_SEQUENCE = Pattern.compile( "(\u001B\\[[;\\d]*[ -/]*[@-~])[^\u001B]*$" ); + + private static final String ANSI_RESET = "\u001B\u005Bm"; + private void configure( CliRequest cliRequest ) throws Exception {