[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
master
Herve Boutemy 2012-05-19 21:53:49 +00:00
parent 0a1066ff87
commit 02b29353d6
7 changed files with 61 additions and 6 deletions

View File

@ -35,7 +35,7 @@ public class CoreIt0013Mojo
{
/**
* @parameter expression="${project.build.directory}"
* @parameter property="project.build.directory"
* @required
*/
private String outputDirectory;

View File

@ -297,9 +297,20 @@ public interface JavaMojoAnnotation
* Refer to <code>&#64;parameter expression="..."</code>.
* <br/>
* <b>Note</b>: 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 <code>-D</code> execution, setting properties or pom properties.
* <br/>
* Refer to <code>&#64;parameter property="..."</code>.
* <br/>
* <b>Note</b>: 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.
* <br/>

View File

@ -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." ) )

View File

@ -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 <since-text>
@ -84,8 +84,8 @@ public class MyMojo
}
+---------+
<<Notice>>: before 3.0, <<<${ }>>> were required for <<<expression>>> value (<<<expression="${aProperty}">>>),
but starting with 3.0, you can omit it (<<<expression="aProperty">>>)
<<Notice>>: before 3.0, <<<property>>> was replaced by <<<expression>>>, with <<<${ }>>> required (<<<expression="${aProperty}">>>),
but starting with 3.0, you can omit it (<<<expression="aProperty">>>), or preferably use <<<property="aProperty">>>.
* See also

View File

@ -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<MojoDescriptor> mojoDescriptors = extractor.execute( request );

View File

@ -63,6 +63,11 @@ public class Full
*/
private File file;
/**
* @parameter property="aSystemProperty"
*/
private String property;
/**
* A component.
*

View File

@ -97,9 +97,17 @@
<editable>true</editable>
<description>A parameter.</description>
</parameter>
<parameter>
<name>property</name>
<type>java.lang.String</type>
<required>false</required>
<editable>true</editable>
<description></description>
</parameter>
</parameters>
<configuration>
<file implementation="java.io.File" default-value="${anExpression}">${aSystemProperty}</file>
<property implementation="java.lang.String">${aSystemProperty}</property>
</configuration>
<requirements>
<requirement>