[maven-pmd-plugin] branch MPMD-266 created (now c59c1cf)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[maven-pmd-plugin] branch MPMD-266 created (now c59c1cf)

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

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


      at c59c1cf  [MPMD-266] Aggregate report in multi-module projects doesn't use correct auxclasspath

This branch includes the following new commits:

     new a2bdbbd  [MPMD-266] Aggregate report in multi-module projects doesn't use correct auxclasspath
     new c59c1cf  [MPMD-266] Aggregate report in multi-module projects doesn't use correct auxclasspath

The 2 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.


Reply | Threaded
Open this post in threaded view
|

[maven-pmd-plugin] 01/02: [MPMD-266] Aggregate report in multi-module projects doesn't use correct auxclasspath

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

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

commit a2bdbbd39dea2e82cbececbaf75b25aa93b497d0
Author: Andreas Dangel <[hidden email]>
AuthorDate: Thu Oct 11 19:11:18 2018 +0200

    [MPMD-266] Aggregate report in multi-module projects doesn't use correct auxclasspath
   
    Extend test case to use a 3rd-party dependency.
---
 src/it/MPMD-266-typeresolution-aggregated/module-b/pom.xml  |  6 ++++++
 .../module-b/src/main/java/module/b/ModuleB.java            | 13 +++++++++++++
 src/it/MPMD-266-typeresolution-aggregated/verify.groovy     |  2 ++
 3 files changed, 21 insertions(+)

diff --git a/src/it/MPMD-266-typeresolution-aggregated/module-b/pom.xml b/src/it/MPMD-266-typeresolution-aggregated/module-b/pom.xml
index da1e92f..3a67e1f 100644
--- a/src/it/MPMD-266-typeresolution-aggregated/module-b/pom.xml
+++ b/src/it/MPMD-266-typeresolution-aggregated/module-b/pom.xml
@@ -36,5 +36,11 @@ under the License.
       <artifactId>MPMD-266-typeresolution-aggregated-module-a</artifactId>
       <version>${project.version}</version>
     </dependency>
+
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-math</artifactId>
+      <version>2.2</version>
+    </dependency>
   </dependencies>
 </project>
diff --git a/src/it/MPMD-266-typeresolution-aggregated/module-b/src/main/java/module/b/ModuleB.java b/src/it/MPMD-266-typeresolution-aggregated/module-b/src/main/java/module/b/ModuleB.java
index d5c2225..0689d93 100644
--- a/src/it/MPMD-266-typeresolution-aggregated/module-b/src/main/java/module/b/ModuleB.java
+++ b/src/it/MPMD-266-typeresolution-aggregated/module-b/src/main/java/module/b/ModuleB.java
@@ -21,6 +21,8 @@ package module.b;
 
 import module.a.IModuleA;
 import module.a.ModuleA;
+import org.apache.commons.math.complex.Complex;
+import org.apache.commons.math.FieldElement;
 
 public class ModuleB
 {
@@ -38,4 +40,15 @@ public class ModuleB
     {
         System.out.println( module );
     }
+
+    public static void aPublicMethod()
+    {
+        Complex u = new Complex(1, 1);
+        aPrivateMethod( u );
+    }
+
+    private static void aPrivateMethod( FieldElement<Complex> u )
+    {
+        System.out.println( "aPrivateMethod: " + u );
+    }
 }
\ No newline at end of file
diff --git a/src/it/MPMD-266-typeresolution-aggregated/verify.groovy b/src/it/MPMD-266-typeresolution-aggregated/verify.groovy
index b523700..da8f51f 100644
--- a/src/it/MPMD-266-typeresolution-aggregated/verify.groovy
+++ b/src/it/MPMD-266-typeresolution-aggregated/verify.groovy
@@ -20,7 +20,9 @@
 File pmdXml = new File( basedir, "target/pmd.xml" )
 assert pmdXml.exists()
 assert !pmdXml.text.contains( "Avoid unused private methods such as 'doSomething(IModuleA)'." )
