diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml index d14442c..5db6488 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml @@ -36,6 +36,7 @@ under the License. UTF-8 + 1.8.6 @@ -54,6 +55,28 @@ under the License. maven-plugin-annotations @project.version@ + + org.codehaus.plexus + plexus-compiler-manager + ${plexusCompilerVersion} + + + org.codehaus.plexus + plexus-component-api + + + + + org.codehaus.plexus + plexus-compiler-javac + ${plexusCompilerVersion} + + + org.codehaus.plexus + plexus-component-api + + + diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java index 89545f9..cdcc6a6 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java @@ -26,6 +26,8 @@ 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.plugins.annotations.Parameter; +import org.codehaus.plexus.compiler.manager.CompilerManager; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import java.io.File; @@ -47,6 +49,18 @@ public abstract class AbstractFirstMojo required = true ) protected File touchFile; + /** + * Plexus compiler manager. + */ + @Component(role = "org.codehaus.plexus.compiler.manager.CompilerManager") + protected CompilerManager compilerManager; + + /** + * + */ + @Component(role = "org.apache.maven.artifact.metadata.ArtifactMetadataSource", roleHint = "maven") + protected ArtifactMetadataSource artifactMetadataSource; + } diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java index dde40db..ec56ff6 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java @@ -51,14 +51,23 @@ public class FirstMojo public void execute() throws MojoExecutionException { + if (basedir == null) + { + throw new MojoExecutionException( "basedir == null" ); + } + if (touchFile == null) + { + throw new MojoExecutionException( "touchFile == null" ); + } if ( projectHelper == null ) { throw new MojoExecutionException( "projectHelper == null" ); } - if (basedir == null || touchFile == null) + if ( compilerManager == null ) { - throw new MojoExecutionException( "basedir == null || touchFile == null" ); + throw new MojoExecutionException( "compilerManager == null" ); } + } } diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy index 32a3d3b..6c0a341 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy @@ -32,11 +32,11 @@ assert mojo.configuration.touchFile[0].text() == '${first.touchFile}' assert mojo.configuration.touchFile[0].'@implementation' == 'java.io.File' assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.directory}/touch.txt' -assert mojo.requirements.requirement.size() == 1 +assert mojo.requirements.requirement.size() == 3 -assert mojo.requirements.requirement[0].role.text() == 'org.apache.maven.project.MavenProjectHelper' -assert mojo.requirements.requirement[0].'role-hint'.text() == 'default' -assert mojo.requirements.requirement[0].'field-name'.text() == 'projectHelper' +assert mojo.requirements.requirement[1].role.text() == 'org.apache.maven.project.MavenProjectHelper' +assert mojo.requirements.requirement[1].'role-hint'.text() == 'default' +assert mojo.requirements.requirement[1].'field-name'.text() == 'projectHelper' assert mojo.parameters.parameter.size() == 3 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 b81ab5c..8b3b17a 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 @@ -357,7 +357,11 @@ public class JavaAnnotationsMojoDescriptorExtractor mojoDescriptor.addParameter( parameter ); } - for ( ComponentAnnotationContent componentAnnotationContent : mojoAnnotatedClass.getComponents().values() ) + Map components = + getComponentsParentHierarchy( mojoAnnotatedClass, new HashMap(), + mojoAnnotatedClasses ); + + for ( ComponentAnnotationContent componentAnnotationContent : components.values() ) { org.apache.maven.plugin.descriptor.Parameter parameter = new org.apache.maven.plugin.descriptor.Parameter(); @@ -383,7 +387,7 @@ public class JavaAnnotationsMojoDescriptorExtractor List parameterAnnotationContents = new ArrayList(); parameterAnnotationContents = - getParent( mojoAnnotatedClass, parameterAnnotationContents, mojoAnnotatedClasses ); + getParametersParent( mojoAnnotatedClass, parameterAnnotationContents, mojoAnnotatedClasses ); // move to parent first to build the Map Collections.reverse( parameterAnnotationContents ); @@ -398,9 +402,9 @@ public class JavaAnnotationsMojoDescriptorExtractor return map; } - protected List getParent( MojoAnnotatedClass mojoAnnotatedClass, - List parameterAnnotationContents, - Map mojoAnnotatedClasses ) + protected List getParametersParent( MojoAnnotatedClass mojoAnnotatedClass, + List parameterAnnotationContents, + Map mojoAnnotatedClasses ) { parameterAnnotationContents.addAll( mojoAnnotatedClass.getParameters().values() ); String parentClassName = mojoAnnotatedClass.getParentClassName(); @@ -409,9 +413,49 @@ public class JavaAnnotationsMojoDescriptorExtractor MojoAnnotatedClass parent = mojoAnnotatedClasses.get( parentClassName ); if ( parent != null ) { - return getParent( parent, parameterAnnotationContents, mojoAnnotatedClasses ); + return getParametersParent( parent, parameterAnnotationContents, mojoAnnotatedClasses ); } } return parameterAnnotationContents; } + + + protected Map getComponentsParentHierarchy( + MojoAnnotatedClass mojoAnnotatedClass, Map components, + Map mojoAnnotatedClasses ) + { + List componentAnnotationContents = new ArrayList(); + + componentAnnotationContents = + getComponentParent( mojoAnnotatedClass, componentAnnotationContents, mojoAnnotatedClasses ); + + // move to parent first to build the Map + Collections.reverse( componentAnnotationContents ); + + Map map = + new HashMap( componentAnnotationContents.size() ); + + for ( ComponentAnnotationContent componentAnnotationContent : componentAnnotationContents ) + { + map.put( componentAnnotationContent.getFieldName(), componentAnnotationContent ); + } + return map; + } + + protected List getComponentParent( MojoAnnotatedClass mojoAnnotatedClass, + List componentAnnotationContents, + Map mojoAnnotatedClasses ) + { + componentAnnotationContents.addAll( mojoAnnotatedClass.getComponents().values() ); + String parentClassName = mojoAnnotatedClass.getParentClassName(); + if ( parentClassName != null ) + { + MojoAnnotatedClass parent = mojoAnnotatedClasses.get( parentClassName ); + if ( parent != null ) + { + return getComponentParent( parent, componentAnnotationContents, mojoAnnotatedClasses ); + } + } + return componentAnnotationContents; + } }