diff --git a/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Component.java b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Component.java
index 0339cdf..121041f 100644
--- a/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Component.java
+++ b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Component.java
@@ -42,7 +42,7 @@ public @interface Component
* role of the component to inject.
* @return the role
*/
- String role() default "";
+ Class> role() default Object.class;
/**
* role-hint of the component to inject.
diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
index 491f0c1..3ce0801 100644
--- a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
+++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
@@ -27,6 +27,7 @@ import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.tools.plugin.annotations.FooMojo;
+import org.apache.maven.project.MavenProjectHelper;
/**
* Touches a test file.
@@ -46,7 +47,7 @@ public class FirstMojo
@Parameter( alias = "alias" )
private String aliasedParam;
- @Component( role = "org.apache.maven.project.MavenProjectHelper" )// , roleHint = "default"
+ @Component( role = MavenProjectHelper.class )// , roleHint = "default"
private Object projectHelper;
public void execute()
diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/src/main/java/org/apache/maven/plugins/AbstractFirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/src/main/java/org/apache/maven/plugins/AbstractFirstMojo.java
index 87ad0dc..775e12c 100644
--- a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/src/main/java/org/apache/maven/plugins/AbstractFirstMojo.java
+++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/src/main/java/org/apache/maven/plugins/AbstractFirstMojo.java
@@ -58,7 +58,7 @@ public abstract class AbstractFirstMojo
/**
*
*/
- @Component( role = "org.apache.maven.artifact.metadata.ArtifactMetadataSource", roleHint = "maven" )
+ @Component( role = ArtifactMetadataSource.class, roleHint = "maven" )
protected ArtifactMetadataSource artifactMetadataSource;
}
diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
index 02cf832..b0b40fe 100644
--- a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
+++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
@@ -27,6 +27,7 @@ import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.AbstractFirstMojo;
+import org.apache.maven.project.MavenProjectHelper;
/**
* Touches a test file.
@@ -47,7 +48,7 @@ public class FirstMojo
@Parameter( alias = "alias" )
private String aliasedParam;
- @Component( role = "org.apache.maven.project.MavenProjectHelper" )
+ @Component( role = MavenProjectHelper.class )
private Object projectHelper;
public void execute()
@@ -69,6 +70,10 @@ public class FirstMojo
{
throw new MojoExecutionException( "compilerManager == null" );
}
+ if (! ( projectHelper instanceof MavenProjectHelper ))
+ {
+ throw new MojoExecutionException( "! projectHelper instanceof MavenProjectHelper" );
+ }
}
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 f0a1263..d05639c 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
@@ -58,7 +58,7 @@ public abstract class AbstractFirstMojo
/**
*
*/
- @Component( role = "org.apache.maven.artifact.metadata.ArtifactMetadataSource", roleHint = "maven" )
+ @Component( role = ArtifactMetadataSource.class, 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 15dd982..e88906e 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
@@ -27,6 +27,7 @@ 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.apache.maven.project.MavenProjectHelper;
import java.util.Set;
@@ -50,7 +51,7 @@ public class FirstMojo
@Parameter( alias = "alias" )
private String aliasedParam;
- @Component( role = "org.apache.maven.project.MavenProjectHelper" )//, roleHint = "default"
+ @Component( role = MavenProjectHelper.class )//, roleHint = "default"
private Object projectHelper;
@Parameter( defaultValue = "${project.artifacts}", required = true, readonly = true )
diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml b/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml
index 7f14216..f814d86 100644
--- a/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml
+++ b/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml
@@ -44,11 +44,15 @@ under the License.
maven-plugin-api
2.0
+
+ org.apache.maven
+ maven-project
+ 2.0
+
org.codehaus.plexus
plexus-utils
3.0.1
- provided
org.apache.maven.plugin-tools
diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
index f5814a3..e78a4cd 100644
--- a/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
+++ b/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
@@ -27,6 +27,7 @@ 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.apache.maven.project.MavenProjectHelper;
import java.io.File;
@@ -59,7 +60,7 @@ public class FirstMojo
@Parameter( alias = "alias" )
private String aliasedParam;
- @Component( role = "org.apache.maven.project.MavenProjectHelper", roleHint = "test" )
+ @Component( role = MavenProjectHelper.class, roleHint = "test" )
private Object projectHelper;
public void execute()
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 4413946..8064e47 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
@@ -525,8 +525,9 @@ public class JavaAnnotationsMojoDescriptorExtractor
if ( StringUtils.contains( property, '$' ) || StringUtils.contains( property, '{' )
|| StringUtils.contains( property, '}' ) )
{
- throw new InvalidParameterException( "Invalid property for parameter '" + parameter.getName() + "', "
- + "forbidden characters ${}: " + property, null );
+ throw new InvalidParameterException(
+ "Invalid property for parameter '" + parameter.getName() + "', " + "forbidden characters ${}: "
+ + property, null );
}
parameter.setExpression( StringUtils.isEmpty( property ) ? "" : "${" + property + "}" );
parameter.setType( parameterAnnotationContent.getClassName() );
@@ -546,8 +547,8 @@ public class JavaAnnotationsMojoDescriptorExtractor
org.apache.maven.plugin.descriptor.Parameter parameter =
new org.apache.maven.plugin.descriptor.Parameter();
parameter.setName( componentAnnotationContent.getFieldName() );
- parameter.setRequirement(
- new Requirement( componentAnnotationContent.role(), componentAnnotationContent.roleHint() ) );
+ parameter.setRequirement( new Requirement( componentAnnotationContent.getRoleClassName(),
+ componentAnnotationContent.roleHint() ) );
parameter.setDeprecated( componentAnnotationContent.getDeprecated() );
parameter.setSince( componentAnnotationContent.getSince() );
@@ -671,8 +672,8 @@ public class JavaAnnotationsMojoDescriptorExtractor
{
return null;
}
- @SuppressWarnings( "unchecked" )
- Collection mavenProjects = project.getProjectReferences().values();
+ @SuppressWarnings( "unchecked" ) Collection mavenProjects =
+ project.getProjectReferences().values();
for ( MavenProject mavenProject : mavenProjects )
{
if ( StringUtils.equals( mavenProject.getId(), artifact.getId() ) )
diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java
index b649a3b..e2e069d 100644
--- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java
+++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java
@@ -31,7 +31,7 @@ public class ComponentAnnotationContent
extends AnnotatedField
implements Component
{
- private String role;
+ private String roleClassName;
private String roleHint;
@@ -43,18 +43,24 @@ public class ComponentAnnotationContent
public ComponentAnnotationContent( String fieldName, String role, String roleHint )
{
this( fieldName );
- this.role = role;
+ this.roleClassName = role;
this.roleHint = roleHint;
}
- public String role()
+ public Class> role()
{
- return role == null ? "" : role;
+ // not used
+ return null;
}
- public void role( String role )
+ public void setRoleClassName( String roleClassName )
{
- this.role = role;
+ this.roleClassName = roleClassName;
+ }
+
+ public String getRoleClassName()
+ {
+ return roleClassName;
}
public String roleHint()
@@ -78,7 +84,7 @@ public class ComponentAnnotationContent
final StringBuilder sb = new StringBuilder();
sb.append( super.toString() );
sb.append( "ComponentAnnotationContent" );
- sb.append( "{role='" ).append( role ).append( '\'' );
+ sb.append( "{role='" ).append( roleClassName ).append( '\'' );
sb.append( ", roleHint='" ).append( roleHint ).append( '\'' );
sb.append( '}' );
return sb.toString();
diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java
index fb1daef..67d737f 100644
--- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java
+++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java
@@ -38,6 +38,7 @@ import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.reflection.Reflector;
import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.Type;
import java.io.BufferedInputStream;
import java.io.File;
@@ -302,12 +303,21 @@ public class DefaultMojoAnnotationsScanner
{
for ( Map.Entry entry : mojoFieldVisitor.getMojoAnnotationVisitor().getAnnotationValues().entrySet() )
{
- reflector.invoke( componentAnnotationContent, entry.getKey(),
- new Object[]{ entry.getValue() } );
+ String methodName = entry.getKey();
+ if ( StringUtils.equals( "role", methodName ) )
+ {
+ Type type = (Type) entry.getValue();
+ componentAnnotationContent.setRoleClassName( type.getClassName() );
+ }
+ else
+ {
+ reflector.invoke( componentAnnotationContent, entry.getKey(),
+ new Object[]{ entry.getValue() } );
+ }
}
- if ( StringUtils.isEmpty( componentAnnotationContent.role() ) )
+ if ( StringUtils.isEmpty( componentAnnotationContent.getRoleClassName() ) )
{
- componentAnnotationContent.role( mojoFieldVisitor.getClassName() );
+ componentAnnotationContent.setRoleClassName( mojoFieldVisitor.getClassName() );
}
}
mojoClassVisitor.getMojoAnnotatedClass().getComponents().put( componentAnnotationContent.getFieldName(),
diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java
index 15b0add..a559325 100644
--- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java
+++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java
@@ -61,7 +61,7 @@ public class FooMojo
/**
*
*/
- @Component( role = "org.apache.maven.artifact.metadata.ArtifactMetadataSource", roleHint = "maven" )
+ @Component( role = ArtifactMetadataSource.class, roleHint = "maven" )
protected ArtifactMetadataSource artifactMetadataSource;
public void execute()