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 e228674..9afbd65 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 @@ -29,15 +29,7 @@ import java.lang.annotation.Target; /** * Used to configure injection of Plexus components by * - * MavenPluginManager.getConfiguredMojo(...) and special Maven - * objects as well: - *
- *
mojoExecution
org.apache.maven.plugin.MojoExecution
- *
project
org.apache.maven.project.MavenProject
- *
session
org.apache.maven.execution.MavenSession
- *
settings
org.apache.maven.settings.Settings
- *
plugin (Maven-3 only)
org.apache.maven.plugin.descriptor.PluginDescriptor
- *
+ * MavenPluginManager.getConfiguredMojo(...). * * @author Olivier Lamy * @since 3.0 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 6cf6689..f934abe 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 @@ -588,7 +588,10 @@ public class JavaAnnotationsMojoDescriptorExtractor } else { - // not a component but a Maven object to be transformed into an expression/property + // not a component but a Maven object to be transformed into an expression/property: deprecated + getLogger().warn( "Deprecated @component for " + parameter.getName() + " field in " + + mojoAnnotatedClass.getClassName() + "." + + ": replace with @parameter name=\"" + expression + "\" @readonly" ); parameter.setDefaultValue( expression ); parameter.setType( componentAnnotationContent.getRoleClassName() ); parameter.setRequired( true ); diff --git a/maven-plugin-tools-annotations/src/site/apt/index.apt b/maven-plugin-tools-annotations/src/site/apt/index.apt index 7965152..558f34b 100644 --- a/maven-plugin-tools-annotations/src/site/apt/index.apt +++ b/maven-plugin-tools-annotations/src/site/apt/index.apt @@ -89,22 +89,23 @@ public class MyMojo hint = "..." ) private MyComponent component; - @Component + // sample objects taken from Maven API through PluginParameterExpressionEvaluator + + @Parameter( defaultValue = "${session}", readonly = true ) private MavenSession session; - @Component + @Parameter( defaultValue = "${project}", readonly = true ) private MavenProject project; - @Component + @Parameter( defaultValue = "${mojoExecution}", readonly = true ) private MojoExecution mojo; - @Component // for Maven 3 only + @Parameter( defaultValue = "${plugin}", readonly = true ) // Maven 3 only private PluginDescriptor plugin; - @Component + @Parameter( defaultValue = "${settings}", readonly = true ) private Settings settings; - // sample objects taken from Maven API through PluginParameterExpressionEvaluator @Parameter( defaultValue = "${project.basedir}", readonly = true ) private File basedir; diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java index 8639a11..d2206dc 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java @@ -45,10 +45,12 @@ public final class PluginUtils } /** - * Expression associated with class types to recognize Maven objects (injected in fact as parameters by - * - * maven-core's PluginParameterExpressionEvaluator) - * like components ("real" components are injected by Plexus). + * Expression associated with class types to recognize Maven objects (injected in fact as parameters by + * maven-core's PluginParameterExpressionEvaluator) like components ("real" components are injected by Plexus). + * + * @deprecated wrong approach (fake components), documented parameter default values instead to learn people how to + * discover them */ public static final Map MAVEN_COMPONENTS; static diff --git a/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java b/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java index e2a0e1d..8ba399e 100644 --- a/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java +++ b/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java @@ -540,6 +540,9 @@ public class JavaMojoDescriptorExtractor else { // not a component but a Maven object to be transformed into an expression/property + getLogger().warn( "Deprecated @Component for " + pd.getName() + " field in " + + javaClass.getFullyQualifiedName() + ": replace with @Parameter( name = \"" + + expression + "\", readonly = true )" ); pd.setDefaultValue( expression ); pd.setType( role ); pd.setRequired( true ); diff --git a/maven-plugin-tools-java/src/site/apt/index.apt b/maven-plugin-tools-java/src/site/apt/index.apt index 86f1abe..d3ec226 100644 --- a/maven-plugin-tools-java/src/site/apt/index.apt +++ b/maven-plugin-tools-java/src/site/apt/index.apt @@ -80,32 +80,38 @@ public class MyMojo */ private Component component; + // sample objects taken from Maven API through PluginParameterExpressionEvaluator + /** - * @component + * @parameter default-value="${session}" + * @readonly */ private MavenSession session; /** - * @component + * @parameter default-value="${project}" + * @readonly */ private MavenProject project; /** - * @component + * @parameter default-value="${mojoExecution}" + * @readonly */ private MojoExecution mojo; /** - * @component + * @parameter default-value="${plugin}" // Maven 3 only + * @readonly */ private PluginDescriptor plugin; /** - * @component + * @parameter default-value="${settings}" + * @readonly */ private Settings settings; - // sample objects taken from Maven API through PluginParameterExpressionEvaluator /** * @parameter default-value="${project.basedir}" * @readonly