You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2005/10/09 05:04:16 UTC

svn commit: r307349 - /maven/components/trunk/maven-plugins/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java

Author: brett
Date: Sat Oct  8 20:04:13 2005
New Revision: 307349

URL: http://svn.apache.org/viewcvs?rev=307349&view=rev
Log:
PR: MNG-1111
Submitted by: Edwin Punzalan
Reviewed by:  Brett Porter
honour use file directive (output to a string which is logged).
modifed: original patch used system.out

Modified:
    maven/components/trunk/maven-plugins/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java

Modified: maven/components/trunk/maven-plugins/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java?rev=307349&r1=307348&r2=307349&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java (original)
+++ maven/components/trunk/maven-plugins/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java Sat Oct  8 20:04:13 2005
@@ -34,6 +34,7 @@
 import org.codehaus.doxia.site.renderer.SiteRenderer;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.StringOutputStream;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -187,6 +188,10 @@
      */
     private SiteRenderer siteRenderer;
 
+    private static final File[] EMPTY_FILE_ARRAY = new File[0];
+
+    private StringOutputStream stringOutputStream;
+
     /**
      * @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale)
      */
@@ -243,7 +248,7 @@
 
         FilterSet filterSet = getSuppressions();
 
-        Checker checker = null;
+        Checker checker;
 
         try
         {
@@ -276,12 +281,7 @@
             checker.addListener( listener );
         }
 
-        if ( useFile != null )
-        {
-            OutputStream out = getOutputStream( useFile );
-
-            checker.addListener( new DefaultLogger( out, true ) );
-        }
+        checker.addListener( getConsoleListener() );
 
         AuditListener sinkListener = new CheckstyleReportListener( getSink(), sourceDirectory, getBundle( locale ) );
 
@@ -291,6 +291,11 @@
 
         checker.destroy();
 
+        if ( stringOutputStream != null )
+        {
+            getLog().info( stringOutputStream.toString() );
+        }
+
         if ( failsOnError && nbErrors > 0 )
         {
             throw new MavenReportException( "There are " + nbErrors + " formatting errors." );
@@ -385,7 +390,7 @@
             throw new MavenReportException( "Failed to get source files", ioe );
         }
 
-        return (File[]) ( files.toArray( new File[0] ) );
+        return (File[]) files.toArray( EMPTY_FILE_ARRAY );
     }
 
     private Properties getOverridingProperties()
@@ -427,7 +432,7 @@
     {
         URL configFile;
 
-        if ( StringUtils.isEmpty( format ) || ( "sun".equalsIgnoreCase( format.trim() ) ) )
+        if ( StringUtils.isEmpty( format ) || "sun".equalsIgnoreCase( format.trim() ) )
         {
             // By default
             configFile = getClass().getResource( "/config/sun_checks.xml" );
@@ -482,6 +487,26 @@
         {
             throw new MavenReportException( "failed to load suppressions XML: " + suppressionsFile, ce );
         }
+    }
+
+    private DefaultLogger getConsoleListener()
+        throws MavenReportException
+    {
+        DefaultLogger consoleListener;
+
+        if ( useFile == null )
+        {
+            stringOutputStream = new StringOutputStream();
+            consoleListener = new DefaultLogger( stringOutputStream, false );
+        }
+        else
+        {
+            OutputStream out = getOutputStream( useFile );
+
+            consoleListener = new DefaultLogger( out, true );
+        }
+
+        return consoleListener;
     }
 
     private static ResourceBundle getBundle( Locale locale )