You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2012/05/04 12:00:53 UTC

svn commit: r1333839 - in /maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main: java/org/apache/maven/tools/plugin/annotations/ java/org/apache/maven/tools/plugin/annotations/datamodel/ resources/META-INF/plexus/

Author: olamy
Date: Fri May  4 10:00:53 2012
New Revision: 1333839

URL: http://svn.apache.org/viewvc?rev=1333839&view=rev
Log:
[MPLUGIN-189] add a datamodel parent class with description,since and deprecated which need to parse with qdox

Added:
    maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java
      - copied, changed from r1333837, maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java
Modified:
    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/datamodel/AnnotatedField.java
    maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/MojoAnnotationContent.java
    maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml

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=1333839&r1=1333838&r2=1333839&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 Fri May  4 10:00:53 2012
@@ -25,10 +25,16 @@ import org.apache.maven.plugin.descripto
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
 import org.apache.maven.tools.plugin.PluginToolsRequest;
+import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotatedClass;
+import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner;
+import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScannerRequest;
 import org.apache.maven.tools.plugin.extractor.ExtractionException;
 import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -39,6 +45,11 @@ public class JavaAnnotationsMojoDescript
     implements MojoDescriptorExtractor
 {
 
+    /**
+     * @requirement
+     */
+    MojoAnnotationsScanner mojoAnnotationsScanner;
+
     public List<MojoDescriptor> execute( MavenProject project, PluginDescriptor pluginDescriptor )
         throws ExtractionException, InvalidPluginDescriptorException
     {
@@ -50,12 +61,50 @@ public class JavaAnnotationsMojoDescript
     {
         try
         {
-            List<String> classpathElements = request.getProject().getCompileClasspathElements();
-            return null;  //To change body of implemented methods use File | Settings | File Templates.
+            MojoAnnotationsScannerRequest mojoAnnotationsScannerRequest = new MojoAnnotationsScannerRequest();
+            List<File> classesDirectories = toFiles( request.getProject().getCompileClasspathElements() );
+            mojoAnnotationsScannerRequest.setClassesDirectories( classesDirectories );
+
+            List<MojoAnnotatedClass> mojoAnnotatedClasses =
+                mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest );
+
+            return toMojoDescriptors( mojoAnnotatedClasses );
         }
         catch ( DependencyResolutionRequiredException e )
         {
             throw new ExtractionException( e.getMessage(), e );
         }
     }
+
+    private List<File> toFiles( List<String> directories )
+    {
+        if ( directories == null )
+        {
+            return Collections.emptyList();
+        }
+        List<File> files = new ArrayList<File>( directories.size() );
+        for ( String directory : directories )
+        {
+            files.add( new File( directory ) );
+        }
+        return files;
+    }
+
+    private List<MojoDescriptor> toMojoDescriptors( List<MojoAnnotatedClass> mojoAnnotatedClasses )
+    {
+        List<MojoDescriptor> mojoDescriptors = new ArrayList<MojoDescriptor>( mojoAnnotatedClasses.size() );
+        for ( MojoAnnotatedClass mojoAnnotatedClass : mojoAnnotatedClasses )
+        {
+            MojoDescriptor mojoDescriptor = new MojoDescriptor();
+
+            Mojo mojo = mojoAnnotatedClass.getMojo();
+
+            mojoDescriptor.setAggregator( mojo.aggregator() );
+            mojoDescriptor.setDependencyResolutionRequired( mojo.requiresDependencyResolution() );
+            mojoDescriptor.setDirectInvocationOnly( mojo.requiresDirectInvocation() );
+
+            mojoDescriptors.add( mojoDescriptor );
+        }
+        return mojoDescriptors;
+    }
 }

Copied: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java (from r1333837, maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.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/datamodel/AnnotatedContent.java?p2=maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java&p1=maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java&r1=1333837&r2=1333839&rev=1333839&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java (original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java Fri May  4 10:00:53 2012
@@ -21,32 +21,41 @@ package org.apache.maven.tools.plugin.an
 /**
  * @author Olivier Lamy
  */
-public class AnnotatedField
+public class AnnotatedContent
 {
-    private String fieldName;
+    private String description;
 
-    public AnnotatedField( String fieldName )
+    private String since;
+
+    private String deprecated;
+
+    public String getDescription()
+    {
+        return description;
+    }
+
+    public void setDescription( String description )
+    {
+        this.description = description;
+    }
+
+    public String getSince()
     {
-        this.fieldName = fieldName;
+        return since;
     }
 
-    public String getFieldName()
+    public void setSince( String since )
     {
-        return fieldName;
+        this.since = since;
     }
 
-    public void setFieldName( String name )
+    public String getDeprecated()
     {
-        this.fieldName = name;
+        return deprecated;
     }
 
-    @Override
-    public String toString()
+    public void setDeprecated( String deprecated )
     {
-        final StringBuilder sb = new StringBuilder();
-        sb.append( "AnnotatedField" );
-        sb.append( "{fieldName='" ).append( fieldName ).append( '\'' );
-        sb.append( '}' );
-        return sb.toString();
+        this.deprecated = deprecated;
     }
 }

Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.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/datamodel/AnnotatedField.java?rev=1333839&r1=1333838&r2=1333839&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java (original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java Fri May  4 10:00:53 2012
@@ -22,6 +22,7 @@ package org.apache.maven.tools.plugin.an
  * @author Olivier Lamy
  */
 public class AnnotatedField
+    extends AnnotatedContent
 {
     private String fieldName;
 

Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/MojoAnnotationContent.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/datamodel/MojoAnnotationContent.java?rev=1333839&r1=1333838&r2=1333839&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/MojoAnnotationContent.java (original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/MojoAnnotationContent.java Fri May  4 10:00:53 2012
@@ -27,6 +27,7 @@ import java.lang.annotation.Annotation;
  * @author Olivier Lamy
  */
 public class MojoAnnotationContent
+    extends AnnotatedContent
     implements Mojo
 {
     private String name;

Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml?rev=1333839&r1=1333838&r2=1333839&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml Fri May  4 10:00:53 2012
@@ -30,6 +30,12 @@
       <role>org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor</role>
       <role-hint>java-annotations</role-hint>
       <implementation>org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner</role>
+          <role-hint>default</role-hint>
+        </requirement>
+      </requirements>
     </component>
 
     <component>