Repository: maven Updated Branches: refs/heads/MNG-6006 1ac426708 -> 0d785b59c (forced update)
[MNG-6037] add support for Gossip slf4j provider Submitted by: Jason Dillon Applied with modifications since general Maven color support was extracted from logging in MNG-3507 this closes #81 Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/427f18c3 Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/427f18c3 Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/427f18c3 Branch: refs/heads/MNG-6006 Commit: 427f18c3a3c4ee1e7e88895e5346260a0917a43a Parents: 2859eb0 Author: Hervé Boutemy <hbout...@apache.org> Authored: Sat Jun 11 13:09:36 2016 +0200 Committer: Hervé Boutemy <hbout...@apache.org> Committed: Sat Jun 11 13:09:36 2016 +0200 ---------------------------------------------------------------------- maven-embedder/pom.xml | 5 + .../impl/gossip/ColorConsoleListener.java | 72 +++++++++++ .../cli/logging/impl/gossip/ColorRenderer.java | 124 +++++++++++++++++++ .../impl/gossip/GossipConfiguration.java | 63 ++++++++++ .../com.planet57.gossip/config.properties | 30 +++++ .../maven/slf4j-configuration.properties | 1 + pom.xml | 9 ++ 7 files changed, 304 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/427f18c3/maven-embedder/pom.xml ---------------------------------------------------------------------- diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index 0c86310..eb72f93 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -97,6 +97,11 @@ under the License. <artifactId>logback-classic</artifactId> <optional>true</optional> </dependency> + <dependency> + <groupId>com.planet57.gossip</groupId> + <artifactId>gossip-slf4j</artifactId> + <optional>true</optional> + </dependency> <!-- CLI --> <dependency> <groupId>commons-cli</groupId> http://git-wip-us.apache.org/repos/asf/maven/blob/427f18c3/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/gossip/ColorConsoleListener.java ---------------------------------------------------------------------- diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/gossip/ColorConsoleListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/gossip/ColorConsoleListener.java new file mode 100644 index 0000000..b9c97a9 --- /dev/null +++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/gossip/ColorConsoleListener.java @@ -0,0 +1,72 @@ +package org.apache.maven.cli.logging.impl.gossip; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.PrintStream; + +import com.planet57.gossip.listener.ConsoleListener; +import org.fusesource.jansi.AnsiConsole; +import org.fusesource.jansi.internal.CLibrary; + +/** + * Specialized {@link com.planet57.gossip.listener.Listener} which is aware of ANSI streams. + * + * @author <a href="mailto:ja...@planet57.com">Jason Dillon</a> + * @since 3.4.0 + */ +public class ColorConsoleListener + extends ConsoleListener +{ + private PrintStream out; + + /** + * Returns file descriptor identifier for the configured stream. + */ + private int getFileno() + { + switch ( getStream() ) + { + case OUT: + return CLibrary.STDOUT_FILENO; + + case ERR: + return CLibrary.STDERR_FILENO; + + default: + throw new InternalError(); + } + } + + /** + * Returns an ANSI aware wrapped stream. + * + * Needed so that jansi (limited) logic to detect supported streams is applied and copes with + * redirection of stream to file to strip out ANSI sequences. + */ + @Override + protected PrintStream getOut() + { + if ( out == null ) + { + out = new PrintStream( AnsiConsole.wrapOutputStream( super.getOut(), getFileno() ) ); + } + return out; + } +} http://git-wip-us.apache.org/repos/asf/maven/blob/427f18c3/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 new file mode 100644 index 0000000..00007cc --- /dev/null +++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/gossip/ColorRenderer.java @@ -0,0 +1,124 @@ +package org.apache.maven.cli.logging.impl.gossip; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import static org.fusesource.jansi.Ansi.ansi; + +import com.planet57.gossip.Event; +import com.planet57.gossip.Level; + +/** + * Specialized {@link com.planet57.gossip.render.Renderer} which colorizes level and error rendering. + * + * @author <a href="mailto:ja...@planet57.com">Jason Dillon</a> + * @since 3.4.0 + */ +public class ColorRenderer +extends com.planet57.gossip.render.PatternRenderer +{ + protected static final String WARNING = "WARNING"; + + @Override + protected void renderLevel( final Event event, final StringBuilder buff ) + { + assert event != null; + assert buff != null; + + Level level = event.getLevel(); + switch ( level ) + { + case TRACE: + case DEBUG: + buff.append( ansi().bold().fgCyan().a( level.name() ).reset() ); + break; + + case INFO: + buff.append( ansi().bold().fgGreen().a( level.name() ).reset() ); + break; + + case WARN: + // Maven uses WARNING instead of WARN + buff.append( ansi().bold().fgYellow().a( WARNING ).reset() ); + break; + + case ERROR: + buff.append( ansi().bold().fgRed().a( level.name() ).reset() ); + break; + + default: + throw new InternalError(); + } + } + + @Override + protected void renderName( final Event event, final StringBuilder buff, final boolean shortName ) + { + StringBuilder tmp = new StringBuilder(); + super.renderName( event, tmp, shortName ); + buff.append( ansi().fgGreen().a( tmp ).reset() ); + } + + + @Override + protected void renderCause( final Event event, final StringBuilder buff ) + { + assert event != null; + assert buff != null; + + Throwable cause = event.getCause(); + if ( cause == null ) + { + return; + } + + buff.append( ansi().bold().fgRed().a( cause.getClass().getName() ).reset() ); + if ( cause.getMessage() != null ) + { + buff.append( ": " ); + buff.append( ansi().bold().fgRed().a( cause.getMessage() ).reset() ); + } + renderNewLine( buff ); + + while ( cause != null ) + { + 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( ")" ) ); + renderNewLine( buff ); + } + + cause = cause.getCause(); + if ( cause != null ) + { + buff.append( ansi().bold().a( "Caused by" ).reset().a( ": " ) + .a( cause.getClass().getName() ) ); + if ( cause.getMessage() != null ) + { + buff.append( ": " ); + buff.append( ansi().bold().fgRed().a( cause.getMessage() ).reset() ); + } + renderNewLine( buff ); + } + } + } +} http://git-wip-us.apache.org/repos/asf/maven/blob/427f18c3/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/gossip/GossipConfiguration.java ---------------------------------------------------------------------- diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/gossip/GossipConfiguration.java b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/gossip/GossipConfiguration.java new file mode 100644 index 0000000..3ef50a3 --- /dev/null +++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/gossip/GossipConfiguration.java @@ -0,0 +1,63 @@ +package org.apache.maven.cli.logging.impl.gossip; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import com.planet57.gossip.Gossip; + +import org.apache.maven.cli.logging.BaseSlf4jConfiguration; +import org.slf4j.MavenSlf4jFriend; + +/** + * Configuration for Gossip. + * + * @author <a href="mailto:ja...@planet57.com">Jason Dillon</a> + * @since 3.4.0 + */ +public class GossipConfiguration + extends BaseSlf4jConfiguration +{ + private com.planet57.gossip.Level rootLevel = com.planet57.gossip.Level.INFO; + + @Override + public void setRootLoggerLevel( final Level level ) + { + switch ( level ) + { + case DEBUG: + rootLevel = com.planet57.gossip.Level.DEBUG; + break; + + case INFO: + rootLevel = com.planet57.gossip.Level.INFO; + break; + + default: + rootLevel = com.planet57.gossip.Level.ERROR; + break; + } + } + + @Override + public void activate() + { + MavenSlf4jFriend.reset(); + Gossip.getInstance().getRoot().setLevel( rootLevel ); + } +} http://git-wip-us.apache.org/repos/asf/maven/blob/427f18c3/maven-embedder/src/main/resources/META-INF/com.planet57.gossip/config.properties ---------------------------------------------------------------------- diff --git a/maven-embedder/src/main/resources/META-INF/com.planet57.gossip/config.properties b/maven-embedder/src/main/resources/META-INF/com.planet57.gossip/config.properties new file mode 100644 index 0000000..4050ee6 --- /dev/null +++ b/maven-embedder/src/main/resources/META-INF/com.planet57.gossip/config.properties @@ -0,0 +1,30 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +version=1.0.0 + +profiles=default + +## +## default +## + +profile.default.logger.*=INFO +profile.default.listeners=console +profile.default.listener.console=com.planet57.gossip.listener.ConsoleListener +profile.default.listener.console.renderer=org.apache.maven.cli.logging.impl.gossip.ColorRenderer +profile.default.listener.console.renderer.pattern=[%l] %m%n%x http://git-wip-us.apache.org/repos/asf/maven/blob/427f18c3/maven-embedder/src/main/resources/META-INF/maven/slf4j-configuration.properties ---------------------------------------------------------------------- diff --git a/maven-embedder/src/main/resources/META-INF/maven/slf4j-configuration.properties b/maven-embedder/src/main/resources/META-INF/maven/slf4j-configuration.properties index cd01f9e..e385dcb 100644 --- a/maven-embedder/src/main/resources/META-INF/maven/slf4j-configuration.properties +++ b/maven-embedder/src/main/resources/META-INF/maven/slf4j-configuration.properties @@ -20,3 +20,4 @@ org.slf4j.impl.SimpleLoggerFactory org.apache.maven.cli.logging.impl.Slf4jSimpleConfiguration org.apache.logging.slf4j.Log4jLoggerFactory org.apache.maven.cli.logging.impl.Log4j2Configuration ch.qos.logback.classic.LoggerContext org.apache.maven.cli.logging.impl.LogbackConfiguration +com.planet57.gossip.Gossip org.apache.maven.cli.logging.impl.gossip.GossipConfiguration http://git-wip-us.apache.org/repos/asf/maven/blob/427f18c3/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 11135ee..a9af928 100644 --- a/pom.xml +++ b/pom.xml @@ -148,6 +148,9 @@ under the License. <contributor> <name>Joseph Walton (MNG-5297)</name> </contributor> + <contributor> + <name>Jason Dillon (MNG-6037)</name> + </contributor> </contributors> <!-- This marked as deprecated for Maven 3.X. This is checked by maven-enforcer-plugin --> @@ -294,6 +297,12 @@ under the License. <version>1.1.7</version> <optional>true</optional> </dependency> + <dependency> + <groupId>com.planet57.gossip</groupId> + <artifactId>gossip-slf4j</artifactId> + <version>2.0.0</version> + <optional>true</optional> + </dependency> <!-- Wagon --> <dependency> <groupId>org.apache.maven.wagon</groupId>