maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aherit...@apache.org
Subject [8/50] git commit: [MNG-5390] mvn -rf (no argument) results in NPE
Date Sat, 01 Dec 2012 14:50:02 GMT
[MNG-5390] mvn -rf (no argument) results in NPE

Created a simple primordial logger that implements the error methods required between CLI
parsing and logger initialization. I don't want to have to look to see if the logger is null.


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

Branch: refs/heads/feature/colorized-console/log4j2
Commit: 6c928b0613cd46d74be43e06f6312d7d4d768f43
Parents: 81bf408
Author: Jason van Zyl <jvanzyl@apache.org>
Authored: Fri Nov 30 15:05:12 2012 -0800
Committer: Arnaud HeĢritier <aheritier@exoplatform.com>
Committed: Sat Dec 1 13:51:05 2012 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/maven/cli/MavenCli.java   |    7 +
 .../maven/cli/logging/PrintStreamLogger.java       |  187 ----------
 .../maven/cli/logging/Slf4jStdoutLogger.java       |  284 +++++++++++++++
 3 files changed, 291 insertions(+), 187 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/6c928b06/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 ed6618a..278add0 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
@@ -40,6 +40,7 @@ import org.apache.maven.Maven;
 import org.apache.maven.cli.event.DefaultEventSpyContext;
 import org.apache.maven.cli.event.ExecutionEventLogger;
 import org.apache.maven.cli.logging.Slf4jLoggerManager;
+import org.apache.maven.cli.logging.Slf4jStdoutLogger;
 import org.apache.maven.cli.transfer.ConsoleMavenTransferListener;
 import org.apache.maven.cli.transfer.QuietMavenTransferListener;
 import org.apache.maven.cli.transfer.Slf4jMavenTransferListener;
