maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1335764 - in /maven/plugin-tools/branches/MPLUGIN-189: maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/ maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/ maven-plugin-tools-annotations...
Date Tue, 08 May 2012 21:00:45 GMT
Author: olamy
Date: Tue May  8 21:00:44 2012
New Revision: 1335764

URL: http://svn.apache.org/viewvc?rev=1335764&view=rev
Log:
use artifacts for scanning for future use

Modified:
    maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
    maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
    maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java
    maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java
    maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java
    maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java

Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java?rev=1335764&r1=1335763&r2=1335764&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
(original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
Tue May  8 21:00:44 2012
@@ -19,6 +19,7 @@ package org.apache.maven.plugin.plugin;
  * under the License.
  */
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
@@ -124,6 +125,16 @@ public abstract class AbstractGeneratorM
     protected boolean skip;
 
     /**
+     * The set of dependencies for the current project
+     *
+     * @parameter default-value = "${project.artifacts}"
+     * @required
+     * @readonly
+     * @since 3.0
+     */
+    protected Set<Artifact> dependencies;
+
+    /**
      * @return the output directory where files will be generated.
      */
     protected abstract File getOutputDirectory();
@@ -203,6 +214,7 @@ public abstract class AbstractGeneratorM
             PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor
);
             request.setEncoding( encoding );
             request.setSkipErrorNoDescriptorsFound( skipErrorNoDescriptorsFound );
+            request.setDependencies( dependencies );
 
             mojoScanner.populatePluginDescriptor( request );
 

Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java?rev=1335764&r1=1335763&r2=1335764&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
(original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
Tue May  8 21:00:44 2012
@@ -22,7 +22,6 @@ import com.thoughtworks.qdox.JavaDocBuil
 import com.thoughtworks.qdox.model.DocletTag;
 import com.thoughtworks.qdox.model.JavaClass;
 import com.thoughtworks.qdox.model.JavaField;
-import org.apache.maven.artifact.DependencyResolutionRequiredException;
 import org.apache.maven.plugin.descriptor.DuplicateParameterException;
 import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
@@ -75,29 +74,23 @@ public class JavaAnnotationsMojoDescript
     public List<MojoDescriptor> execute( PluginToolsRequest request )
         throws ExtractionException, InvalidPluginDescriptorException
     {
-        try
-        {
-            MojoAnnotationsScannerRequest mojoAnnotationsScannerRequest = new MojoAnnotationsScannerRequest();
 
-            mojoAnnotationsScannerRequest.setClassesDirectories(
-                Arrays.asList( new File( request.getProject().getBuild().getOutputDirectory()
) ) );
+        MojoAnnotationsScannerRequest mojoAnnotationsScannerRequest = new MojoAnnotationsScannerRequest();
 
-            mojoAnnotationsScannerRequest.setDependencies(
-                toFiles( request.getProject().getCompileClasspathElements() ) );
+        mojoAnnotationsScannerRequest.setClassesDirectories(
+            Arrays.asList( new File( request.getProject().getBuild().getOutputDirectory()
) ) );
 
-            Map<String, MojoAnnotatedClass> mojoAnnotatedClasses =
-                mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest );
+        mojoAnnotationsScannerRequest.setDependencies( request.getDependencies() );
 
-            Map<String, JavaClass> javaClassesMap = discoverClasses( request );
+        Map<String, MojoAnnotatedClass> mojoAnnotatedClasses =
+            mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest );
 
-            populateDataFromJavadoc( mojoAnnotatedClasses, javaClassesMap );
+        Map<String, JavaClass> javaClassesMap = discoverClasses( request );
+
+        populateDataFromJavadoc( mojoAnnotatedClasses, javaClassesMap );
+
+        return toMojoDescriptors( mojoAnnotatedClasses, request );
 
-            return toMojoDescriptors( mojoAnnotatedClasses, request );
-        }
-        catch ( DependencyResolutionRequiredException e )
-        {
-            throw new ExtractionException( e.getMessage(), e );
-        }
     }
 
     /**

Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java?rev=1335764&r1=1335763&r2=1335764&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java
(original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java
Tue May  8 21:00:44 2012
@@ -18,6 +18,7 @@ package org.apache.maven.tools.plugin.an
  * under the License.
  */
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Execute;
 import org.apache.maven.plugins.annotations.Mojo;
