store the origin artifact of the annotation for later use

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1335765 13f79535-47bb-0310-9956-ffa450edef68
master
Olivier Lamy 2012-05-08 21:01:10 +00:00
parent 18e8cb4178
commit 3dd6a922a9
7 changed files with 51 additions and 5 deletions

View File

@ -6,6 +6,8 @@ assert descriptorFile.isFile()
def pluginDescriptor = new XmlParser().parse( descriptorFile ); def pluginDescriptor = new XmlParser().parse( descriptorFile );
assert pluginDescriptor.mojos.mojo.size() == 3
def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first"}[0] def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first"}[0]
assert mojo.goal.text() == 'first' assert mojo.goal.text() == 'first'

View File

@ -82,6 +82,8 @@ public class JavaAnnotationsMojoDescriptorExtractor
mojoAnnotationsScannerRequest.setDependencies( request.getDependencies() ); mojoAnnotationsScannerRequest.setDependencies( request.getDependencies() );
mojoAnnotationsScannerRequest.setProject( request.getProject() );
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses = Map<String, MojoAnnotatedClass> mojoAnnotatedClasses =
mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest ); mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest );

View File

@ -18,12 +18,15 @@ package org.apache.maven.tools.plugin.annotations.datamodel;
* under the License. * under the License.
*/ */
import org.apache.maven.artifact.Artifact;
/** /**
* @author Olivier Lamy * @author Olivier Lamy
* @since 3.0 * @since 3.0
*/ */
public class AnnotatedContent public class AnnotatedContent
{ {
private String description; private String description;
private String since; private String since;
@ -59,4 +62,5 @@ public class AnnotatedContent
{ {
this.deprecated = deprecated; this.deprecated = deprecated;
} }
} }

View File

@ -74,11 +74,13 @@ public class DefaultMojoAnnotationsScanner
{ {
if ( dependencyFile.isDirectory() ) if ( dependencyFile.isDirectory() )
{ {
mojoAnnotatedClasses.putAll( scanDirectory( dependencyFile, request.getIncludePatterns() ) ); mojoAnnotatedClasses.putAll(
scanDirectory( dependencyFile, request.getIncludePatterns(), dependency ) );
} }
else else
{ {
mojoAnnotatedClasses.putAll( scanFile( dependencyFile, request.getIncludePatterns() ) ); mojoAnnotatedClasses.putAll(
scanFile( dependencyFile, request.getIncludePatterns(), dependency ) );
} }
} }
} }
@ -87,7 +89,8 @@ public class DefaultMojoAnnotationsScanner
{ {
if ( classDirectory.exists() && classDirectory.isDirectory() ) if ( classDirectory.exists() && classDirectory.isDirectory() )
{ {
mojoAnnotatedClasses.putAll( scanDirectory( classDirectory, request.getIncludePatterns() ) ); mojoAnnotatedClasses.putAll( scanDirectory( classDirectory, request.getIncludePatterns(),
request.getProject().getArtifact() ) );
} }
} }
@ -99,7 +102,8 @@ public class DefaultMojoAnnotationsScanner
} }
} }
protected Map<String, MojoAnnotatedClass> scanFile( File archiveFile, List<String> includePatterns ) protected Map<String, MojoAnnotatedClass> scanFile( File archiveFile, List<String> includePatterns,
Artifact artifact )
throws IOException, ExtractionException throws IOException, ExtractionException
{ {
if ( !archiveFile.exists() ) if ( !archiveFile.exists() )
@ -127,6 +131,7 @@ public class DefaultMojoAnnotationsScanner
getLogger().debug( getLogger().debug(
"found MojoAnnotatedClass:" + mojoClassVisitor.getMojoAnnotatedClass().getClassName() + ":" "found MojoAnnotatedClass:" + mojoClassVisitor.getMojoAnnotatedClass().getClassName() + ":"
+ mojoClassVisitor.getMojoAnnotatedClass() ); + mojoClassVisitor.getMojoAnnotatedClass() );
mojoClassVisitor.getMojoAnnotatedClass().setArtifact( artifact );
mojoAnnotatedClasses.put( mojoClassVisitor.getMojoAnnotatedClass().getClassName(), mojoAnnotatedClasses.put( mojoClassVisitor.getMojoAnnotatedClass().getClassName(),
mojoClassVisitor.getMojoAnnotatedClass() ); mojoClassVisitor.getMojoAnnotatedClass() );
} }
@ -140,7 +145,8 @@ public class DefaultMojoAnnotationsScanner
return mojoAnnotatedClasses; return mojoAnnotatedClasses;
} }
protected Map<String, MojoAnnotatedClass> scanDirectory( File classDirectory, List<String> includePatterns ) protected Map<String, MojoAnnotatedClass> scanDirectory( File classDirectory, List<String> includePatterns,
Artifact artifact )
throws IOException, ExtractionException throws IOException, ExtractionException
{ {
if ( !classDirectory.exists() ) if ( !classDirectory.exists() )
@ -176,6 +182,7 @@ public class DefaultMojoAnnotationsScanner
getLogger().debug( getLogger().debug(
"found MojoAnnotatedClass:" + mojoClassVisitor.getMojoAnnotatedClass().getClassName() + ":" "found MojoAnnotatedClass:" + mojoClassVisitor.getMojoAnnotatedClass().getClassName() + ":"
+ mojoClassVisitor.getMojoAnnotatedClass() ); + mojoClassVisitor.getMojoAnnotatedClass() );
mojoClassVisitor.getMojoAnnotatedClass().setArtifact( artifact );
mojoAnnotatedClasses.put( mojoClassVisitor.getMojoAnnotatedClass().getClassName(), mojoAnnotatedClasses.put( mojoClassVisitor.getMojoAnnotatedClass().getClassName(),
mojoClassVisitor.getMojoAnnotatedClass() ); mojoClassVisitor.getMojoAnnotatedClass() );
} }

