You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ad...@apache.org on 2018/05/29 18:49:10 UTC

[maven-pmd-plugin] branch master updated (7622ced -> f708bc3)

This is an automated email from the ASF dual-hosted git repository.

adangel pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/maven-pmd-plugin.git.


    from 7622ced  [MPMD-263] - Add documentation information for GitHub
     add 8194869  [MPMD-261] - Upgrade to PMD 6.4.0
     new f708bc3  [MPMD-264] - Add rule priority to HTML report

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            |  2 +-
 .../org/apache/maven/plugins/pmd/PmdReport.java    |  9 ++++++++
 .../maven/plugins/pmd/PmdReportGenerator.java      | 21 +++++++++++++++++
 src/main/resources/pmd-report.properties           |  1 +
 src/main/resources/pmd-report_de.properties        |  1 +
 .../apache/maven/plugins/pmd/PmdReportTest.java    | 27 ++++++++++++++++++++++
 ...ort-not-render-rule-priority-plugin-config.xml} |  2 ++
 7 files changed, 62 insertions(+), 1 deletion(-)
 copy src/test/resources/unit/default-configuration/{default-configuration-plugin-config.xml => pmd-report-not-render-rule-priority-plugin-config.xml} (97%)

-- 
To stop receiving notification emails like this one, please contact
adangel@apache.org.

[maven-pmd-plugin] 01/01: [MPMD-264] - Add rule priority to HTML report

Posted by ad...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

adangel pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-pmd-plugin.git

commit f708bc3c1782489a655850fbcfd20b2ae584fcff
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Tue May 29 19:36:04 2018 +0200

    [MPMD-264] - Add rule priority to HTML report
---
 .../org/apache/maven/plugins/pmd/PmdReport.java    |  9 +++
 .../maven/plugins/pmd/PmdReportGenerator.java      | 21 +++++++
 src/main/resources/pmd-report.properties           |  1 +
 src/main/resources/pmd-report_de.properties        |  1 +
 .../apache/maven/plugins/pmd/PmdReportTest.java    | 27 +++++++++
 ...port-not-render-rule-priority-plugin-config.xml | 68 ++++++++++++++++++++++
 6 files changed, 127 insertions(+)

diff --git a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
index 6bc8d42..caab072 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
@@ -218,6 +218,14 @@ public class PmdReport
     private boolean renderProcessingErrors = true;
 
     /**
+     * Also render the rule priority into the HTML report.
+     *
+     * @since 3.10.0
+     */
+    @Parameter( property = "pmd.renderRuleViolationPriority", defaultValue = "true" )
+    private boolean renderRuleViolationPriority = true;
+
+    /**
      * {@inheritDoc}
      */
     public String getName( Locale locale )
@@ -524,6 +532,7 @@ public class PmdReport
     {
         Sink sink = getSink();
         PmdReportGenerator doxiaRenderer = new PmdReportGenerator( getLog(), sink, getBundle( locale ), aggregate );
+        doxiaRenderer.setRenderRuleViolationPriority( renderRuleViolationPriority );
         doxiaRenderer.setFiles( filesToProcess );
         doxiaRenderer.setViolations( renderer.getViolations() );
         if ( renderProcessingErrors )
diff --git a/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java b/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java
index f13d7c2..7284583 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java
@@ -60,6 +60,8 @@ public class PmdReportGenerator
 
     private boolean aggregate;
 
+    private boolean renderRuleViolationPriority;
+
     // The number of erroneous files
     private int fileCount = 0;
 
@@ -159,6 +161,12 @@ public class PmdReportGenerator
         sink.tableHeaderCell();
         sink.text( bundle.getString( "report.pmd.column.violation" ) );
         sink.tableHeaderCell_();
+        if ( this.renderRuleViolationPriority )
+        {
+            sink.tableHeaderCell();
+            sink.text( bundle.getString( "report.pmd.column.priority" ) );
+            sink.tableHeaderCell_();
+        }
         sink.tableHeaderCell();
         sink.text( bundle.getString( "report.pmd.column.line" ) );
         sink.tableHeaderCell_();
@@ -177,6 +185,14 @@ public class PmdReportGenerator
         sink.tableCell();
         sink.text( ruleViolation.getDescription() );
         sink.tableCell_();
+
+        if ( this.renderRuleViolationPriority )
+        {
+            sink.tableCell();
+            sink.text( String.valueOf( ruleViolation.getRule().getPriority().getPriority() ) );
+            sink.tableCell_();
+        }
+
         sink.tableCell();
 
         int beginLine = ruleViolation.getBeginLine();
@@ -412,4 +428,9 @@ public class PmdReportGenerator
     {
         this.files = files;
     }
+
+    public void setRenderRuleViolationPriority( boolean renderRuleViolationPriority )
+    {
+        this.renderRuleViolationPriority = renderRuleViolationPriority;
+    }
 }