@@ -262,6 +263,12 @@ public class MavenCli
     private void cli( CliRequest cliRequest )
         throws Exception
     {
+        //
+        // Parsing errors can happen during the processing of the arguments and we prefer
not having to check if the logger is null
+        // and make construct this so we can use an SLF4J logger everywhere
+        //
+        slf4jLogger = new Slf4jStdoutLogger();
+
         CLIManager cliManager = new CLIManager();
 
         try

http://git-wip-us.apache.org/repos/asf/maven/blob/6c928b06/maven-embedder/src/main/java/org/apache/maven/cli/logging/PrintStreamLogger.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/PrintStreamLogger.java
b/maven-embedder/src/main/java/org/apache/maven/cli/logging/PrintStreamLogger.java
deleted file mode 100644
index 53025a0..0000000
--- a/maven-embedder/src/main/java/org/apache/maven/cli/logging/PrintStreamLogger.java
+++ /dev/null
@@ -1,187 +0,0 @@
-package org.apache.maven.cli.logging;
-
-/*
- * 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 org.apache.maven.Maven;
-import org.codehaus.plexus.logging.AbstractLogger;
-import org.codehaus.plexus.logging.Logger;
-
-/**
- * Logs to a user-supplied {@link PrintStream}.
- * 
- * @author Benjamin Bentmann
- */
-public class PrintStreamLogger
-    extends AbstractLogger
-{
-
-    public interface Provider
-    {
-        PrintStream getStream();
-    }
-
-    private Provider provider;
-
-    private static final String FATAL_ERROR = "[FATAL] ";
-
-    private static final String ERROR = "[ERROR] ";
-
-    private static final String WARNING = "[WARNING] ";
-
-    private static final String INFO = "[INFO] ";
-
-    private static final String DEBUG = "[DEBUG] ";
-
-    public PrintStreamLogger( Provider provider )
-    {
-        super( Logger.LEVEL_INFO, Maven.class.getName() );
-
-        if ( provider == null )
-        {
-            throw new IllegalArgumentException( "output stream provider missing" );
-        }
-        this.provider = provider;
-    }
-
-    public PrintStreamLogger( PrintStream out )
-    {
-        super( Logger.LEVEL_INFO, Maven.class.getName() );
-
-        setStream( out );
-    }
-
-    public void setStream( final PrintStream out )
-    {
-        if ( out == null )
-        {
-            throw new IllegalArgumentException( "output stream missing" );
-        }
-
-        this.provider = new Provider()
-        {
-            public PrintStream getStream()
-            {
-                return out;
-            }
-        };
-    }
-
-    public void debug( String message, Throwable throwable )
-    {
-        if ( isDebugEnabled() )
-        {
-            PrintStream out = provider.getStream();
-
-            out.print( DEBUG );
-            out.println( message );
-
-            if ( null != throwable )
-            {
-                throwable.printStackTrace( out );
-            }
-        }
-    }
-
-    public void info( String message, Throwable throwable )
-    {
-        if ( isInfoEnabled() )
-        {
-            PrintStream out = provider.getStream();
-
-            out.print( INFO );
-            out.println( message );
-
-            if ( null != throwable )
-            {
-                throwable.printStackTrace( out );
-            }
-        }
-    }
-
-    public void warn( String message, Throwable throwable )
-    {
-        if ( isWarnEnabled() )
-        {
-            PrintStream out = provider.getStream();
-
-            out.print( WARNING );
-            out.println( message );
-
-            if ( null != throwable )
-            {
-                throwable.printStackTrace( out );
-            }
-        }
-    }
-
-    public void error( String message, Throwable throwable )
-    {
-        if ( isErrorEnabled() )
-        {
-            PrintStream out = provider.getStream();
-
-            out.print( ERROR );
-            out.println( message );
-
-            if ( null != throwable )
-            {
-                throwable.printStackTrace( out );
-            }
-        }
-    }
-
-    public void fatalError( String message, Throwable throwable )
-    {
-        if ( isFatalErrorEnabled() )
-        {
-            PrintStream out = provider.getStream();
-
-            out.print( FATAL_ERROR );
-            out.println( message );
-
-            if ( null != throwable )
-            {
-                throwable.printStackTrace( out );
-            }
-        }
-    }
-
-    public void close()
-    {
-        PrintStream out = provider.getStream();
-
-        if ( out == System.out || out == System.err )
-        {
-            out.flush();
-        }
-        else
-        {
-            out.close();
-        }
-    }
-
-    public Logger getChildLogger( String arg0 )
-    {
-        return this;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/maven/blob/6c928b06/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jStdoutLogger.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jStdoutLogger.java
b/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jStdoutLogger.java
new file mode 100644
index 0000000..f1a27ae
--- /dev/null
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jStdoutLogger.java
@@ -0,0 +1,284 @@
+package org.apache.maven.cli.logging;
+
+import java.io.PrintStream;
+
+import org.slf4j.Logger;
+import org.slf4j.Marker;
+
+public class Slf4jStdoutLogger
+    implements Logger
+{
+    private static final String ERROR = "[ERROR] ";
+
+    private PrintStream out = System.out;
+
+    //
+    // These are the only methods we need in our primordial logger
+    //    
+    public void error( String msg )
+    {
+        out.print( ERROR );
+        out.println( msg );
+    }
+
+    public void error( String msg, Throwable t )
+    {
+        error( msg );
+
+        if ( null != t )
+        {
+            t.printStackTrace( out );
+        }        
+    }    
+
+    //
+    // Don't need any of this
+    //    
+    public String getName()
+    {
+        return null;
+    }
+
+    public boolean isTraceEnabled()
+    {
+        return false;
+    }
+
+    public void trace( String msg )
+    {
+    }
+
+    public void trace( String format, Object arg )
+    {
+    }
+
+    public void trace( String format, Object arg1, Object arg2 )
+    {
+    }
+
+    public void trace( String format, Object... arguments )
+    {
+    }
+
+    public void trace( String msg, Throwable t )
+    {
+    }
+
+    public boolean isTraceEnabled( Marker marker )
+    {
+        return false;
+    }
+
+    public void trace( Marker marker, String msg )
+    {
+    }
+
+    public void trace( Marker marker, String format, Object arg )
+    {
+    }
+
+    public void trace( Marker marker, String format, Object arg1, Object arg2 )
+    {
+    }
+
+    public void trace( Marker marker, String format, Object... argArray )
+    {
+    }
+
+    public void trace( Marker marker, String msg, Throwable t )
+    {
+    }
+
+    public boolean isDebugEnabled()
+    {
+        return false;
+    }
+
+    public void debug( String msg )
+    {
+    }
+
+    public void debug( String format, Object arg )
+    {
+    }
+
+    public void debug( String format, Object arg1, Object arg2 )
+    {
+    }
+
+    public void debug( String format, Object... arguments )
+    {
+    }
+
+    public void debug( String msg, Throwable t )
+    {
+    }
+
+    public boolean isDebugEnabled( Marker marker )
+    {
+        return false;
+    }
+
+    public void debug( Marker marker, String msg )
+    {
+    }
+
+    public void debug( Marker marker, String format, Object arg )
+    {
+    }
+
+    public void debug( Marker marker, String format, Object arg1, Object arg2 )
+    {
+    }
+
+    public void debug( Marker marker, String format, Object... arguments )
+    {
+    }
+
+    public void debug( Marker marker, String msg, Throwable t )
+    {
+    }
+
+    public boolean isInfoEnabled()
+    {
+        return false;
+    }
+
+    public void info( String msg )
+    {
+    }
+
+    public void info( String format, Object arg )
+    {
+    }
+
+    public void info( String format, Object arg1, Object arg2 )
+    {
+    }
+
+    public void info( String format, Object... arguments )
+    {
+    }
+
+    public void info( String msg, Throwable t )
+    {
+    }
+
+    public boolean isInfoEnabled( Marker marker )
+    {
+        return false;
+    }
+
+    public void info( Marker marker, String msg )
+    {
+    }
+
+    public void info( Marker marker, String format, Object arg )
+    {
+    }
+
+    public void info( Marker marker, String format, Object arg1, Object arg2 )
+    {
+    }
+
+    public void info( Marker marker, String format, Object... arguments )
+    {
+    }
+
+    public void info( Marker marker, String msg, Throwable t )
+    {
+    }
+
+    public boolean isWarnEnabled()
+    {
+        return false;
+    }
+
+    public void warn( String msg )
+    {
+    }
+
+    public void warn( String format, Object arg )
+    {
+    }
+
+    public void warn( String format, Object... arguments )
+    {
+    }
+
+    public void warn( String format, Object arg1, Object arg2 )
+    {
+    }
+
+    public void warn( String msg, Throwable t )
+    {
+    }
+
+    public boolean isWarnEnabled( Marker marker )
+    {
+        return false;
+    }
+
+    public void warn( Marker marker, String msg )
+    {
+    }
+
+    public void warn( Marker marker, String format, Object arg )
+    {
+    }
+
+    public void warn( Marker marker, String format, Object arg1, Object arg2 )
+    {
+    }
+
+    public void warn( Marker marker, String format, Object... arguments )
+    {
+    }
+
+    public void warn( Marker marker, String msg, Throwable t )
+    {
+    }
+
+    public boolean isErrorEnabled()
+    {
+        return false;
+    }
+
+    public void error( String format, Object arg )
+    {
+    }
+
+    public void error( String format, Object arg1, Object arg2 )
+    {
+    }
+
+    public void error( String format, Object... arguments )
+    {
+    }
+
+    public boolean isErrorEnabled( Marker marker )
+    {
+        return false;
+    }
+
+    public void error( Marker marker, String msg )
+    {
+    }
+
+    public void error( Marker marker, String format, Object arg )
+    {
+    }
+
+    public void error( Marker marker, String format, Object arg1, Object arg2 )
+    {
+    }
+
+    public void error( Marker marker, String format, Object... arguments )
+    {
+    }
+
+    public void error( Marker marker, String msg, Throwable t )
+    {
+    }
+
+}


Mime
View raw message