View File

@ -18,6 +18,7 @@ package org.apache.maven.tools.plugin.annotations.scanner;
* under the License. * under the License.
*/ */
import org.apache.maven.artifact.Artifact;
import org.apache.maven.tools.plugin.annotations.datamodel.ComponentAnnotationContent; import org.apache.maven.tools.plugin.annotations.datamodel.ComponentAnnotationContent;
import org.apache.maven.tools.plugin.annotations.datamodel.ExecuteAnnotationContent; import org.apache.maven.tools.plugin.annotations.datamodel.ExecuteAnnotationContent;
import org.apache.maven.tools.plugin.annotations.datamodel.MojoAnnotationContent; import org.apache.maven.tools.plugin.annotations.datamodel.MojoAnnotationContent;
@ -50,6 +51,11 @@ public class MojoAnnotatedClass
*/ */
private Map<String, ComponentAnnotationContent> components; private Map<String, ComponentAnnotationContent> components;
/**
* artifact which contains this annotation
*/
private Artifact artifact;
public MojoAnnotatedClass() public MojoAnnotatedClass()
{ {
// no op // no op
@ -129,6 +135,15 @@ public class MojoAnnotatedClass
return this; return this;
} }
public Artifact getArtifact()
{
return artifact;
}
public void setArtifact( Artifact artifact )
{
this.artifact = artifact;
}
@Override @Override
public String toString() public String toString()

View File

@ -19,6 +19,8 @@ package org.apache.maven.tools.plugin.annotations.scanner;
*/ */
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -41,6 +43,8 @@ public class MojoAnnotationsScannerRequest
private List<File> sourceDirectories = new ArrayList<File>(); private List<File> sourceDirectories = new ArrayList<File>();
private MavenProject project;
public MojoAnnotationsScannerRequest() public MojoAnnotationsScannerRequest()
{ {
// no o // no o
@ -85,4 +89,14 @@ public class MojoAnnotationsScannerRequest
{ {
this.sourceDirectories = sourceDirectories; this.sourceDirectories = sourceDirectories;
} }
public MavenProject getProject()
{
return project;
}
public void setProject( MavenProject project )
{
this.project = project;
}
} }

View File

@ -22,6 +22,7 @@ import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Execute; import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.annotations.datamodel.ComponentAnnotationContent; import org.apache.maven.tools.plugin.annotations.datamodel.ComponentAnnotationContent;
import org.apache.maven.tools.plugin.annotations.datamodel.ParameterAnnotationContent; import org.apache.maven.tools.plugin.annotations.datamodel.ParameterAnnotationContent;
import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotatedClass; import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotatedClass;
@ -50,6 +51,7 @@ public class TestAnnotationsReader
MojoAnnotationsScannerRequest request = new MojoAnnotationsScannerRequest(); MojoAnnotationsScannerRequest request = new MojoAnnotationsScannerRequest();
request.setClassesDirectories( Collections.singletonList( new File( "target/test-classes" ) ) ); request.setClassesDirectories( Collections.singletonList( new File( "target/test-classes" ) ) );
request.setIncludePatterns( Arrays.asList( "**/FooMojo.class" ) ); request.setIncludePatterns( Arrays.asList( "**/FooMojo.class" ) );
request.setProject( new MavenProject( ) );
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses = mojoAnnotationsScanner.scan( request ); Map<String, MojoAnnotatedClass> mojoAnnotatedClasses = mojoAnnotationsScanner.scan( request );