diff --git a/src/main/resources/pmd-report.properties b/src/main/resources/pmd-report.properties
index 031ceef..6b2cd01 100644
--- a/src/main/resources/pmd-report.properties
+++ b/src/main/resources/pmd-report.properties
@@ -19,6 +19,7 @@ report.pmd.name=PMD
 report.pmd.description=Verification of coding rules.
 report.pmd.title=PMD Results
 report.pmd.column.violation=Violation
+report.pmd.column.priority=Priority
 report.pmd.column.line=Line
 report.pmd.pmdlink=The following document contains the results of
 report.pmd.files=Files
diff --git a/src/main/resources/pmd-report_de.properties b/src/main/resources/pmd-report_de.properties
index 36a7cd7..de8ee93 100644
--- a/src/main/resources/pmd-report_de.properties
+++ b/src/main/resources/pmd-report_de.properties
@@ -19,6 +19,7 @@ report.pmd.name=PMD
 report.pmd.description=Verifikation von Code-Richtlinien.
 report.pmd.title=PMD Ergebnisse
 report.pmd.column.violation=Versto\u00df
+report.pmd.column.priority=Priorit\u00e4t
 report.pmd.column.line=Zeile
 report.pmd.pmdlink=Dieses Dokument enth\u00e4lt die Ergebnisse von
 report.pmd.files=Dateien
diff --git a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
index 5fd1356..eb2fa23 100644
--- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
@@ -52,6 +52,7 @@ public class PmdReportTest
         throws Exception
     {
         super.setUp();
+        Locale.setDefault( Locale.ENGLISH );
         FileUtils.deleteDirectory( new File( getBasedir(), "target/test/unit" ) );
     }
 
@@ -86,6 +87,32 @@ public class PmdReportTest
         assertTrue( str.contains( "/xref/def/configuration/App.html#L31" ) );
 
         assertTrue( str.contains( "/xref/def/configuration/AppSample.html#L45" ) );
+
+        // check if there's a priority column
+        assertTrue( str.contains( "Priority" ) );
+    }
+
+    public void testDefaultConfigurationNotRenderRuleViolationPriority()
+            throws Exception
+    {
+        FileUtils.copyDirectoryStructure( new File( getBasedir(),
+                                                    "src/test/resources/unit/default-configuration/jxr-files" ),
+                                          new File( getBasedir(), "target/test/unit/default-configuration/target/site" ) );
+
+        File testPom =
+            new File( getBasedir(),
+                      "src/test/resources/unit/default-configuration/pmd-report-not-render-rule-priority-plugin-config.xml" );
+        PmdReport mojo = (PmdReport) lookupMojo( "pmd", testPom );
+        mojo.execute();
+
+        File generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/site/pmd.html" );
+        renderer( mojo, generatedFile );
+        assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
+
+        String str = readFile( generatedFile );
+
+        // check that there's no priority column
+        assertFalse( str.contains( "Priority" ) );
     }
 
     public void testDefaultConfigurationWithAnalysisCache()
diff --git a/src/test/resources/unit/default-configuration/pmd-report-not-render-rule-priority-plugin-config.xml b/src/test/resources/unit/default-configuration/pmd-report-not-render-rule-priority-plugin-config.xml
new file mode 100644
index 0000000..9afeda3
--- /dev/null
+++ b/src/test/resources/unit/default-configuration/pmd-report-not-render-rule-priority-plugin-config.xml
@@ -0,0 +1,68 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>def.configuration</groupId>
+  <artifactId>default-configuration</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0-SNAPSHOT</version>
+  <inceptionYear>2006</inceptionYear>
+  <name>Maven PMD Plugin Default Configuration Test</name>
+  <url>http://maven.apache.org</url>
+  <build>
+    <finalName>default-configuration</finalName>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-pmd-plugin</artifactId>
+        <configuration>
+          <project implementation="org.apache.maven.plugins.pmd.stubs.DefaultConfigurationMavenProjectStub"/>
+          <outputDirectory>${basedir}/target/test/unit/default-configuration/target/site</outputDirectory>
+          <targetDirectory>${basedir}/target/test/unit/default-configuration/target</targetDirectory>
+          <format>xml</format>
+          <linkXRef>true</linkXRef>
+          <xrefLocation>${basedir}/target/test/unit/default-configuration/target/site/xref</xrefLocation>
+          <sourceEncoding>UTF-8</sourceEncoding>
+          
+          <compileSourceRoots>
+            <compileSourceRoot>${basedir}/src/test/resources/unit/default-configuration/</compileSourceRoot>
+          </compileSourceRoots>
+
+          <renderRuleViolationPriority>false</renderRuleViolationPriority>
+        </configuration>
+        <dependencies>
+          <dependency>
+            <groupId>pmd</groupId>
+            <artifactId>pmd</artifactId>
+            <version>3.6</version>
+          </dependency>
+        </dependencies>
+      </plugin>
+    </plugins>
+  </build>
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jxr-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </reporting>
+</project>

-- 
To stop receiving notification emails like this one, please contact
adangel@apache.org.