mirror of https://github.com/apache/maven.git
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:
parent
d0492b341b
commit
a6726d91e2
|
@ -34,6 +34,7 @@ import org.apache.maven.reporting.MavenReportException;
|
||||||
import org.codehaus.doxia.site.renderer.SiteRenderer;
|
import org.codehaus.doxia.site.renderer.SiteRenderer;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
import org.codehaus.plexus.util.StringOutputStream;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
@ -187,6 +188,10 @@ public class CheckstyleReport
|
||||||
*/
|
*/
|
||||||
private SiteRenderer siteRenderer;
|
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)
|
* @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale)
|
||||||
*/
|
*/
|
||||||
|
@ -243,7 +248,7 @@ public class CheckstyleReport
|
||||||
|
|
||||||
FilterSet filterSet = getSuppressions();
|
FilterSet filterSet = getSuppressions();
|
||||||
|
|
||||||
Checker checker = null;
|
Checker checker;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -276,12 +281,7 @@ public class CheckstyleReport
|
||||||
checker.addListener( listener );
|
checker.addListener( listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( useFile != null )
|
checker.addListener( getConsoleListener() );
|
||||||
{
|
|
||||||
OutputStream out = getOutputStream( useFile );
|
|
||||||
|
|
||||||
checker.addListener( new DefaultLogger( out, true ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
AuditListener sinkListener = new CheckstyleReportListener( getSink(), sourceDirectory, getBundle( locale ) );
|
AuditListener sinkListener = new CheckstyleReportListener( getSink(), sourceDirectory, getBundle( locale ) );
|
||||||
|
|
||||||
|
@ -291,6 +291,11 @@ public class CheckstyleReport
|
||||||
|
|
||||||
checker.destroy();
|
checker.destroy();
|
||||||
|
|
||||||
|
if ( stringOutputStream != null )
|
||||||
|
{
|
||||||
|
getLog().info( stringOutputStream.toString() );
|
||||||
|
}
|
||||||
|
|
||||||
if ( failsOnError && nbErrors > 0 )
|
if ( failsOnError && nbErrors > 0 )
|
||||||
{
|
{
|
||||||
throw new MavenReportException( "There are " + nbErrors + " formatting errors." );
|
throw new MavenReportException( "There are " + nbErrors + " formatting errors." );
|
||||||
|
@ -385,7 +390,7 @@ public class CheckstyleReport
|
||||||
throw new MavenReportException( "Failed to get source files", ioe );
|
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()
|
private Properties getOverridingProperties()
|
||||||
|
@ -427,7 +432,7 @@ public class CheckstyleReport
|
||||||
{
|
{
|
||||||
URL configFile;
|
URL configFile;
|
||||||
|
|
||||||
if ( StringUtils.isEmpty( format ) || ( "sun".equalsIgnoreCase( format.trim() ) ) )
|
if ( StringUtils.isEmpty( format ) || "sun".equalsIgnoreCase( format.trim() ) )
|
||||||
{
|
{
|
||||||
// By default
|
// By default
|
||||||
configFile = getClass().getResource( "/config/sun_checks.xml" );
|
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 )
|
private static ResourceBundle getBundle( Locale locale )
|
||||||
{
|
{
|
||||||
return ResourceBundle.getBundle( "checkstyle-report", locale, CheckstyleReport.class.getClassLoader() );
|
return ResourceBundle.getBundle( "checkstyle-report", locale, CheckstyleReport.class.getClassLoader() );
|
||||||
|
|
Loading…
Reference in New Issue