You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2014/07/13 13:51:43 UTC

svn commit: r1610171 - in /maven/plugins/trunk/maven-checkstyle-plugin/src/main: java/org/apache/maven/plugin/checkstyle/CheckstyleReportGenerator.java resources/checkstyle-report.properties resources/checkstyle-report_fr.properties

Author: hboutemy
Date: Sun Jul 13 11:51:43 2014
New Revision: 1610171

URL: http://svn.apache.org/r1610171
Log:
[MCHECKSTYLE-233] added link to rules documentation

Modified:
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportGenerator.java
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/checkstyle-report.properties
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/checkstyle-report_fr.properties

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportGenerator.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportGenerator.java?rev=1610171&r1=1610170&r2=1610171&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 Jul 13 11:51:43 2014
@@ -258,7 +258,7 @@ public class CheckstyleReportGenerator
 
         sink.tableRow();
         sink.tableHeaderCell();
-        sink.text( bundle.getString( "report.checkstyle.column.severity" ) );
+        sink.text( bundle.getString( "report.checkstyle.rule.category" ) );
         sink.tableHeaderCell_();
 
         sink.tableHeaderCell();
@@ -269,6 +269,10 @@ public class CheckstyleReportGenerator
         sink.text( bundle.getString( "report.checkstyle.violations" ) );
         sink.tableHeaderCell_();
 
+        sink.tableHeaderCell();
+        sink.text( bundle.getString( "report.checkstyle.column.severity" ) );
+        sink.tableHeaderCell_();
+
         sink.tableRow_();
 
         // Top level should be the checker.
@@ -367,17 +371,24 @@ public class CheckstyleReportGenerator
 
         sink.tableRow();
 
-        // column 1: severity
+        // column 1: rule category
         sink.tableCell();
-        // Grab the severity from the rule configuration, this time use error as default value
-        // Also pass along all parent configurations, so that we can try to find the severity there
-        String severity = getConfigAttribute( checkerConfig, parentConfigurations, "severity", "error" );
-        iconTool.iconSeverity( severity, IconTool.TEXT_SIMPLE );
+        String category = getRuleCategoryName( lastMatchedEvent );
+        sink.text( category );
         sink.tableCell_();
 
         // column 2: Rule name + configured attributes
         sink.tableCell();
-        sink.text( ruleName );
+        if ( !"extension".equals( category ) )
+        {
+            sink.link( "http://checkstyle.sourceforge.net/config_" + category + ".html#" + ruleName );
+            sink.text( ruleName );
+            sink.link_();
+        }
+        else
+        {
+            sink.text( ruleName );
+        }
 
         List<String> attribnames = new ArrayList<String>( Arrays.asList( checkerConfig.getAttributeNames() ) );
         attribnames.remove( "severity" ); // special value (deserves unique column)
@@ -450,6 +461,14 @@ public class CheckstyleReportGenerator
         sink.text( String.valueOf( violations ) );
         sink.tableCell_();
 
+        // column 4: severity
+        sink.tableCell();
+        // Grab the severity from the rule configuration, this time use error as default value
+        // Also pass along all parent configurations, so that we can try to find the severity there
+        String severity = getConfigAttribute( checkerConfig, parentConfigurations, "severity", "error" );
+        iconTool.iconSeverity( severity, IconTool.TEXT_SIMPLE );
+        sink.tableCell_();
+
         sink.tableRow_();
     }
 
@@ -477,6 +496,36 @@ public class CheckstyleReportGenerator
     }
 
     /**
+     * Get the rule category from a violation.
+     *
+     * @param event the violation
+     * @return the rule category, which is the last package name or "misc" or "extension"
+     */
+    public String getRuleCategoryName( AuditEvent event )
+    {
+        String eventSrcName = event.getSourceName();
+
+        if ( eventSrcName == null )
+        {
+            return null;
+        }
+
+        int end = eventSrcName.lastIndexOf( '.' );
+        eventSrcName = eventSrcName.substring( 0,  end );
+
+        if ( "com.puppycrawl.tools.checkstyle.checks".equals( eventSrcName ) )
+        {
+            return "misc";
+        }
+        else if ( eventSrcName.startsWith( "com.puppycrawl.tools.checkstyle.checks" ) )
+        {
+            return "extension";
+        }
+
+        return eventSrcName.substring( eventSrcName.lastIndexOf( '.' ) + 1 );
+    }
+
+    /**
      * Check if a violation matches a rule.
      *
      * @param event the violation to check
@@ -515,6 +564,7 @@ public class CheckstyleReportGenerator
         return true;
     }
 
+    private AuditEvent lastMatchedEvent = null; // TODO better implementation...
     /**
      * Count the number of violations for the given rule.
      *
@@ -528,6 +578,7 @@ public class CheckstyleReportGenerator
                                     String expectedSeverity )
     {
         long count = 0;
+        lastMatchedEvent = null;
 
         for ( List<AuditEvent> errors : files )
         {
@@ -535,6 +586,7 @@ public class CheckstyleReportGenerator
             {
                 if ( matchRule( event, ruleName, expectedMessage, expectedSeverity ) )
                 {
+                    lastMatchedEvent = event;
                     count++;
                 }
             }
@@ -689,6 +741,9 @@ public class CheckstyleReportGenerator
             sink.text( bundle.getString( "report.checkstyle.column.severity" ) );
             sink.tableHeaderCell_();
             sink.tableHeaderCell();
+            sink.text( bundle.getString( "report.checkstyle.rule.category" ) );
+            sink.tableHeaderCell_();
+            sink.tableHeaderCell();
             sink.text( bundle.getString( "report.checkstyle.rule" ) );
             sink.tableHeaderCell_();
             sink.tableHeaderCell();
@@ -726,6 +781,14 @@ public class CheckstyleReportGenerator
             sink.tableCell_();
 
             sink.tableCell();
+            String category = getRuleCategoryName( event );
+            if ( category != null )
+            {
+                sink.text( category );
+            }
+            sink.tableCell_();
+
+            sink.tableCell();
             String ruleName = getRuleName( event );
             if ( ruleName != null )
             {

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/checkstyle-report.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/checkstyle-report.properties?rev=1610171&r1=1610170&r2=1610171&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/checkstyle-report.properties [ISO-8859-1] (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/checkstyle-report.properties [ISO-8859-1] Sun Jul 13 11:51:43 2014
@@ -39,5 +39,6 @@ report.checkstyle.details=Details
 report.checkstyle.summary=Summary
 report.checkstyle.rule=Rule
 report.checkstyle.rules=Rules
+report.checkstyle.rule.category=Category
 report.checkstyle.severity_title=Checkstyle errors in severity
 report.checkstyle.norule=No rules found

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/checkstyle-report_fr.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/checkstyle-report_fr.properties?rev=1610171&r1=1610170&r2=1610171&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/checkstyle-report_fr.properties [ISO-8859-1] (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/checkstyle-report_fr.properties [ISO-8859-1] Sun Jul 13 11:51:43 2014
@@ -39,5 +39,6 @@ report.checkstyle.details=Détails
 report.checkstyle.summary=Résumé
 report.checkstyle.rule=Règle
 report.checkstyle.rules=Règles
+report.checkstyle.rule.category=Catégorie
 report.checkstyle.severity_title=Erreurs Checkstyle par sévérité
 report.checkstyle.norule=Pas de règle trouvée