You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2012/05/07 18:15:13 UTC
svn commit: r1335091 - in /maven/plugin-tools/branches/MPLUGIN-189:
maven-plugin-plugin/src/it/annotation-with-inheritance/
maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/
maven-plugin-tools-annotati...
Author: olamy
Date: Mon May 7 16:15:12 2012
New Revision: 1335091
URL: http://svn.apache.org/viewvc?rev=1335091&view=rev
Log:
[MPLUGIN-189] support components field inheritance
Modified:
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml?rev=1335091&r1=1335090&r2=1335091&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml (original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml Mon May 7 16:15:12 2012
@@ -36,6 +36,7 @@ under the License.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <plexusCompilerVersion>1.8.6</plexusCompilerVersion>
</properties>
<dependencies>
@@ -54,6 +55,28 @@ under the License.
<artifactId>maven-plugin-annotations</artifactId>
<version>@project.version@</version>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-compiler-manager</artifactId>
+ <version>${plexusCompilerVersion}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-compiler-javac</artifactId>
+ <version>${plexusCompilerVersion}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
<build>
Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java?rev=1335091&r1=1335090&r2=1335091&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java (original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java Mon May 7 16:15:12 2012
@@ -26,6 +26,8 @@ import org.apache.maven.plugins.annotati
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;
+
}
Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java?rev=1335091&r1=1335090&r2=1335091&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java (original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java Mon May 7 16:15:12 2012
@@ -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" );
}
+
}
}
Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy?rev=1335091&r1=1335090&r2=1335091&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy (original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy Mon May 7 16:15:12 2012
@@ -32,11 +32,11 @@ assert mojo.configuration.touchFile[0].t
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
Modified: maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java?rev=1335091&r1=1335090&r2=1335091&view=diff
==============================================================================
--- maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java (original)
+++ maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java Mon May 7 16:15:12 2012
@@ -357,7 +357,11 @@ public class JavaAnnotationsMojoDescript
mojoDescriptor.addParameter( parameter );
}
- for ( ComponentAnnotationContent componentAnnotationContent : mojoAnnotatedClass.getComponents().values() )
+ Map<String, ComponentAnnotationContent> components =
+ getComponentsParentHierarchy( mojoAnnotatedClass, new HashMap<String, ComponentAnnotationContent>(),
+ 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 JavaAnnotationsMojoDescript
List<ParameterAnnotationContent> parameterAnnotationContents = new ArrayList<ParameterAnnotationContent>();
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 JavaAnnotationsMojoDescript
return map;
}
- protected List<ParameterAnnotationContent> getParent( MojoAnnotatedClass mojoAnnotatedClass,
- List<ParameterAnnotationContent> parameterAnnotationContents,
- Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
+ protected List<ParameterAnnotationContent> getParametersParent( MojoAnnotatedClass mojoAnnotatedClass,
+ List<ParameterAnnotationContent> parameterAnnotationContents,
+ Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
{
parameterAnnotationContents.addAll( mojoAnnotatedClass.getParameters().values() );
String parentClassName = mojoAnnotatedClass.getParentClassName();
@@ -409,9 +413,49 @@ public class JavaAnnotationsMojoDescript
MojoAnnotatedClass parent = mojoAnnotatedClasses.get( parentClassName );
if ( parent != null )
{
- return getParent( parent, parameterAnnotationContents, mojoAnnotatedClasses );
+ return getParametersParent( parent, parameterAnnotationContents, mojoAnnotatedClasses );
}
}
return parameterAnnotationContents;
}
+
+
+ protected Map<String, ComponentAnnotationContent> getComponentsParentHierarchy(
+ MojoAnnotatedClass mojoAnnotatedClass, Map<String, ComponentAnnotationContent> components,
+ Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
+ {
+ List<ComponentAnnotationContent> componentAnnotationContents = new ArrayList<ComponentAnnotationContent>();
+
+ componentAnnotationContents =
+ getComponentParent( mojoAnnotatedClass, componentAnnotationContents, mojoAnnotatedClasses );
+
+ // move to parent first to build the Map
+ Collections.reverse( componentAnnotationContents );
+
+ Map<String, ComponentAnnotationContent> map =
+ new HashMap<String, ComponentAnnotationContent>( componentAnnotationContents.size() );
+
+ for ( ComponentAnnotationContent componentAnnotationContent : componentAnnotationContents )
+ {
+ map.put( componentAnnotationContent.getFieldName(), componentAnnotationContent );
+ }
+ return map;
+ }
+
+ protected List<ComponentAnnotationContent> getComponentParent( MojoAnnotatedClass mojoAnnotatedClass,
+ List<ComponentAnnotationContent> componentAnnotationContents,
+ Map<String, MojoAnnotatedClass> 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;
+ }
}