diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java index 9f1a05f..5de46e5 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java @@ -25,10 +25,16 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor; 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 JavaAnnotationsMojoDescriptorExtractor implements MojoDescriptorExtractor { + /** + * @requirement + */ + MojoAnnotationsScanner mojoAnnotationsScanner; + public List execute( MavenProject project, PluginDescriptor pluginDescriptor ) throws ExtractionException, InvalidPluginDescriptorException { @@ -50,12 +61,50 @@ public class JavaAnnotationsMojoDescriptorExtractor { try { - List classpathElements = request.getProject().getCompileClasspathElements(); - return null; //To change body of implemented methods use File | Settings | File Templates. + MojoAnnotationsScannerRequest mojoAnnotationsScannerRequest = new MojoAnnotationsScannerRequest(); + List classesDirectories = toFiles( request.getProject().getCompileClasspathElements() ); + mojoAnnotationsScannerRequest.setClassesDirectories( classesDirectories ); + + List mojoAnnotatedClasses = + mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest ); + + return toMojoDescriptors( mojoAnnotatedClasses ); } catch ( DependencyResolutionRequiredException e ) { throw new ExtractionException( e.getMessage(), e ); } } + + private List toFiles( List directories ) + { + if ( directories == null ) + { + return Collections.emptyList(); + } + List files = new ArrayList( directories.size() ); + for ( String directory : directories ) + { + files.add( new File( directory ) ); + } + return files; + } + + private List toMojoDescriptors( List mojoAnnotatedClasses ) + { + List mojoDescriptors = new ArrayList( 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; + } } diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java new file mode 100644 index 0000000..5f3cb55 --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java @@ -0,0 +1,61 @@ +package org.apache.maven.tools.plugin.annotations.datamodel; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * @author Olivier Lamy + */ +public class AnnotatedContent +{ + private String description; + + private String since; + + private String deprecated; + + public String getDescription() + { + return description; + } + + public void setDescription( String description ) + { + this.description = description; + } + + public String getSince() + { + return since; + } + + public void setSince( String since ) + { + this.since = since; + } + + public String getDeprecated() + { + return deprecated; + } + + public void setDeprecated( String deprecated ) + { + this.deprecated = deprecated; + } +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java index cc9bf6d..0169206 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java @@ -22,6 +22,7 @@ package org.apache.maven.tools.plugin.annotations.datamodel; * @author Olivier Lamy */ public class AnnotatedField + extends AnnotatedContent { private String fieldName; diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/MojoAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/MojoAnnotationContent.java index 8986633..fdbf6ae 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/MojoAnnotationContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/MojoAnnotationContent.java @@ -27,6 +27,7 @@ import java.lang.annotation.Annotation; * @author Olivier Lamy */ public class MojoAnnotationContent + extends AnnotatedContent implements Mojo { private String name; diff --git a/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml b/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml index d7b2dbe..91df740 100644 --- a/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml +++ b/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml @@ -30,6 +30,12 @@ org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor java-annotations org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor + + + org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner + default + +