+assert !pmdXml.text.contains( "Avoid unused private methods such as 'aPrivateMethod(FieldElement)'." )
 
 File pmdHtml = new File( basedir, "target/site/pmd.html" )
 assert pmdHtml.exists()
 assert !pmdHtml.text.contains( "Avoid unused private methods such as 'doSomething(IModuleA)'." )
+assert !pmdHtml.text.contains( "Avoid unused private methods such as 'aPrivateMethod(FieldElement)'." )

Reply | Threaded
Open this post in threaded view
|

[maven-pmd-plugin] 02/02: [MPMD-266] Aggregate report in multi-module projects doesn't use correct auxclasspath

adangel
In reply to this post by adangel
This is an automated email from the ASF dual-hosted git repository.

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

commit c59c1cf2909dc3506bd66e9d46d17c2ada73f6cc
Author: Andreas Dangel <[hidden email]>
AuthorDate: Thu Oct 11 20:56:59 2018 +0200

    [MPMD-266] Aggregate report in multi-module projects doesn't use correct auxclasspath
   
    Use maven-artifact-transfer to resolve the dependencies
    of the reactor projects.
---
 pom.xml                                            |  5 ++++
 .../org/apache/maven/plugins/pmd/PmdReport.java    | 33 ++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/pom.xml b/pom.xml
index f9dac8f..e22451a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -120,6 +120,11 @@ under the License.
       <artifactId>maven-plugin-annotations</artifactId>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-artifact-transfer</artifactId>
+      <version>0.10.0</version>
+    </dependency>
 
     <!-- pmd -->
     <dependency>
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 0b39c06..bbadea7 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
@@ -35,13 +35,19 @@ import java.util.Properties;
 import java.util.ResourceBundle;
 
 import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.MojoExecutionException;
 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.project.DefaultProjectBuildingRequest;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.reporting.MavenReportException;
+import org.apache.maven.shared.artifact.filter.resolve.ScopeFilter;
+import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult;
+import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver;
 import org.codehaus.plexus.resource.ResourceManager;
 import org.codehaus.plexus.resource.loader.FileResourceCreationException;
 import org.codehaus.plexus.resource.loader.FileResourceLoader;
@@ -227,6 +233,12 @@ public class PmdReport
     @Parameter( property = "pmd.renderRuleViolationPriority", defaultValue = "true" )
     private boolean renderRuleViolationPriority = true;
 
+    @Component
+    private DependencyResolver dependencyResolver;
+
+    @Parameter( defaultValue = "${session}", required = true, readonly = true )
+    private MavenSession session;
+
     /**
      * {@inheritDoc}
      */
@@ -707,11 +719,32 @@ public class PmdReport
             List<String> classpath = new ArrayList<>();
             if ( aggregate )
             {
+                List<String> dependencies = new ArrayList<>();
+
                 for ( MavenProject localProject : reactorProjects )
                 {
+                    // Add the project's target folder first
                     classpath.addAll( includeTests ? localProject.getTestClasspathElements()
                             : localProject.getCompileClasspathElements() );
+
+                    ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(
+                            session.getProjectBuildingRequest() );
+
+                    Iterable<ArtifactResult> resolvedDependencies = dependencyResolver.resolveDependencies(
+                            buildingRequest, localProject.getModel(),
+                            includeTests ? ScopeFilter.including( "test" ) : ScopeFilter.including( "compile" ) );
+
+                    for ( ArtifactResult resolvedArtifact : resolvedDependencies )
+                    {
+                        dependencies.add( resolvedArtifact.getArtifact().getFile().toString() );
+                    }
+
                 }
+
+                // Add the dependencies as last entries
+                getLog().debug( "Resolved " + dependencies.size() + " additional dependencies.");
+                classpath.addAll( dependencies );
+
                 getLog().debug( "Using aggregated aux classpath: " + classpath );
             }
             else