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


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@307349 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-09 03:04:13 +00:00
parent d0492b341b
commit a6726d91e2
1 changed files with 34 additions and 9 deletions

View File

@ -34,6 +34,7 @@ import org.apache.maven.reporting.MavenReportException;
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 @@ public class CheckstyleReport
*/
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 @@ public class CheckstyleReport
FilterSet filterSet = getSuppressions();
Checker checker = null;
Checker checker;
try
{
@ -276,12 +281,7 @@ public class CheckstyleReport
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 @@ public class CheckstyleReport
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 @@ public class CheckstyleReport
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 @@ public class CheckstyleReport
{
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" );
@ -484,6 +489,26 @@ public class CheckstyleReport
}
}
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 )
{
return ResourceBundle.getBundle( "checkstyle-report", locale, CheckstyleReport.class.getClassLoader() );