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:04:17 UTC
svn commit: r1333848 - in /maven/plugin-tools/branches/MPLUGIN-189: ./
maven-plugin-tools-annotations/
maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/
maven-plugin-tools-annotations/src/main/java/org/apache/maven...
Author: olamy
Date: Fri May 4 10:04:16 2012
New Revision: 1333848
URL: http://svn.apache.org/viewvc?rev=1333848&view=rev
Log:
move to a Map with className as key to merge with javadoc scan
Modified:
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/pom.xml
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/MojoAnnotationsScanner.java
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-java/pom.xml
maven/plugin-tools/branches/MPLUGIN-189/pom.xml
Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/pom.xml?rev=1333848&r1=1333847&r2=1333848&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/pom.xml (original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/pom.xml Fri May 4 10:04:16 2012
@@ -71,6 +71,12 @@
<artifactId>asm-commons</artifactId>
<version>3.3.1</version>
</dependency>
+
+ <dependency>
+ <groupId>com.thoughtworks.qdox</groupId>
+ <artifactId>qdox</artifactId>
+ </dependency>
+
</dependencies>
</project>
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=1333848&r1=1333847&r2=1333848&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:04:16 2012
@@ -18,6 +18,8 @@ package org.apache.maven.tools.plugin.an
* under the License.
*/
+import com.thoughtworks.qdox.JavaDocBuilder;
+import com.thoughtworks.qdox.model.JavaClass;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.descriptor.DuplicateParameterException;
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
@@ -43,6 +45,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
/**
* @author Olivier Lamy
@@ -76,9 +79,11 @@ public class JavaAnnotationsMojoDescript
mojoAnnotationsScannerRequest.setDependencies( request.getProject().getCompileClasspathElements() );
- List<MojoAnnotatedClass> mojoAnnotatedClasses =
+ Map<String, MojoAnnotatedClass> mojoAnnotatedClasses =
mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest );
+ JavaClass[] javaClasses = discoverClasses( request );
+
return toMojoDescriptors( mojoAnnotatedClasses, request );
}
catch ( DependencyResolutionRequiredException e )
@@ -87,6 +92,28 @@ public class JavaAnnotationsMojoDescript
}
}
+ protected JavaClass[] discoverClasses( final PluginToolsRequest request )
+ {
+ JavaDocBuilder builder = new JavaDocBuilder();
+ builder.setEncoding( request.getEncoding() );
+
+ MavenProject project = request.getProject();
+
+ for ( String source : (List<String>) project.getCompileSourceRoots() )
+ {
+ builder.addSourceTree( new File( source ) );
+ }
+
+ // TODO be more dynamic
+ File generatedPlugin = new File( project.getBasedir(), "target/generated-sources/plugin" );
+ if ( !project.getCompileSourceRoots().contains( generatedPlugin.getAbsolutePath() ) )
+ {
+ builder.addSourceTree( generatedPlugin );
+ }
+
+ return builder.getClasses();
+ }
+
private List<File> toFiles( List<String> directories )
{
if ( directories == null )
@@ -101,18 +128,19 @@ public class JavaAnnotationsMojoDescript
return files;
}
- private List<MojoDescriptor> toMojoDescriptors( List<MojoAnnotatedClass> mojoAnnotatedClasses,
+ private List<MojoDescriptor> toMojoDescriptors( Map<String, MojoAnnotatedClass> mojoAnnotatedClasses,
PluginToolsRequest request )
throws DuplicateParameterException
{
List<MojoDescriptor> mojoDescriptors = new ArrayList<MojoDescriptor>( mojoAnnotatedClasses.size() );
- for ( MojoAnnotatedClass mojoAnnotatedClass : mojoAnnotatedClasses )
+ for ( MojoAnnotatedClass mojoAnnotatedClass : mojoAnnotatedClasses.values() )
{
MojoDescriptor mojoDescriptor = new MojoDescriptor();
//mojoDescriptor.setRole( mojoAnnotatedClass.getClassName() );
//mojoDescriptor.setRoleHint( "default" );
mojoDescriptor.setImplementation( mojoAnnotatedClass.getClassName() );
+ mojoDescriptor.setLanguage( "java" );
MojoAnnotationContent mojo = mojoAnnotatedClass.getMojo();
@@ -138,7 +166,6 @@ public class JavaAnnotationsMojoDescript
mojoDescriptor.setOnlineRequired( mojo.requiresOnline() );
mojoDescriptor.setPhase( mojo.defaultPhase().id() );
- mojoDescriptor.setLanguage( "java" );
for ( ParameterAnnotationContent parameterAnnotationContent : mojoAnnotatedClass.getParameters() )
{
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=1333848&r1=1333847&r2=1333848&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 Fri May 4 10:04:16 2012
@@ -41,7 +41,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -55,22 +55,21 @@ public class DefaultMojoAnnotationsScann
{
private Reflector reflector = new Reflector();
- public List<MojoAnnotatedClass> scan( MojoAnnotationsScannerRequest request )
+ public Map<String, MojoAnnotatedClass> scan( MojoAnnotationsScannerRequest request )
throws ExtractionException
{
- List<MojoAnnotatedClass> mojoAnnotatedClasses = new ArrayList<MojoAnnotatedClass>();
+ Map<String, MojoAnnotatedClass> mojoAnnotatedClasses = new HashMap<String, MojoAnnotatedClass>();
try
{
for ( File classDirectory : request.getClassesDirectories() )
{
if ( classDirectory.exists() && classDirectory.isDirectory() )
{
- mojoAnnotatedClasses.addAll( scanDirectory( classDirectory, request.getIncludePatterns() ) );
+ mojoAnnotatedClasses.putAll( scanDirectory( classDirectory, request.getIncludePatterns() ) );
// TODO scan sources to get @since and @deprecated and description of classes and fields.
}
}
-
//TODO scan dependencies to get super class annotations if exist request.getDependencies()
return mojoAnnotatedClasses;
@@ -81,10 +80,10 @@ public class DefaultMojoAnnotationsScann
}
}
- protected List<MojoAnnotatedClass> scanDirectory( File classDirectory, List<String> includePatterns )
+ protected Map<String, MojoAnnotatedClass> scanDirectory( File classDirectory, List<String> includePatterns )
throws IOException, ExtractionException
{
- List<MojoAnnotatedClass> mojoAnnotatedClasses = new ArrayList<MojoAnnotatedClass>();
+ Map<String, MojoAnnotatedClass> mojoAnnotatedClasses = new HashMap<String, MojoAnnotatedClass>();
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir( classDirectory );
scanner.addDefaultExcludes();
@@ -110,7 +109,8 @@ public class DefaultMojoAnnotationsScann
analyzeVisitors( mojoClassVisitor );
if ( isMojoAnnnotatedClassCandidate( mojoClassVisitor.getMojoAnnotatedClass() ) != null )
{
- mojoAnnotatedClasses.add( mojoClassVisitor.getMojoAnnotatedClass() );
+ mojoAnnotatedClasses.put( mojoClassVisitor.getMojoAnnotatedClass().getClassName(),
+ mojoClassVisitor.getMojoAnnotatedClass() );
}
}
Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.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/MojoAnnotationsScanner.java?rev=1333848&r1=1333847&r2=1333848&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java (original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java Fri May 4 10:04:16 2012
@@ -26,6 +26,7 @@ import org.apache.maven.tools.plugin.ext
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
/**
* @author Olivier Lamy
@@ -41,6 +42,6 @@ public interface MojoAnnotationsScanner
static final List<String> acceptedFieldLevelAnnotationClasses =
Arrays.asList( Parameter.class.getName(), Component.class.getName() );
- List<MojoAnnotatedClass> scan( MojoAnnotationsScannerRequest request )
+ Map<String, MojoAnnotatedClass> scan( MojoAnnotationsScannerRequest request )
throws ExtractionException;
}
Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java?rev=1333848&r1=1333847&r2=1333848&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java (original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java Fri May 4 10:04:16 2012
@@ -34,6 +34,7 @@ import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
/**
* @author Olivier Lamy
@@ -50,13 +51,13 @@ public class TestAnnotationsReader
request.setClassesDirectories( Collections.singletonList( new File( "target/test-classes" ) ) );
request.setIncludePatterns( Arrays.asList( "**/FooMojo.class" ) );
- List<MojoAnnotatedClass> mojoAnnotatedClasses = mojoAnnotationsScanner.scan( request );
+ Map<String, MojoAnnotatedClass> mojoAnnotatedClasses = mojoAnnotationsScanner.scan( request );
System.out.println( "mojoAnnotatedClasses:" + mojoAnnotatedClasses );
Assertions.assertThat( mojoAnnotatedClasses ).isNotNull().isNotEmpty().hasSize( 1 );
- MojoAnnotatedClass mojoAnnotatedClass = mojoAnnotatedClasses.get( 0 );
+ MojoAnnotatedClass mojoAnnotatedClass = mojoAnnotatedClasses.values().iterator().next();
assertEquals( FooMojo.class.getName(), mojoAnnotatedClass.getClassName() );
assertEquals( AbstractMojo.class.getName(), mojoAnnotatedClass.getParentClassName() );
Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-java/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-java/pom.xml?rev=1333848&r1=1333847&r2=1333848&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-java/pom.xml (original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-java/pom.xml Fri May 4 10:04:16 2012
@@ -66,7 +66,6 @@
<dependency>
<groupId>com.thoughtworks.qdox</groupId>
<artifactId>qdox</artifactId>
- <version>1.11</version>
</dependency>
<dependency>
Modified: maven/plugin-tools/branches/MPLUGIN-189/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/pom.xml?rev=1333848&r1=1333847&r2=1333848&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/pom.xml (original)
+++ maven/plugin-tools/branches/MPLUGIN-189/pom.xml Fri May 4 10:04:16 2012
@@ -230,6 +230,12 @@
</dependency>
<dependency>
+ <groupId>com.thoughtworks.qdox</groupId>
+ <artifactId>qdox</artifactId>
+ <version>1.11</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>${pluginTestingHarnessVersion}</version>