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-ffa450edef68master
parent
18e8cb4178
commit
3dd6a922a9
|
|
@ -6,6 +6,8 @@ assert descriptorFile.isFile()
|
|||
|
||||
def pluginDescriptor = new XmlParser().parse( descriptorFile );
|
||||
|
||||
assert pluginDescriptor.mojos.mojo.size() == 3
|
||||
|
||||
def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first"}[0]
|
||||
|
||||
assert mojo.goal.text() == 'first'
|
||||
|
|
|
|||
|
|
@ -82,6 +82,8 @@ public class JavaAnnotationsMojoDescriptorExtractor
|
|||
|
||||
mojoAnnotationsScannerRequest.setDependencies( request.getDependencies() );
|
||||
|
||||
mojoAnnotationsScannerRequest.setProject( request.getProject() );
|
||||
|
||||
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses =
|
||||
mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest );
|
||||
|
||||
|
|
|
|||
|
|
@ -18,12 +18,15 @@ package org.apache.maven.tools.plugin.annotations.datamodel;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
* @since 3.0
|
||||
*/
|
||||
public class AnnotatedContent
|
||||
{
|
||||
|
||||
private String description;
|
||||
|
||||
private String since;
|
||||
|
|
@ -59,4 +62,5 @@ public class AnnotatedContent
|
|||
{
|
||||
this.deprecated = deprecated;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,11 +74,13 @@ public class DefaultMojoAnnotationsScanner
|
|||
{
|
||||
if ( dependencyFile.isDirectory() )
|
||||
{
|
||||
mojoAnnotatedClasses.putAll( scanDirectory( dependencyFile, request.getIncludePatterns() ) );
|
||||
mojoAnnotatedClasses.putAll(
|
||||
scanDirectory( dependencyFile, request.getIncludePatterns(), dependency ) );
|
||||
}
|
||||
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() )
|
||||
{
|
||||
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
|
||||
{
|
||||
if ( !archiveFile.exists() )
|
||||
|
|
@ -127,6 +131,7 @@ public class DefaultMojoAnnotationsScanner
|
|||
getLogger().debug(
|
||||
"found MojoAnnotatedClass:" + mojoClassVisitor.getMojoAnnotatedClass().getClassName() + ":"
|
||||
+ mojoClassVisitor.getMojoAnnotatedClass() );
|
||||
mojoClassVisitor.getMojoAnnotatedClass().setArtifact( artifact );
|
||||
mojoAnnotatedClasses.put( mojoClassVisitor.getMojoAnnotatedClass().getClassName(),
|
||||
mojoClassVisitor.getMojoAnnotatedClass() );
|
||||
}
|
||||
|
|
@ -140,7 +145,8 @@ public class DefaultMojoAnnotationsScanner
|
|||
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
|
||||
{
|
||||
if ( !classDirectory.exists() )
|
||||
|
|
@ -176,6 +182,7 @@ public class DefaultMojoAnnotationsScanner
|
|||
getLogger().debug(
|
||||
"found MojoAnnotatedClass:" + mojoClassVisitor.getMojoAnnotatedClass().getClassName() + ":"
|
||||
+ mojoClassVisitor.getMojoAnnotatedClass() );
|
||||
mojoClassVisitor.getMojoAnnotatedClass().setArtifact( artifact );
|
||||
mojoAnnotatedClasses.put( mojoClassVisitor.getMojoAnnotatedClass().getClassName(),
|
||||
mojoClassVisitor.getMojoAnnotatedClass() );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package org.apache.maven.tools.plugin.annotations.scanner;
|
|||
* 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.ExecuteAnnotationContent;
|
||||
import org.apache.maven.tools.plugin.annotations.datamodel.MojoAnnotationContent;
|
||||
|
|
@ -50,6 +51,11 @@ public class MojoAnnotatedClass
|
|||
*/
|
||||
private Map<String, ComponentAnnotationContent> components;
|
||||
|
||||
/**
|
||||
* artifact which contains this annotation
|
||||
*/
|
||||
private Artifact artifact;
|
||||
|
||||
public MojoAnnotatedClass()
|
||||
{
|
||||
// no op
|
||||
|
|
@ -129,6 +135,15 @@ public class MojoAnnotatedClass
|
|||
return this;
|
||||
}
|
||||
|
||||
public Artifact getArtifact()
|
||||
{
|
||||
return artifact;
|
||||
}
|
||||
|
||||
public void setArtifact( Artifact artifact )
|
||||
{
|
||||
this.artifact = artifact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ package org.apache.maven.tools.plugin.annotations.scanner;
|
|||
*/
|
||||
|
||||
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.util.ArrayList;
|
||||
|
|
@ -41,6 +43,8 @@ public class MojoAnnotationsScannerRequest
|
|||
|
||||
private List<File> sourceDirectories = new ArrayList<File>();
|
||||
|
||||
private MavenProject project;
|
||||
|
||||
public MojoAnnotationsScannerRequest()
|
||||
{
|
||||
// no o
|
||||
|
|
@ -85,4 +89,14 @@ public class MojoAnnotationsScannerRequest
|
|||
{
|
||||
this.sourceDirectories = sourceDirectories;
|
||||
}
|
||||
|
||||
public MavenProject getProject()
|
||||
{
|
||||
return project;
|
||||
}
|
||||
|
||||
public void setProject( MavenProject project )
|
||||
{
|
||||
this.project = project;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.apache.maven.plugin.AbstractMojo;
|
|||
import org.apache.maven.plugins.annotations.Execute;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
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.ParameterAnnotationContent;
|
||||
import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotatedClass;
|
||||
|
|
@ -50,6 +51,7 @@ public class TestAnnotationsReader
|
|||
MojoAnnotationsScannerRequest request = new MojoAnnotationsScannerRequest();
|
||||
request.setClassesDirectories( Collections.singletonList( new File( "target/test-classes" ) ) );
|
||||
request.setIncludePatterns( Arrays.asList( "**/FooMojo.class" ) );
|
||||
request.setProject( new MavenProject( ) );
|
||||
|
||||
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses = mojoAnnotationsScanner.scan( request );
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue