Author: agudian
Date: Wed Jan 27 20:20:58 2016
New Revision: 1727176

URL: http://svn.apache.org/viewvc?rev=1727176&view=rev
Log:
[MCOMPILER-262] Don't add project dependencies to -processorpath when using the 
annotationProcessorPaths option, but only the dependencies of the processor 
artifacts.

Modified:
    
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-203-processorpath/annotation-processor/pom.xml
    
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-203-processorpath/annotation-processor/src/main/java/org/issue/SimpleAnnotationProcessor.java
    
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-203-processorpath/annotation-user/pom.xml
    
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

Modified: 
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-203-processorpath/annotation-processor/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-203-processorpath/annotation-processor/pom.xml?rev=1727176&r1=1727175&r2=1727176&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-203-processorpath/annotation-processor/pom.xml
 (original)
+++ 
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-203-processorpath/annotation-processor/pom.xml
 Wed Jan 27 20:20:58 2016
@@ -31,4 +31,12 @@ under the License.
   </parent>
 
   <artifactId>annotation-processor</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <version>3.4</version>
+    </dependency>
+  </dependencies>
 </project>

Modified: 
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-203-processorpath/annotation-processor/src/main/java/org/issue/SimpleAnnotationProcessor.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-203-processorpath/annotation-processor/src/main/java/org/issue/SimpleAnnotationProcessor.java?rev=1727176&r1=1727175&r2=1727176&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-203-processorpath/annotation-processor/src/main/java/org/issue/SimpleAnnotationProcessor.java
 (original)
+++ 
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-203-processorpath/annotation-processor/src/main/java/org/issue/SimpleAnnotationProcessor.java
 Wed Jan 27 20:20:58 2016
@@ -52,6 +52,29 @@ public class SimpleAnnotationProcessor
             return true;
         }
 
+        // assert that commons-lang3 is on the classpath
+        try
+        {
+            getClass().getClassLoader().loadClass( 
"org.apache.commons.lang3.StringUtils" );
+        }
+        catch ( ClassNotFoundException expected )
+        {
+            throw new RuntimeException( "Expected 
org.apache.commons.lang3.StringUtils to be on the processorpath,"
+                + "because it is a declared dependency of the annotation 
processor." );
+        }
+
+        // assert that commons-io is NOT on the classpath, as it is only a 
project dependency in "annotation-user"
+        try
+        {
+            getClass().getClassLoader().loadClass( 
"org.apache.commons.io.IOUtils" );
+            throw new RuntimeException( "Expected a ClassNotFoundException 
because "
+                + "org.apache.commons.io.IOUtils is not supposed to be on the 
processorpath." );
+        }
+        catch ( ClassNotFoundException expected )
+        {
+            // expected.
+        }
+
         Filer filer = processingEnv.getFiler();
 
         Elements elementUtils = processingEnv.getElementUtils();

Modified: 
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-203-processorpath/annotation-user/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-203-processorpath/annotation-user/pom.xml?rev=1727176&r1=1727175&r2=1727176&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-203-processorpath/annotation-user/pom.xml
 (original)
+++ 
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-203-processorpath/annotation-user/pom.xml
 Wed Jan 27 20:20:58 2016
@@ -33,6 +33,11 @@ under the License.
 
   <dependencies>
     <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>2.4</version>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.10</version>

Modified: 
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java?rev=1727176&r1=1727175&r2=1727176&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
 Wed Jan 27 20:20:58 2016
@@ -64,6 +64,7 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -1356,7 +1357,7 @@ public abstract class AbstractCompilerMo
 
         try
         {
-            Set<Artifact> requiredArtifacts = new HashSet<Artifact>();
+            Set<Artifact> requiredArtifacts = new LinkedHashSet<Artifact>();
 
             for ( DependencyCoordinate coord : annotationProcessorPaths )
             {
@@ -1376,8 +1377,8 @@ public abstract class AbstractCompilerMo
             }
 
             ArtifactResolutionRequest request = new ArtifactResolutionRequest()
-                            .setArtifact( project.getArtifact() )
-                            .setResolveRoot( false )
+                            .setArtifact( requiredArtifacts.iterator().next() )
+                            .setResolveRoot( true )
                             .setResolveTransitively( true )
                             .setArtifactDependencies( requiredArtifacts )
                             .setLocalRepository( session.getLocalRepository() )
@@ -1387,14 +1388,14 @@ public abstract class AbstractCompilerMo
 
             resolutionErrorHandler.throwErrors( request, resolutionResult );
 
-            List<String> classpathElements = new ArrayList<String>( 
resolutionResult.getArtifacts().size() );
+            List<String> elements = new ArrayList<String>( 
resolutionResult.getArtifacts().size() );
 
             for ( Object resolved : resolutionResult.getArtifacts() )
             {
-                classpathElements.add( ( (Artifact) resolved 
).getFile().getAbsolutePath() );
+                elements.add( ( (Artifact) resolved 
).getFile().getAbsolutePath() );
             }
 
-            return classpathElements;
+            return elements;
         }
         catch ( Exception e )
         {


Reply via email to