exclude @Mojo annotation when coming from classes from dependencies

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1335766 13f79535-47bb-0310-9956-ffa450edef68
master
Olivier Lamy 2012-05-08 21:01:28 +00:00
parent 3dd6a922a9
commit 261a3cf86a
4 changed files with 63 additions and 6 deletions

View File

@ -316,6 +316,14 @@
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-tools-annotations</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
</dependency>
</dependencies>
</profile>
</profiles>
</project>

View File

@ -44,6 +44,12 @@ under the License.
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-tools-annotations</artifactId>
<version>@project.version@</version>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>

View File

@ -79,4 +79,20 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -75,12 +75,12 @@ public class DefaultMojoAnnotationsScanner
if ( dependencyFile.isDirectory() )
{
mojoAnnotatedClasses.putAll(
scanDirectory( dependencyFile, request.getIncludePatterns(), dependency ) );
scanDirectory( dependencyFile, request.getIncludePatterns(), dependency, true ) );
}
else
{
mojoAnnotatedClasses.putAll(
scanFile( dependencyFile, request.getIncludePatterns(), dependency ) );
scanFile( dependencyFile, request.getIncludePatterns(), dependency, true ) );
}
}
}
@ -89,8 +89,9 @@ public class DefaultMojoAnnotationsScanner
{
if ( classDirectory.exists() && classDirectory.isDirectory() )
{
mojoAnnotatedClasses.putAll( scanDirectory( classDirectory, request.getIncludePatterns(),
request.getProject().getArtifact() ) );
mojoAnnotatedClasses.putAll(
scanDirectory( classDirectory, request.getIncludePatterns(), request.getProject().getArtifact(),
false ) );
}
}
@ -102,8 +103,17 @@ public class DefaultMojoAnnotationsScanner
}
}
/**
* @param archiveFile
* @param includePatterns
* @param artifact
* @param excludeMojo for dependencies we exclude Mojo annotations found
* @return
* @throws IOException
* @throws ExtractionException
*/
protected Map<String, MojoAnnotatedClass> scanFile( File archiveFile, List<String> includePatterns,
Artifact artifact )
Artifact artifact, boolean excludeMojo )
throws IOException, ExtractionException
{
if ( !archiveFile.exists() )
@ -126,6 +136,10 @@ public class DefaultMojoAnnotationsScanner
rdr.accept( mojoClassVisitor,
ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG );
analyzeVisitors( mojoClassVisitor );
if ( excludeMojo )
{
mojoClassVisitor.getMojoAnnotatedClass().setMojo( null );
}
if ( isMojoAnnnotatedClassCandidate( mojoClassVisitor.getMojoAnnotatedClass() ) != null )
{
getLogger().debug(
@ -145,8 +159,17 @@ public class DefaultMojoAnnotationsScanner
return mojoAnnotatedClasses;
}
/**
* @param classDirectory
* @param includePatterns
* @param artifact
* @param excludeMojo for dependencies we exclude Mojo annotations found
* @return
* @throws IOException
* @throws ExtractionException
*/
protected Map<String, MojoAnnotatedClass> scanDirectory( File classDirectory, List<String> includePatterns,
Artifact artifact )
Artifact artifact, boolean excludeMojo )
throws IOException, ExtractionException
{
if ( !classDirectory.exists() )
@ -177,6 +200,10 @@ public class DefaultMojoAnnotationsScanner
rdr.accept( mojoClassVisitor,
ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG );
analyzeVisitors( mojoClassVisitor );
if ( excludeMojo )
{
mojoClassVisitor.getMojoAnnotatedClass().setMojo( null );
}
if ( isMojoAnnnotatedClassCandidate( mojoClassVisitor.getMojoAnnotatedClass() ) != null )
{
getLogger().debug(