You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2016/10/19 12:12:58 UTC
maven git commit: MNG-6093 switched to monkey patched slf4j-simple
provider supporting Maven color styles (reverts MNG-6038)
Repository: maven
Updated Branches:
refs/heads/master 904f7975c -> 5bd5a6df8
MNG-6093 switched to monkey patched slf4j-simple provider supporting
Maven color styles (reverts MNG-6038)
Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/5bd5a6df
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/5bd5a6df
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/5bd5a6df
Branch: refs/heads/master
Commit: 5bd5a6df8d2664e9c13941a85e0bccd58958f7ce
Parents: 904f797
Author: Herv� Boutemy <hb...@apache.org>
Authored: Thu Sep 22 17:46:53 2016 +0200
Committer: Herv� Boutemy <hb...@apache.org>
Committed: Wed Oct 19 14:10:13 2016 +0200
----------------------------------------------------------------------
apache-maven/pom.xml | 4 +-
.../maven/slf4j-configuration.properties | 1 +
maven-slf4j-provider/pom.xml | 116 ++++++++++++++++++
.../java/org/slf4j/impl/MavenSimpleLogger.java | 117 +++++++++++++++++++
.../slf4j/impl/MavenSimpleLoggerFactory.java | 44 +++++++
.../src/main/script/patch-slf4j-simple.groovy | 53 +++++++++
maven-slf4j-provider/src/site/site.xml | 36 ++++++
pom.xml | 6 +
src/site/xdoc/index.xml | 1 +
9 files changed, 376 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven/blob/5bd5a6df/apache-maven/pom.xml
----------------------------------------------------------------------
diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml
index ec11cc2..437fc43 100644
--- a/apache-maven/pom.xml
+++ b/apache-maven/pom.xml
@@ -92,8 +92,8 @@ under the License.
<artifactId>aether-transport-wagon</artifactId>
</dependency>
<dependency>
- <groupId>com.planet57.gossip</groupId>
- <artifactId>gossip-slf4j</artifactId>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-slf4j-provider</artifactId>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
http://git-wip-us.apache.org/repos/asf/maven/blob/5bd5a6df/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 e385dcb..42b39c0 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
@@ -18,6 +18,7 @@
# key = Slf4j effective logger factory implementation
# value = corresponding o.a.m.cli.logging.Slf4jConfiguration class
org.slf4j.impl.SimpleLoggerFactory org.apache.maven.cli.logging.impl.Slf4jSimpleConfiguration
+org.slf4j.impl.MavenSimpleLoggerFactory 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/5bd5a6df/maven-slf4j-provider/pom.xml
----------------------------------------------------------------------
diff --git a/maven-slf4j-provider/pom.xml b/maven-slf4j-provider/pom.xml
new file mode 100644
index 0000000..ecb93e8
--- /dev/null
+++ b/maven-slf4j-provider/pom.xml
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven</artifactId>
+ <version>3.4.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>maven-slf4j-provider</artifactId>
+
+ <name>Maven SLF4J Simple Provider</name>
+ <description>
+ Maven SLF4J provider based on SLF4J's simple provider, monkey-patched to support Maven styled colors
+ for levels and stacktraces rendering.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-shared-utils</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>${slf4jVersion}</version>
+ <type>jar</type>
+ <classifier>sources</classifier>
+ <overWrite>false</overWrite>
+ <outputDirectory>${project.build.directory}/generated-sources/slf4j-simple</outputDirectory>
+ <includes>org/slf4j/impl/*.java</includes>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ <executions>
+ <execution>
+ <id>unzip-slf4j-simple</id>
+ <goals>
+ <goal>unpack</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.12</version>
+ <executions>
+ <execution>
+ <id>add-slf4j-simple</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${project.build.directory}/generated-sources/slf4j-simple</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.gmaven</groupId>
+ <artifactId>groovy-maven-plugin</artifactId>
+ <version>2.0</version>
+ <executions>
+ <execution>
+ <id>patch-slf4j-simple</id>
+ <phase>process-sources</phase>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ <configuration>
+ <source>${project.basedir}/src/main/script/patch-slf4j-simple.groovy</source>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/maven/blob/5bd5a6df/maven-slf4j-provider/src/main/java/org/slf4j/impl/MavenSimpleLogger.java
----------------------------------------------------------------------
diff --git a/maven-slf4j-provider/src/main/java/org/slf4j/impl/MavenSimpleLogger.java b/maven-slf4j-provider/src/main/java/org/slf4j/impl/MavenSimpleLogger.java
new file mode 100644
index 0000000..0715ed0
--- /dev/null
+++ b/maven-slf4j-provider/src/main/java/org/slf4j/impl/MavenSimpleLogger.java
@@ -0,0 +1,117 @@
+package org.slf4j.impl;
+
+/*
+ * 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.apache.maven.shared.utils.logging.MessageUtils.buffer;
+
+import java.io.PrintStream;
+
+/**
+ * Logger for Maven, that support colorization of levels and stacktraces.
+ * This class implements 2 methods introduced in slf4j-simple provider local copy.
+ * @since 3.4.0
+ */
+public class MavenSimpleLogger
+ extends SimpleLogger
+{
+ private static final String NEWLINE = System.getProperty( "line.separator" );
+
+ MavenSimpleLogger( String name )
+ {
+ super( name );
+ }
+
+ @Override
+ protected String renderLevel( int level )
+ {
+ switch ( level )
+ {
+ case LOG_LEVEL_TRACE:
+ return buffer().debug( "TRACE" ).toString();
+ case LOG_LEVEL_DEBUG:
+ return buffer().debug( "DEBUG" ).toString();
+ case LOG_LEVEL_INFO:
+ return buffer().info( "INFO" ).toString();
+ case LOG_LEVEL_WARN:
+ return buffer().warning( "WARNING" ).toString();
+ case LOG_LEVEL_ERROR:
+ default:
+ return buffer().error( "ERROR" ).toString();
+ }
+ }
+
+ @Override
+ protected void renderThrowable( Throwable t, PrintStream stream )
+ {
+ stream.append( buffer().failure( t.getClass().getName() ).toString() );
+ if ( t.getMessage() != null )
+ {
+ stream.append( ": " );
+ stream.append( buffer().failure( t.getMessage() ).toString() );
+ }
+ stream.append( NEWLINE );
+
+ while ( t != null )
+ {
+ for ( StackTraceElement e : t.getStackTrace() )
+ {
+ stream.append( " " );
+ stream.append( buffer().strong( "at" ).toString() );
+ stream.append( " " + e.getClassName() + "." + e.getMethodName() );
+ stream.append( buffer().a( " (" ).strong( getLocation( e ) ).a( ")" ).toString() );
+ stream.append( NEWLINE );
+ }
+
+ t = t.getCause();
+ if ( t != null )
+ {
+ stream.append( buffer().strong( "Caused by" ).a( ": " ).a( t.getClass().getName() ).toString() );
+ if ( t.getMessage() != null )
+ {
+ stream.append( ": " );
+ stream.append( buffer().failure( t.getMessage() ).toString() );
+ }
+ stream.append( NEWLINE );
+ }
+ }
+ }
+
+ protected String getLocation( final StackTraceElement e )
+ {
+ assert e != null;
+
+ if ( e.isNativeMethod() )
+ {
+ return "Native Method";
+ }
+ else if ( e.getFileName() == null )
+ {
+ return "Unknown Source";
+ }
+ else if ( e.getLineNumber() >= 0 )
+ {
+ return String.format( "%s:%s", e.getFileName(), e.getLineNumber() );
+ }
+ else
+ {
+ return e.getFileName();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven/blob/5bd5a6df/maven-slf4j-provider/src/main/java/org/slf4j/impl/MavenSimpleLoggerFactory.java
----------------------------------------------------------------------
diff --git a/maven-slf4j-provider/src/main/java/org/slf4j/impl/MavenSimpleLoggerFactory.java b/maven-slf4j-provider/src/main/java/org/slf4j/impl/MavenSimpleLoggerFactory.java
new file mode 100644
index 0000000..d56e346
--- /dev/null
+++ b/maven-slf4j-provider/src/main/java/org/slf4j/impl/MavenSimpleLoggerFactory.java
@@ -0,0 +1,44 @@
+package org.slf4j.impl;
+
+/*
+ * 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 org.slf4j.Logger;
+
+public class MavenSimpleLoggerFactory
+ extends SimpleLoggerFactory
+{
+ /**
+ * Return an appropriate {@link MavenSimpleLogger} instance by name.
+ */
+ public Logger getLogger( String name )
+ {
+ Logger simpleLogger = loggerMap.get( name );
+ if ( simpleLogger != null )
+ {
+ return simpleLogger;
+ }
+ else
+ {
+ Logger newInstance = new MavenSimpleLogger( name );
+ Logger oldInstance = loggerMap.putIfAbsent( name, newInstance );
+ return oldInstance == null ? newInstance : oldInstance;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven/blob/5bd5a6df/maven-slf4j-provider/src/main/script/patch-slf4j-simple.groovy
----------------------------------------------------------------------
diff --git a/maven-slf4j-provider/src/main/script/patch-slf4j-simple.groovy b/maven-slf4j-provider/src/main/script/patch-slf4j-simple.groovy
new file mode 100644
index 0000000..bba8646
--- /dev/null
+++ b/maven-slf4j-provider/src/main/script/patch-slf4j-simple.groovy
@@ -0,0 +1,53 @@
+
+/*
+ * 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.
+ */
+
+dir = new File( basedir, 'target/generated-sources/slf4j-simple/org/slf4j/impl' );
+
+file = new File( dir, 'StaticLoggerBinder.java' );
+content = file.text;
+
+// check if already patched
+if ( content.contains( 'MavenSimpleLoggerFactory' ) )
+{
+ println ' slf4j-simple already patched';
+ return;
+}
+
+
+println ' patching StaticLoggerBinder.java';
+content = content.replaceAll( 'SimpleLoggerFactory', 'MavenSimpleLoggerFactory' );
+file.write( content );
+
+
+println ' patching SimpleLogger.java';
+file = new File( dir, 'SimpleLogger.java' );
+content = file.text;
+content = content.replaceAll( 'private static final int LOG_LEVEL_', 'protected static final int LOG_LEVEL_' );
+content = content.replaceAll( 't.printStackTrace(TARGET_STREAM)', 'renderThrowable(t, TARGET_STREAM);' );
+
+index = content.indexOf( 'switch (level) {' );
+end = content.indexOf( '}', index ) + 1;
+content = content.substring( 0, index ) + 'buf.append(renderLevel(level));' + content.substring( end );
+
+content = content.substring( 0, content.lastIndexOf( '}' ) );
+content += ' protected void renderThrowable(Throwable t, PrintStream stream) {}\n';
+content += ' protected String renderLevel(int level) { return ""; }\n}\n';
+
+file.write( content );
http://git-wip-us.apache.org/repos/asf/maven/blob/5bd5a6df/maven-slf4j-provider/src/site/site.xml
----------------------------------------------------------------------
diff --git a/maven-slf4j-provider/src/site/site.xml b/maven-slf4j-provider/src/site/site.xml
new file mode 100644
index 0000000..3a16bf9
--- /dev/null
+++ b/maven-slf4j-provider/src/site/site.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/DECORATION/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd">
+ <body>
+ <menu name="Overview">
+ <item name="Introduction" href="index.html"/>
+ <item name="JavaDocs" href="apidocs/index.html"/>
+ <item name="Source Xref" href="xref/index.html"/>
+ <!--item name="FAQ" href="faq.html"/-->
+ </menu>
+
+ <menu ref="parent"/>
+ <menu ref="reports"/>
+ </body>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/maven/blob/5bd5a6df/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 861b915..ec82598 100644
--- a/pom.xml
+++ b/pom.xml
@@ -91,6 +91,7 @@ under the License.
<module>maven-artifact</module>
<module>maven-aether-provider</module>
<module>maven-repository-metadata</module>
+ <module>maven-slf4j-provider</module>
<module>maven-embedder</module>
<module>maven-compat</module>
<module>apache-maven</module>
@@ -227,6 +228,11 @@ under the License.
<artifactId>maven-builder-support</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-slf4j-provider</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<!--bootstrap-end-comment-->
<!-- Plexus -->
<dependency>
http://git-wip-us.apache.org/repos/asf/maven/blob/5bd5a6df/src/site/xdoc/index.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml
index 61b105d..eda684f 100644
--- a/src/site/xdoc/index.xml
+++ b/src/site/xdoc/index.xml
@@ -55,6 +55,7 @@
<area shape="rect" coords="449,229,532,266" alt="maven-settings" href="maven-settings/" />
<area shape="rect" coords="388,284,521,319" alt="maven-model-builder" href="maven-model-builder/" />
<area shape="rect" coords="409,342,500,378" alt="maven-model" href="maven-model/" />
+ <area shape="rect" coords="TODO" alt="maven-slf4j-provider" href="maven-slf4j-provider/" />
<area shape="rect" coords="88,59,192,94" alt="slf4j-api" href="http://www.slf4j.org/manual.html" />
<area shape="rect" coords="551,58,707,94" alt="commons-cli" href="http://commons.apache.org/cli/" />
<area shape="rect" coords="88,175,205,211" alt="maven-shared-utils" href="https://maven.apache.org/shared/maven-shared-utils/" />