You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by fg...@apache.org on 2006/01/22 15:06:59 UTC
svn commit: r371297 - in
/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle:
CheckstyleReport.java CheckstyleReportGenerator.java
Author: fgiust
Date: Sun Jan 22 06:06:55 2006
New Revision: 371297
URL: http://svn.apache.org/viewcvs?rev=371297&view=rev
Log:
MCHECKSTYLE-29 Checkstyle violations should link to Xref if available
Submitted by: Nick Giles
Modified:
maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java
maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportGenerator.java
Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java?rev=371297&r1=371296&r2=371297&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java Sun Jan 22 06:06:55 2006
@@ -83,19 +83,19 @@
* @deprecated Remove with format parameter.
*/
private static final Map FORMAT_TO_CONFIG_LOCATION;
-
+
static
{
Map fmt2Cfg = new HashMap();
-
+
fmt2Cfg.put( "sun", "config/sun_checks.xml" );
fmt2Cfg.put( "turbine", "config/turbine_checks.xml" );
fmt2Cfg.put( "avalon", "config/avalon_checks.xml" );
fmt2Cfg.put( "maven", "config/maven_checks.xml" );
-
+
FORMAT_TO_CONFIG_LOCATION = Collections.unmodifiableMap( fmt2Cfg );
}
-
+
/**
* Specifies the directory where the report will be generated
*
@@ -103,7 +103,7 @@
* @required
*/
private File outputDirectory;
-
+
/**
* Specifies if the Rules summary should be enabled or not.
*
@@ -119,7 +119,7 @@
* default-value="true"
*/
private boolean enableSeveritySummary;
-
+
/**
* Specifies if the Files summary should be enabled or not.
*
@@ -127,7 +127,7 @@
* default-value="true"
*/
private boolean enableFilesSummary;
-
+
/**
* Specifies if the Files summary should be enabled or not.
*
@@ -135,7 +135,7 @@
* default-value="true"
*/
private boolean enableRSS;
-
+
/**
* Specifies the names filter of the source files to be used for checkstyle
*
@@ -185,7 +185,7 @@
* @parameter expression="${checkstyle.config.location}" default-value="config/sun_checks.xml"
*/
private String configLocation;
-
+
/**
* Specifies what predefined check set to use. Available sets are
* "sun" (for the Sun coding conventions), "turbine", and "avalon".
@@ -219,7 +219,7 @@
* @since 2.0-beta-2
*/
private String propertiesLocation;
-
+
/**
* Specifies the location of the checkstyle properties that will be used to check the source.
*
@@ -261,7 +261,7 @@
* @deprecated Use headerLocation instead.
*/
private File headerFile;
-
+
/**
* Specifies the cache file used to speed up Checkstyle on successive runs.
*
@@ -378,12 +378,18 @@
private boolean consoleOutput;
/**
+ * Location of the Xrefs to link to.
+ * @parameter
+ */
+ private String xrefLocation;
+
+ /**
* @component
* @required
* @readonly
*/
private SiteRenderer siteRenderer;
-
+
/**
* Velocity Component
*
@@ -391,10 +397,11 @@
* @required
*/
private VelocityComponent velocityComponent;
-
+
private static final File[] EMPTY_FILE_ARRAY = new File[0];
private StringOutputStream stringOutputStream;
+
private Locator locator;
/**
@@ -444,24 +451,24 @@
throws MavenReportException
{
mergeDeprecatedInfo();
-
+
if ( !canGenerateReport() )
{
getLog().info( "Source directory does not exist - skipping report." );
return;
}
-
-// for when we start using maven-shared-io and maven-shared-monitor...
-// locator = new Locator( new MojoLogMonitorAdaptor( getLog() ) );
-
+
+ // for when we start using maven-shared-io and maven-shared-monitor...
+ // locator = new Locator( new MojoLogMonitorAdaptor( getLog() ) );
+
locator = new Locator( getLog(), new File( project.getBuild().getDirectory() ) );
-
+
String configFile = getConfigFile();
Properties overridingProperties = getOverridingProperties();
ModuleFactory moduleFactory;
Configuration config;
CheckstyleResults results;
-
+
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
try
@@ -491,7 +498,7 @@
// be sure to restore original context classloader
Thread.currentThread().setContextClassLoader( currentClassLoader );
}
-
+
private void generateReportStatics()
throws MavenReportException
{
@@ -509,9 +516,9 @@
private void generateRSS( CheckstyleResults results )
throws MavenReportException
{
- VelocityTemplate vtemplate = new VelocityTemplate(velocityComponent, PLUGIN_RESOURCES);
+ VelocityTemplate vtemplate = new VelocityTemplate( velocityComponent, PLUGIN_RESOURCES );
vtemplate.setLog( getLog() );
-
+
Context context = new VelocityContext();
context.put( "results", results );
context.put( "project", project );
@@ -520,7 +527,7 @@
context.put( "levelWarning", SeverityLevel.WARNING );
context.put( "levelError", SeverityLevel.ERROR );
context.put( "stringutils", new StringUtils() );
-
+
try
{
vtemplate.generate( outputDirectory.getPath() + "/checkstyle.rss", "checkstyle-rss.vm", context );
@@ -564,7 +571,8 @@
return copyright;
}
- private void generateMainReport( CheckstyleResults results, Configuration config, ModuleFactory moduleFactory, ResourceBundle bundle )
+ private void generateMainReport( CheckstyleResults results, Configuration config, ModuleFactory moduleFactory,
+ ResourceBundle bundle )
{
CheckstyleReportGenerator generator = new CheckstyleReportGenerator( getSink(), bundle );
@@ -575,6 +583,7 @@
generator.setEnableRSS( enableRSS );
generator.setCheckstyleConfig( config );
generator.setCheckstyleModuleFactory( moduleFactory );
+ generator.setXrefLocation( xrefLocation );
generator.generateReport( results );
}
@@ -589,7 +598,7 @@
{
configLocation = (String) FORMAT_TO_CONFIG_LOCATION.get( format );
}
-
+
if ( StringUtils.isEmpty( propertiesLocation ) )
{
if ( propertiesFile != null )
@@ -601,7 +610,7 @@
propertiesLocation = propertiesURL.toExternalForm();
}
}
-
+
if ( "LICENSE.txt".equals( headerLocation ) )
{
File defaultHeaderFile = new File( project.getBasedir(), "LICENSE.txt" );
@@ -610,12 +619,12 @@
headerLocation = headerFile.getPath();
}
}
-
+
if ( StringUtils.isEmpty( suppressionsLocation ) )
{
suppressionsLocation = suppressionsFile;
}
-
+
if ( StringUtils.isEmpty( packageNamesLocation ) )
{
packageNamesLocation = packageNamesFile;
@@ -697,7 +706,7 @@
checker.addListener( sinkListener );
int nbErrors = checker.process( files );
-
+
checker.destroy();
if ( stringOutputStream != null )
@@ -749,8 +758,8 @@
else
{
// TODO: failure if not a report
- throw new MavenReportException(
- "Invalid output file format: (" + outputFileFormat + "). Must be 'plain' or 'xml'." );
+ throw new MavenReportException( "Invalid output file format: (" + outputFileFormat
+ + "). Must be 'plain' or 'xml'." );
}
}
@@ -804,7 +813,7 @@
return (File[]) files.toArray( EMPTY_FILE_ARRAY );
}
-
+
private Properties getOverridingProperties()
throws MavenReportException
{
@@ -813,12 +822,12 @@
try
{
File propertiesFile = locator.resolveLocation( propertiesLocation, "checkstyle-checker.properties" );
-
+
if ( propertiesFile != null )
{
p.load( new FileInputStream( propertiesFile ) );
}
-
+
if ( StringUtils.isNotEmpty( propertyExpansion ) )
{
p.load( new StringInputStream( propertyExpansion ) );
@@ -852,7 +861,7 @@
return p;
}
-
+
private String getConfigFile()
throws MavenReportException
{
Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportGenerator.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportGenerator.java?rev=371297&r1=371296&r2=371297&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportGenerator.java (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportGenerator.java Sun Jan 22 06:06:55 2006
@@ -36,37 +36,39 @@
public class CheckstyleReportGenerator
{
private Log log;
-
+
private ResourceBundle bundle;
-
+
private Sink sink;
-
+
private SeverityLevel severityLevel;
-
+
private Configuration checkstyleConfig;
-
+
private ModuleFactory checkstyleModuleFactory;
-
+
private boolean enableRulesSummary;
-
+
private boolean enableSeveritySummary;
-
+
private boolean enableFilesSummary;
-
+
private boolean enableRSS;
-
+
+ private String xrefLocation;
+
public CheckstyleReportGenerator( Sink sink, ResourceBundle bundle )
{
this.bundle = bundle;
-
+
this.sink = sink;
-
+
this.enableRulesSummary = true;
this.enableSeveritySummary = true;
this.enableFilesSummary = true;
this.enableRSS = true;
}
-
+
public Log getLog()
{
if ( this.log == null )
@@ -75,48 +77,51 @@
}
return this.log;
}
-
+
public void setLog( Log log )
{
this.log = log;
}
-
+
private String getTitle()
{
String title;
-
+
if ( getSeverityLevel() == null )
title = bundle.getString( "report.checkstyle.title" );
else
title = bundle.getString( "report.checkstyle.severity_title" ) + severityLevel.getName();
-
+
return title;
}
public void generateReport( CheckstyleResults results )
{
doHeading();
-
- if ( getSeverityLevel() == null )
+
+ if ( getSeverityLevel() == null )
{
- if(enableSeveritySummary) {
+ if ( enableSeveritySummary )
+ {
doSeveritySummary( results );
}
-
- if(enableRulesSummary) {
+
+ if ( enableRulesSummary )
+ {
doRulesSummary( results );
}
-
- if(enableFilesSummary) {
+
+ if ( enableFilesSummary )
+ {
doFilesSummary( results );
}
}
-
+
doDetails( results );
sink.body_();
sink.flush();
}
-
+
private void doHeading()
{
sink.head();
@@ -131,17 +136,17 @@
sink.sectionTitle1();
sink.text( getTitle() );
sink.sectionTitle1_();
-
- doxiaHack();
-
+
+ doxiaHack();
+
sink.paragraph();
sink.text( bundle.getString( "report.checkstyle.checkstylelink" ) + " " );
sink.link( "http://checkstyle.sourceforge.net/" );
sink.text( "Checkstyle" );
sink.link_();
sink.text( "." );
-
- if(enableRSS)
+
+ if ( enableRSS )
{
sink.nonBreakingSpace();
sink.link( "checkstyle.rss" );
@@ -153,11 +158,11 @@
sink.figure_();
sink.link_();
}
-
+
sink.paragraph_();
- doxiaHack();
+ doxiaHack();
}
-
+
private void iconSeverity( String level )
{
if ( SeverityLevel.INFO.getName().equalsIgnoreCase( level ) )
@@ -173,7 +178,7 @@
iconError();
}
}
-
+
private void iconInfo()
{
sink.figure();
@@ -202,21 +207,22 @@
sink.figureCaption_();
sink.figureGraphics( "images/icon_error_sml.gif" );
sink.figure_();
- }
-
- private String getConfigAttribute(Configuration config, String attname, String defvalue) {
+ }
+
+ private String getConfigAttribute( Configuration config, String attname, String defvalue )
+ {
String ret = defvalue;
try
{
- ret = config.getAttribute(attname);
+ ret = config.getAttribute( attname );
}
catch ( CheckstyleException e )
{
- ret = defvalue;
- }
+ ret = defvalue;
+ }
return ret;
}
-
+
private void doRulesSummary( CheckstyleResults results )
{
if ( checkstyleConfig == null )
@@ -228,24 +234,24 @@
sink.sectionTitle1();
sink.text( bundle.getString( "report.checkstyle.rules" ) );
sink.sectionTitle1_();
- doxiaHack();
-
+ doxiaHack();
+
sink.table();
-
+
sink.tableRow();
sink.tableHeaderCell();
sink.text( bundle.getString( "report.checkstyle.rules" ) );
sink.tableHeaderCell_();
-
+
sink.tableHeaderCell();
sink.text( "Violations" );
sink.tableHeaderCell_();
-
+
sink.tableHeaderCell();
sink.text( "Severity" );
sink.tableHeaderCell_();
sink.tableRow_();
-
+
// Top level should be the checker.
if ( "checker".equalsIgnoreCase( checkstyleConfig.getName() ) )
{
@@ -261,11 +267,11 @@
}
sink.table_();
-
+
sink.section1_();
- doxiaHack();
+ doxiaHack();
}
-
+
private void doRuleChildren( Configuration configChildren[], CheckstyleResults results )
{
for ( int cci = 0; cci < configChildren.length; cci++ )
@@ -289,7 +295,7 @@
sink.tableRow();
sink.tableCell();
sink.text( ruleName );
-
+
List attribnames = new ArrayList( Arrays.asList( checkerConfig.getAttributeNames() ) );
attribnames.remove( "severity" ); // special value (deserves unique column)
if ( !attribnames.isEmpty() )
@@ -308,10 +314,10 @@
// special case, Header.header and RegexpHeader.header
if ( "header".equals( name ) && ( "Header".equals( ruleName ) || "RegexpHeader".equals( ruleName ) ) )
{
- List lines = stringSplit(value, "\\n");
+ List lines = stringSplit( value, "\\n" );
int linenum = 1;
Iterator itl = lines.iterator();
- while(itl.hasNext())
+ while ( itl.hasNext() )
{
String line = (String) itl.next();
sink.lineBreak();
@@ -320,11 +326,13 @@
sink.rawText( "</span>" );
sink.nonBreakingSpace();
sink.monospaced();
- sink.text(line);
+ sink.text( line );
sink.monospaced_();
linenum++;
}
- } else {
+ }
+ else
+ {
sink.text( ": " );
sink.monospaced();
sink.text( "\"" );
@@ -333,29 +341,29 @@
sink.monospaced_();
}
sink.listItem_();
- doxiaHack();
+ doxiaHack();
}
sink.list_();
}
-
+
sink.tableCell_();
-
+
sink.tableCell();
String fixedmessage = getConfigAttribute( checkerConfig, "message", null );
sink.text( countRuleViolation( results.getFiles().values().iterator(), ruleName, fixedmessage ) );
sink.tableCell_();
-
+
sink.tableCell();
String configSeverity = getConfigAttribute( checkerConfig, "severity", "error" );
iconSeverity( configSeverity );
sink.nonBreakingSpace();
sink.text( StringUtils.capitalise( configSeverity ) );
sink.tableCell_();
-
+
sink.tableRow_();
- doxiaHack();
+ doxiaHack();
}
-
+
/**
* Splits a string against a delim consisting of a string (not a single character).
*
@@ -385,22 +393,22 @@
return ret;
}
-
+
private String countRuleViolation( Iterator files, String ruleName, String message )
{
long count = 0;
String sourceName;
-
+
try
{
- sourceName = checkstyleModuleFactory.createModule(ruleName).getClass().getName();
+ sourceName = checkstyleModuleFactory.createModule( ruleName ).getClass().getName();
}
catch ( CheckstyleException e )
{
- getLog().error("Unable to obtain Source Name for Rule '" + ruleName + "'.", e);
+ getLog().error( "Unable to obtain Source Name for Rule '" + ruleName + "'.", e );
return "(report failure)";
- }
-
+ }
+
while ( files.hasNext() )
{
List errors = (List) files.next();
@@ -427,45 +435,45 @@
}
}
}
-
+
return String.valueOf( count );
- }
-
+ }
+
private void doSeveritySummary( CheckstyleResults results )
{
sink.section1();
sink.sectionTitle1();
sink.text( bundle.getString( "report.checkstyle.summary" ) );
sink.sectionTitle1_();
-
+
doxiaHack();
-
+
sink.table();
-
+
sink.tableRow();
sink.tableHeaderCell();
sink.text( bundle.getString( "report.checkstyle.files" ) );
sink.tableHeaderCell_();
-
+
sink.tableHeaderCell();
sink.text( "Infos" );
sink.nonBreakingSpace();
iconInfo();
sink.tableHeaderCell_();
-
+
sink.tableHeaderCell();
sink.text( "Warnings" );
sink.nonBreakingSpace();
iconWarning();
sink.tableHeaderCell_();
-
+
sink.tableHeaderCell();
sink.text( "Errors" );
sink.nonBreakingSpace();
iconError();
sink.tableHeaderCell_();
sink.tableRow_();
-
+
sink.tableRow();
sink.tableCell();
sink.text( String.valueOf( results.getFileCount() ) );
@@ -482,20 +490,20 @@
sink.tableRow_();
sink.table_();
-
+
sink.section1_();
- doxiaHack();
+ doxiaHack();
}
-
+
private void doFilesSummary( CheckstyleResults results )
{
sink.section1();
sink.sectionTitle1();
sink.text( bundle.getString( "report.checkstyle.files" ) );
sink.sectionTitle1_();
-
+
sink.table();
-
+
sink.tableRow();
sink.tableHeaderCell();
sink.text( bundle.getString( "report.checkstyle.files" ) );
@@ -516,8 +524,8 @@
iconError();
sink.tableHeaderCell_();
sink.tableRow_();
-
- for( Iterator files = results.getFiles().keySet().iterator(); files.hasNext(); )
+
+ for ( Iterator files = results.getFiles().keySet().iterator(); files.hasNext(); )
{
String filename = (String) files.next();
List violations = results.getFileViolations( filename );
@@ -526,35 +534,35 @@
// skip files without violations
continue;
}
-
+
sink.tableRow();
-
+
sink.tableCell();
sink.link( "#" + filename.replace( '/', '.' ) );
sink.text( filename );
sink.link_();
sink.tableCell_();
-
+
sink.tableCell();
sink.text( String.valueOf( results.getSeverityCount( violations, SeverityLevel.INFO ) ) );
sink.tableCell_();
-
+
sink.tableCell();
sink.text( String.valueOf( results.getSeverityCount( violations, SeverityLevel.WARNING ) ) );
sink.tableCell_();
-
+
sink.tableCell();
sink.text( String.valueOf( results.getSeverityCount( violations, SeverityLevel.ERROR ) ) );
sink.tableCell_();
-
+
sink.tableRow_();
- doxiaHack();
+ doxiaHack();
}
-
+
sink.table_();
sink.section1_();
}
-
+
private void doDetails( CheckstyleResults results )
{
@@ -562,28 +570,28 @@
sink.sectionTitle1();
sink.text( bundle.getString( "report.checkstyle.details" ) );
sink.sectionTitle1_();
-
+
Iterator files = results.getFiles().keySet().iterator();
-
+
while ( files.hasNext() )
{
String file = (String) files.next();
List violations = results.getFileViolations( file );
-
+
if ( violations.isEmpty() )
{
// skip files without violations
continue;
}
-
- doxiaHack();
+
+ doxiaHack();
sink.section2();
sink.sectionTitle2();
sink.anchor( file.replace( '/', '.' ) );
sink.anchor_();
sink.text( file );
sink.sectionTitle2_();
-
+
sink.table();
sink.tableRow();
sink.tableHeaderCell();
@@ -597,30 +605,31 @@
sink.tableHeaderCell_();
sink.tableRow_();
- doFileEvents( violations);
-
+ doFileEvents( violations, file );
+
sink.table_();
sink.section2_();
}
-
+
sink.section1_();
}
-
- private void doFileEvents( List eventList )
+
+ private void doFileEvents( List eventList, String filename )
{
Iterator events = eventList.iterator();
while ( events.hasNext() )
{
AuditEvent event = (AuditEvent) events.next();
SeverityLevel level = event.getSeverityLevel();
-
+
if ( getSeverityLevel() != null )
- if ( !getSeverityLevel().equals( level ) ) continue;
+ if ( !getSeverityLevel().equals( level ) )
+ continue;
sink.tableRow();
-
+
sink.tableCell();
-
+
if ( SeverityLevel.INFO.equals( level ) )
iconInfo();
else if ( SeverityLevel.WARNING.equals( level ) )
@@ -629,26 +638,35 @@
iconError();
sink.tableCell_();
-
+
sink.tableCell();
sink.text( event.getMessage() );
sink.tableCell_();
-
+
sink.tableCell();
+ if ( getXrefLocation() != null )
+ {
+ sink
+ .link( getXrefLocation() + "/" + filename.replaceAll( "\\.java$", ".html" ) + "#" + event.getLine() );
+ }
sink.text( String.valueOf( event.getLine() ) );
+ if ( getXrefLocation() != null )
+ {
+ sink.link_();
+ }
sink.tableCell_();
sink.tableRow_();
- doxiaHack();
+ doxiaHack();
}
}
-
+
public SeverityLevel getSeverityLevel()
{
return severityLevel;
}
- public void setSeverityLevel(SeverityLevel severityLevel)
+ public void setSeverityLevel( SeverityLevel severityLevel )
{
this.severityLevel = severityLevel;
}
@@ -693,6 +711,16 @@
this.enableRSS = enableRSS;
}
+ public String getXrefLocation()
+ {
+ return xrefLocation;
+ }
+
+ public void setXrefLocation( String xrefLocation )
+ {
+ this.xrefLocation = xrefLocation;
+ }
+
public Configuration getCheckstyleConfig()
{
return checkstyleConfig;
@@ -712,7 +740,7 @@
{
this.checkstyleModuleFactory = checkstyleModuleFactory;
}
-
+
/**
* This is here purely as a hack against the large lines the XhtmlSink
* produces.
@@ -725,7 +753,7 @@
*/
private void doxiaHack()
{
- sink.rawText("\n");
+ sink.rawText( "\n" );
sink.flush();
}
}