You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2014/11/30 14:03:27 UTC

svn commit: r1642541 - in /maven/plugins/trunk/maven-pmd-plugin/src: main/java/org/apache/maven/plugin/pmd/ test/java/org/apache/maven/plugin/pmd/ test/resources/unit/default-configuration/ test/resources/unit/default-configuration/def/configuration/

Author: michaelo
Date: Sun Nov 30 13:03:26 2014
New Revision: 1642541

URL: http://svn.apache.org/r1642541
Log:
[MPMD-129] Maven PMD plugin does not have suppressMarker property that is available in PMD itself

Contributed-by: Andreas Dangel, Svetlomira Manova

Added:
    maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-with-suppressMarker-plugin-config.xml
Modified:
    maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java
    maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdReportTest.java
    maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/def/configuration/App.java

Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java?rev=1642541&r1=1642540&r2=1642541&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java Sun Nov 30 13:03:26 2014
@@ -149,6 +149,16 @@ public class PmdReport
     private String benchmarkOutputFilename;
 
     /**
+     * Source level marker used to indicate whether a RuleViolation should be suppressed.
+     * If it is not set, PMD's default will be used, which is <code>NOPMD</code>.
+     * See also <a href="http://pmd.sourceforge.net/usage/suppressing.html">PMD - Suppressing warnings</a>.
+     *
+     * @since 3.4
+     */
+    @Parameter( property = "pmd.suppressMarker" )
+    private String suppressMarker;
+
+    /**
      */
     @Component
     private ResourceManager locator;
@@ -562,6 +572,11 @@ public class PmdReport
             }
         }
 
+        if ( null != suppressMarker )
+        {
+            configuration.setSuppressMarker( suppressMarker );
+        }
+
         configuration.setBenchmark( benchmark );
 
         return configuration;

Modified: maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdReportTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdReportTest.java?rev=1642541&r1=1642540&r2=1642541&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdReportTest.java (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdReportTest.java Sun Nov 30 13:03:26 2014
@@ -345,4 +345,28 @@ public class PmdReportTest
 
     }
 
+    /**
+     * Verify that suppressMarker works
+     *
+     * @throws Exception
+     */
+    public void testSuppressMarkerConfiguration()
+            throws Exception
+        {
+            File testPom = new File( getBasedir(),
+                                     "src/test/resources/unit/default-configuration/pmd-with-suppressMarker-plugin-config.xml" );
+            PmdReport mojo = (PmdReport) lookupMojo( "pmd", testPom );
+            mojo.execute();
+
+            //check if the PMD files were generated
+            File generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd.xml" );
+            assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
+
+            String str =
+                readFile( new File( getBasedir(), "target/test/unit/default-configuration/target/pmd.xml" ) );
+
+            //check that there is no violation reported for "unusedVar2" - as it is suppressed
+            assertFalse(str.contains("Avoid unused private fields such as 'unusedVar2'."));
+        }
+
 }

Modified: maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/def/configuration/App.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/def/configuration/App.java?rev=1642541&r1=1642540&r2=1642541&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/def/configuration/App.java (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/def/configuration/App.java Sun Nov 30 13:03:26 2014
@@ -28,7 +28,7 @@ public class App
 {
     protected String unusedVar1;
 
-    private int unusedVar2;
+    private int unusedVar2; //SUPPRESSME test for the suppressMarker property
 
     String unusedvar3;
 

Added: maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-with-suppressMarker-plugin-config.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-with-suppressMarker-plugin-config.xml?rev=1642541&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-with-suppressMarker-plugin-config.xml (added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-with-suppressMarker-plugin-config.xml Sun Nov 30 13:03:26 2014
@@ -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>suppressMarker-configuration</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0-SNAPSHOT</version>
+  <inceptionYear>2006</inceptionYear>
+  <name>Maven PMD Plugin SuppressMarker 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.plugin.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>
+
+          <suppressMarker>SUPPRESSME</suppressMarker>
+
+          <compileSourceRoots>
+            <compileSourceRoot>${basedir}/src/test/resources/unit/default-configuration/</compileSourceRoot>
+          </compileSourceRoots>
+        </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>