@@ -66,17 +67,20 @@ public class DefaultMojoAnnotationsScann
         try
         {
 
-            for ( File dependency : request.getDependencies() )
+            for ( Artifact dependency : request.getDependencies() )
             {
-                if ( dependency.isDirectory() )
+                File dependencyFile = dependency.getFile();
+                if ( dependencyFile != null && dependencyFile.exists() )
                 {
-                    mojoAnnotatedClasses.putAll( scanDirectory( dependency, request.getIncludePatterns()
) );
-                }
-                else
-                {
-                    mojoAnnotatedClasses.putAll( scanFile( dependency, request.getIncludePatterns()
) );
+                    if ( dependencyFile.isDirectory() )
+                    {
+                        mojoAnnotatedClasses.putAll( scanDirectory( dependencyFile, request.getIncludePatterns()
) );
+                    }
+                    else
+                    {
+                        mojoAnnotatedClasses.putAll( scanFile( dependencyFile, request.getIncludePatterns()
) );
+                    }
                 }
-
             }
 
             for ( File classDirectory : request.getClassesDirectories() )

Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java?rev=1335764&r1=1335763&r2=1335764&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java
(original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java
Tue May  8 21:00:44 2012
@@ -18,10 +18,14 @@ package org.apache.maven.tools.plugin.an
  * under the License.
  */
 
+import org.apache.maven.artifact.Artifact;
+
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 /**
  * @author Olivier Lamy
@@ -31,7 +35,7 @@ public class MojoAnnotationsScannerReque
 {
     private List<File> classesDirectories = new ArrayList<File>();
 
-    private List<File> dependencies = new ArrayList<File>();
+    private Set<Artifact> dependencies = new HashSet<Artifact>();
 
     private List<String> includePatterns = Arrays.asList( "**/*.class" );
 
@@ -52,12 +56,12 @@ public class MojoAnnotationsScannerReque
         this.classesDirectories = classesDirectories;
     }
 
-    public List<File> getDependencies()
+    public Set<Artifact> getDependencies()
     {
         return dependencies;
     }
 
-    public void setDependencies( List<File> dependencies )
+    public void setDependencies( Set<Artifact> dependencies )
     {
         this.dependencies = dependencies;
     }

Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java?rev=1335764&r1=1335763&r2=1335764&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java
(original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java
Tue May  8 21:00:44 2012
@@ -19,23 +19,27 @@ package org.apache.maven.tools.plugin;
  * under the License.
  */
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.StringUtils;
 
+import java.util.HashSet;
+import java.util.Set;
+
 /**
  * Default implementation of {@link PluginToolsRequest}, which is used to pass parameters
to components used to extract
  * {@link MojoDescriptor} instances from different types of metadata for a given plugin.
- * 
+ *
  * @author jdcasey
  * @since 2.5
  */
 public class DefaultPluginToolsRequest
     implements PluginToolsRequest
 {
-    
+
     private static final String DEFAULT_ENCODING = ReaderFactory.FILE_ENCODING;
 
     private PluginDescriptor pluginDescriptor;
@@ -46,6 +50,8 @@ public class DefaultPluginToolsRequest
 
     private boolean skipErrorNoDescriptorsFound;
 
+    private Set<Artifact> dependencies;
+
     public DefaultPluginToolsRequest( MavenProject project, PluginDescriptor pluginDescriptor
)
     {
         this.project = project;
@@ -59,7 +65,7 @@ public class DefaultPluginToolsRequest
     {
         return pluginDescriptor;
     }
-    
+
     /**
      * {@inheritDoc}
      */
@@ -76,7 +82,7 @@ public class DefaultPluginToolsRequest
     {
         return project;
     }
-    
+
     /**
      * {@inheritDoc}
      */
@@ -127,4 +133,19 @@ public class DefaultPluginToolsRequest
         this.skipErrorNoDescriptorsFound = skipErrorNoDescriptorsFound;
         return this;
     }
+
+    public Set<Artifact> getDependencies()
+    {
+        if ( this.dependencies == null )
+        {
+            this.dependencies = new HashSet<Artifact>();
+        }
+        return dependencies;
+    }
+
+    public PluginToolsRequest setDependencies( Set<Artifact> dependencies )
+    {
+        this.dependencies = dependencies;
+        return this;
+    }
 }

Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java?rev=1335764&r1=1335763&r2=1335764&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java
(original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java
Tue May  8 21:00:44 2012
@@ -19,10 +19,13 @@ package org.apache.maven.tools.plugin;
  * under the License.
  */
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
 import org.apache.maven.project.MavenProject;
 
+import java.util.Set;
+
 /**
  * Request that encapsulates all information relevant to the process of extracting {@link
MojoDescriptor}
  * instances from metadata for a certain type of mojo.
@@ -74,16 +77,29 @@ public interface PluginToolsRequest
      * By default an exception is throw if no mojo descriptor is found. As the maven-plugin
is defined in core, the
      * descriptor generator mojo is bound to generate-resources phase.
      * But for annotations, the compiled classes are needed, so skip error
+     *
      * @since 3.0
      */
     PluginToolsRequest setSkipErrorNoDescriptorsFound( boolean skipErrorNoDescriptorsFound
);
 
     /**
-     * @since 3.0
      * @return
+     * @since 3.0
      */
     boolean isSkipErrorNoDescriptorsFound();
 
+    /**
+     * Returns the list of {@link Artifact} used in class path scanning for annotations
+     * @return
+     * @since 3.0
+     */
+    Set<Artifact> getDependencies();
 
+    /**
+     *
+     * @param dependencies
+     * @return
+     */
+    PluginToolsRequest setDependencies( Set<Artifact> dependencies );
 
 }



Mime
View raw message