From 02b29353d613e64a3471e0d5a758bbdbbcd05a73 Mon Sep 17 00:00:00 2001 From: Herve Boutemy Date: Sat, 19 May 2012 21:53:49 +0000 Subject: [PATCH] [MPLUGIN-196] added property support to javadoc tags in addition to expression, deprecating expression git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1340574 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/plugin/coreit/CoreIt0013Mojo.java | 2 +- .../extractor/java/JavaMojoAnnotation.java | 11 +++++++ .../java/JavaMojoDescriptorExtractor.java | 29 +++++++++++++++++++ .../src/site/apt/index.apt | 6 ++-- .../java/JavaMojoDescriptorExtractorTest.java | 6 ++-- .../src/test/resources/source/Full.java | 5 ++++ .../test/resources/source/plugin-expected.xml | 8 +++++ 7 files changed, 61 insertions(+), 6 deletions(-) diff --git a/maven-plugin-plugin/src/it/java-basic/src/main/java/org/apache/maven/plugin/coreit/CoreIt0013Mojo.java b/maven-plugin-plugin/src/it/java-basic/src/main/java/org/apache/maven/plugin/coreit/CoreIt0013Mojo.java index 69354f6..824f043 100644 --- a/maven-plugin-plugin/src/it/java-basic/src/main/java/org/apache/maven/plugin/coreit/CoreIt0013Mojo.java +++ b/maven-plugin-plugin/src/it/java-basic/src/main/java/org/apache/maven/plugin/coreit/CoreIt0013Mojo.java @@ -35,7 +35,7 @@ public class CoreIt0013Mojo { /** - * @parameter expression="${project.build.directory}" + * @parameter property="project.build.directory" * @required */ private String outputDirectory; diff --git a/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoAnnotation.java b/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoAnnotation.java index baff8b8..4c1503b 100644 --- a/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoAnnotation.java +++ b/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoAnnotation.java @@ -297,9 +297,20 @@ public interface JavaMojoAnnotation * Refer to @parameter expression="...". *
* Note: Should be defined in a Mojo Field. + * @deprecated use PARAMETER_PROPERTY instead */ String PARAMETER_EXPRESSION = "expression"; + /** + * This defines the property used to calculate the value to be injected into this parameter of the + * Mojo at build time, which can come from -D execution, setting properties or pom properties. + *
+ * Refer to @parameter property="...". + *
+ * Note: Should be defined in a Mojo Field. + */ + String PARAMETER_PROPERTY = "property"; + /** * This defines the default implementation in the case the parameter type is an interface. *
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 8f69937..79fb26e 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 @@ -549,6 +549,35 @@ public class JavaMojoDescriptorExtractor } String expression = parameter.getNamedParameter( JavaMojoAnnotation.PARAMETER_EXPRESSION ); + String property = parameter.getNamedParameter( JavaMojoAnnotation.PARAMETER_PROPERTY ); + + if ( StringUtils.isNotEmpty( expression ) && StringUtils.isNotEmpty( property ) ) + { + getLogger().error( javaClass.getFullyQualifiedName() + "#" + field.getName() + ":" ); + getLogger().error( " Cannot use both:" ); + getLogger().error( " @parameter expression=\"${property}\"" ); + getLogger().error( " and" ); + getLogger().error( " @parameter property=\"property\"" ); + getLogger().error( " Second syntax is preferred." ); + throw new InvalidParameterException( javaClass.getFullyQualifiedName() + "#" + field.getName() + + ": cannot" + " use both @parameter expression and property", null ); + } + + if ( StringUtils.isNotEmpty( expression ) ) + { + getLogger().warn( javaClass.getFullyQualifiedName() + "#" + field.getName() + ":" ); + getLogger().warn( " The syntax" ); + getLogger().warn( " @parameter expression=\"${property}\"" ); + getLogger().warn( " is deprecated, please use" ); + getLogger().warn( " @parameter property=\"property\"" ); + getLogger().warn( " instead." ); + + } + else if ( StringUtils.isNotEmpty( property ) ) + { + expression = "${" + property + "}"; + } + pd.setExpression( expression ); if ( StringUtils.isNotEmpty( expression ) && expression.startsWith( "${component." ) ) diff --git a/maven-plugin-tools-java/src/site/apt/index.apt b/maven-plugin-tools-java/src/site/apt/index.apt index c8512a0..9094c91 100644 --- a/maven-plugin-tools-java/src/site/apt/index.apt +++ b/maven-plugin-tools-java/src/site/apt/index.apt @@ -62,7 +62,7 @@ public class MyMojo extends AbstractMojo { /** - * @parameter alias="myAlias" implementation="" expression="aProperty" default-value="${anExpression}" + * @parameter alias="myAlias" implementation="" property="aProperty" default-value="${anExpression}" * @readonly * @required * @since @@ -84,8 +84,8 @@ public class MyMojo } +---------+ - <>: before 3.0, <<<${ }>>> were required for <<>> value (<<>>), - but starting with 3.0, you can omit it (<<>>) + <>: before 3.0, <<>> was replaced by <<>>, with <<<${ }>>> required (<<>>), + but starting with 3.0, you can omit it (<<>>), or preferably use <<>>. * See also diff --git a/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java b/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java index 77b2359..a30b1e7 100644 --- a/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java +++ b/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java @@ -29,11 +29,12 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; import org.apache.maven.tools.plugin.ExtendedMojoDescriptor; import org.apache.maven.tools.plugin.PluginToolsRequest; -import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor; import org.apache.maven.tools.plugin.generator.Generator; import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator; import org.apache.maven.tools.plugin.util.PluginUtils; import org.codehaus.plexus.component.repository.ComponentDependency; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.logging.console.ConsoleLogger; import org.codehaus.plexus.util.FileUtils; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; @@ -102,7 +103,8 @@ public class JavaMojoDescriptorExtractorTest protected PluginDescriptor generate( String directory ) throws Exception { - MojoDescriptorExtractor extractor = new JavaMojoDescriptorExtractor(); + JavaMojoDescriptorExtractor extractor = new JavaMojoDescriptorExtractor(); + extractor.enableLogging( new ConsoleLogger( Logger.LEVEL_INFO, "test" ) ); PluginToolsRequest request = createRequest( directory ); List mojoDescriptors = extractor.execute( request ); diff --git a/maven-plugin-tools-java/src/test/resources/source/Full.java b/maven-plugin-tools-java/src/test/resources/source/Full.java index 05a29de..07c57d4 100644 --- a/maven-plugin-tools-java/src/test/resources/source/Full.java +++ b/maven-plugin-tools-java/src/test/resources/source/Full.java @@ -63,6 +63,11 @@ public class Full */ private File file; + /** + * @parameter property="aSystemProperty" + */ + private String property; + /** * A component. * diff --git a/maven-plugin-tools-java/src/test/resources/source/plugin-expected.xml b/maven-plugin-tools-java/src/test/resources/source/plugin-expected.xml index 8fcf538..4983fe8 100644 --- a/maven-plugin-tools-java/src/test/resources/source/plugin-expected.xml +++ b/maven-plugin-tools-java/src/test/resources/source/plugin-expected.xml @@ -97,9 +97,17 @@ true A parameter. + + property + java.lang.String + false + true + + ${aSystemProperty} + ${aSystemProperty}