You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2013/01/29 12:11:57 UTC

svn commit: r1439834 - in /maven/plugins/trunk/maven-pmd-plugin: ./ src/it/mpmd-89/ src/it/mpmd-89/src/ src/it/mpmd-89/src/main/ src/it/mpmd-89/src/main/pmd/ src/it/mpmd-89/src/test/ src/it/mpmd-89/src/test/java/ src/it/mpmd-89/src/test/java/it/ src/ma...

Author: bentmann
Date: Tue Jan 29 11:11:55 2013
New Revision: 1439834

URL: http://svn.apache.org/viewvc?rev=1439834&view=rev
Log:
[MPMD-89] Having an equivalent for auxclasspath option

Added:
    maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/invoker.properties   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/pom.xml   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/main/   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/main/pmd/   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/main/pmd/ruleset.xml   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/NoTestsHere.java   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/TestSupport.java   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/verify.bsh   (with props)
Modified:
    maven/plugins/trunk/maven-pmd-plugin/pom.xml
    maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java

Modified: maven/plugins/trunk/maven-pmd-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/pom.xml?rev=1439834&r1=1439833&r2=1439834&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-pmd-plugin/pom.xml Tue Jan 29 11:11:55 2013
@@ -82,6 +82,11 @@ under the License.
     <!-- maven -->
     <dependency>
       <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>${mavenVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
       <artifactId>maven-model</artifactId>
       <version>${mavenVersion}</version>
     </dependency>
@@ -174,12 +179,6 @@ under the License.
       <version>1.2</version>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.apache.maven</groupId>
-      <artifactId>maven-artifact</artifactId>
-      <version>${mavenVersion}</version>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
 
   <build>

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/
------------------------------------------------------------------------------
    bugtraq:number = true

Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/invoker.properties?rev=1439834&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/invoker.properties (added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/invoker.properties Tue Jan 29 11:11:55 2013
@@ -0,0 +1,2 @@
+invoker.goals = clean test-compile
+invoker.buildResult = failure

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/invoker.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/invoker.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/pom.xml?rev=1439834&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/pom.xml (added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/pom.xml Tue Jan 29 11:11:55 2013
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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>org.apache.maven.plugin.pmd.it</groupId>
+  <artifactId>mpmd-89</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.2</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <!-- to check proper aux classpath, we need to require something that the maven-pmd-plugin doesn't already drag in -->
+      <groupId>xmlunit</groupId>
+      <artifactId>xmlunit</artifactId>
+      <version>1.3</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>@project.groupId@</groupId>
+        <artifactId>@project.artifactId@</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <includeTests>true</includeTests>
+          <typeResolution>true</typeResolution>
+          <rulesets>
+            <ruleset>src/main/pmd/ruleset.xml</ruleset>
+          </rulesets>
+        </configuration>
+        <executions>
+          <execution>
+            <phase>test-compile</phase>
+            <goals>
+              <goal>check</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/
------------------------------------------------------------------------------
    bugtraq:number = true

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/main/
------------------------------------------------------------------------------
    bugtraq:number = true

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/main/pmd/
------------------------------------------------------------------------------
    bugtraq:number = true

Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/main/pmd/ruleset.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/main/pmd/ruleset.xml?rev=1439834&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/main/pmd/ruleset.xml (added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/main/pmd/ruleset.xml Tue Jan 29 11:11:55 2013
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<ruleset name="Custom ruleset"
+    xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
+  <rule ref="rulesets/java/junit.xml/TestClassWithoutTestCases"/>
+</ruleset>

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/main/pmd/ruleset.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/main/pmd/ruleset.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/
------------------------------------------------------------------------------
    bugtraq:number = true

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/
------------------------------------------------------------------------------
    bugtraq:number = true

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/
------------------------------------------------------------------------------
    bugtraq:number = true

Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/NoTestsHere.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/NoTestsHere.java?rev=1439834&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/NoTestsHere.java (added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/NoTestsHere.java Tue Jan 29 11:11:55 2013
@@ -0,0 +1,32 @@
+package it;
+
+/*
+ * 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.
+ */
+
+/**
+ * This class violates http://pmd.sourceforge.net/pmd-5.0.1/rules/java/junit.html#TestClassWithoutTestCases but for PMD
+ * to actually detect this, it needs to do type resolution which in turn requires use of the proper aux classpath for
+ * PMD.
+ */
+// does not directly extend *TestCase to enforce need for type resolution, otherwise PMD uses name-based heuristics
+public class NoTestsHere
+    extends TestSupport
+{
+
+}

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/NoTestsHere.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/NoTestsHere.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/TestSupport.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/TestSupport.java?rev=1439834&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/TestSupport.java (added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/TestSupport.java Tue Jan 29 11:11:55 2013
@@ -0,0 +1,28 @@
+package it;
+
+/*
+ * 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.
+ */
+
+import org.custommonkey.xmlunit.XMLTestCase;
+
+public abstract class TestSupport
+    extends XMLTestCase
+{
+
+}

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/TestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/src/test/java/it/TestSupport.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/verify.bsh?rev=1439834&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/verify.bsh (added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/verify.bsh Tue Jan 29 11:11:55 2013
@@ -0,0 +1,5 @@
+File pmdXml = new File( basedir, "target/pmd.xml" );
+if (!pmdXml.isFile())
+{
+    throw new IllegalStateException( pmdXml + " does not exist" );
+}

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/verify.bsh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/mpmd-89/verify.bsh
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

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=1439834&r1=1439833&r2=1439834&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 Tue Jan 29 11:11:55 2013
@@ -39,6 +39,7 @@ import org.apache.maven.doxia.sink.Sink;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
 import org.apache.maven.reporting.MavenReportException;
 import org.codehaus.plexus.resource.ResourceManager;
 import org.codehaus.plexus.resource.loader.FileResourceCreationException;
@@ -69,7 +70,7 @@ import java.util.ResourceBundle;
  * @version $Id$
  * @since 2.0
  */
-@Mojo( name = "pmd", threadSafe = true )
+@Mojo( name = "pmd", threadSafe = true, requiresDependencyResolution = ResolutionScope.TEST )
 public class PmdReport
     extends AbstractPmdReport
 {
@@ -122,6 +123,15 @@ public class PmdReport
     private String[] rulesets = new String[]{ "java-basic", "java-unusedcode", "java-imports" };
 
     /**
+     * Controls whether the project's compile/test classpath should be passed to PMD to enable its type resolution
+     * feature.
+     * 
+     * @since 3.0
+     */
+    @Parameter( property = "pmd.typeResolution", defaultValue = "false" )
+    private boolean typeResolution;
+
+    /**
      */
     @Component
     private ResourceManager locator;
@@ -421,6 +431,22 @@ public class PmdReport
             configuration.setDefaultLanguageVersion( languageVersion );
         }
 
+        if ( typeResolution )
+        {
+            try
+            {
+                @SuppressWarnings( "unchecked" )
+                List<String> classpath =
+                    includeTests ? project.getTestClasspathElements() : project.getCompileClasspathElements();
+                getLog().debug( "Using aux classpath: " + classpath );
+                configuration.prependClasspath( StringUtils.join( classpath.iterator(), File.pathSeparator ) );
+            }
+            catch ( Exception e )
+            {
+                throw new MavenReportException( e.getMessage(), e );
+            }
+        }
+
         return configuration;
     }