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-ffa450edef68master
parent
3dd6a922a9
commit
261a3cf86a
|
|
@ -316,6 +316,14 @@
|
||||||
</plugins>
|
</plugins>
|
||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
</build>
|
</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>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,12 @@ under the License.
|
||||||
<artifactId>maven-plugin-api</artifactId>
|
<artifactId>maven-plugin-api</artifactId>
|
||||||
<version>2.0</version>
|
<version>2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||||
|
<artifactId>maven-plugin-tools-annotations</artifactId>
|
||||||
|
<version>@project.version@</version>
|
||||||
|
<classifier>tests</classifier>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
<artifactId>maven-project</artifactId>
|
<artifactId>maven-project</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -79,4 +79,20 @@
|
||||||
|
|
||||||
</dependencies>
|
</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>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -75,12 +75,12 @@ public class DefaultMojoAnnotationsScanner
|
||||||
if ( dependencyFile.isDirectory() )
|
if ( dependencyFile.isDirectory() )
|
||||||
{
|
{
|
||||||
mojoAnnotatedClasses.putAll(
|
mojoAnnotatedClasses.putAll(
|
||||||
scanDirectory( dependencyFile, request.getIncludePatterns(), dependency ) );
|
scanDirectory( dependencyFile, request.getIncludePatterns(), dependency, true ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mojoAnnotatedClasses.putAll(
|
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() )
|
if ( classDirectory.exists() && classDirectory.isDirectory() )
|
||||||
{
|
{
|
||||||
mojoAnnotatedClasses.putAll( scanDirectory( classDirectory, request.getIncludePatterns(),
|
mojoAnnotatedClasses.putAll(
|
||||||
request.getProject().getArtifact() ) );
|
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,
|
protected Map<String, MojoAnnotatedClass> scanFile( File archiveFile, List<String> includePatterns,
|
||||||
Artifact artifact )
|
Artifact artifact, boolean excludeMojo )
|
||||||
throws IOException, ExtractionException
|
throws IOException, ExtractionException
|
||||||
{
|
{
|
||||||
if ( !archiveFile.exists() )
|
if ( !archiveFile.exists() )
|
||||||
|
|
@ -126,6 +136,10 @@ public class DefaultMojoAnnotationsScanner
|
||||||
rdr.accept( mojoClassVisitor,
|
rdr.accept( mojoClassVisitor,
|
||||||
ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG );
|
ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG );
|
||||||
analyzeVisitors( mojoClassVisitor );
|
analyzeVisitors( mojoClassVisitor );
|
||||||
|
if ( excludeMojo )
|
||||||
|
{
|
||||||
|
mojoClassVisitor.getMojoAnnotatedClass().setMojo( null );
|
||||||
|
}
|
||||||
if ( isMojoAnnnotatedClassCandidate( mojoClassVisitor.getMojoAnnotatedClass() ) != null )
|
if ( isMojoAnnnotatedClassCandidate( mojoClassVisitor.getMojoAnnotatedClass() ) != null )
|
||||||
{
|
{
|
||||||
getLogger().debug(
|
getLogger().debug(
|
||||||
|
|
@ -145,8 +159,17 @@ public class DefaultMojoAnnotationsScanner
|
||||||
return mojoAnnotatedClasses;
|
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,
|
protected Map<String, MojoAnnotatedClass> scanDirectory( File classDirectory, List<String> includePatterns,
|
||||||
Artifact artifact )
|
Artifact artifact, boolean excludeMojo )
|
||||||
throws IOException, ExtractionException
|
throws IOException, ExtractionException
|
||||||
{
|
{
|
||||||
if ( !classDirectory.exists() )
|
if ( !classDirectory.exists() )
|
||||||
|
|
@ -177,6 +200,10 @@ public class DefaultMojoAnnotationsScanner
|
||||||
rdr.accept( mojoClassVisitor,
|
rdr.accept( mojoClassVisitor,
|
||||||
ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG );
|
ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG );
|
||||||
analyzeVisitors( mojoClassVisitor );
|
analyzeVisitors( mojoClassVisitor );
|
||||||
|
if ( excludeMojo )
|
||||||
|
{
|
||||||
|
mojoClassVisitor.getMojoAnnotatedClass().setMojo( null );
|
||||||
|
}
|
||||||
if ( isMojoAnnnotatedClassCandidate( mojoClassVisitor.getMojoAnnotatedClass() ) != null )
|
if ( isMojoAnnnotatedClassCandidate( mojoClassVisitor.getMojoAnnotatedClass() ) != null )
|
||||||
{
|
{
|
||||||
getLogger().debug(
|
getLogger().debug(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue