[MPLUGIN-196] rename expression attribute of parameter to property for Java 5 annotation

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1339888 13f79535-47bb-0310-9956-ffa450edef68
master
Herve Boutemy 2012-05-17 22:20:31 +00:00
parent 53dfd41c54
commit 092e4267b0
13 changed files with 37 additions and 33 deletions

View File

@ -48,7 +48,7 @@ public @interface Parameter
* Property to use to retrieve a value. Can come from <code>-D</code> execution, setting properties or pom properties.
* @return property name
*/
String expression() default "";
String property() default "";
/**
* parameter default value, eventually containing <code>${...}</code> expressions which will be interpreted at inject time.

View File

@ -45,7 +45,7 @@ public abstract class AbstractFirstMojo
@Parameter( defaultValue = "${basedir}", readonly = true )
protected File basedir;
@Parameter( expression = "${first.touchFile}", defaultValue = "${project.build.directory}/touch.txt",
@Parameter( property = "first.touchFile", defaultValue = "${project.build.directory}/touch.txt",
required = true )
protected File touchFile;
@ -61,6 +61,4 @@ public abstract class AbstractFirstMojo
@Component( role = "org.apache.maven.artifact.metadata.ArtifactMetadataSource", roleHint = "maven" )
protected ArtifactMetadataSource artifactMetadataSource;
}

View File

@ -36,7 +36,7 @@ public class CoreIt0014Mojo
extends AbstractMojo
{
@Parameter( expression = "${project.build.directory}", required = true )
@Parameter( property = "project.build.directory", required = true )
private String outputDirectory;
public void execute()

View File

@ -45,7 +45,7 @@ public abstract class AbstractFirstMojo
@Parameter( defaultValue = "${basedir}", readonly = true )
protected File basedir;
@Parameter( expression = "${first.touchFile}", defaultValue = "${project.build.directory}/touch.txt",
@Parameter( property = "first.touchFile", defaultValue = "${project.build.directory}/touch.txt",
required = true )
protected File touchFile;
@ -58,9 +58,7 @@ public abstract class AbstractFirstMojo
/**
*
*/
@Component(role = "org.apache.maven.artifact.metadata.ArtifactMetadataSource", roleHint = "maven")
@Component( role = "org.apache.maven.artifact.metadata.ArtifactMetadataSource", roleHint = "maven" )
protected ArtifactMetadataSource artifactMetadataSource;
}

View File

@ -36,7 +36,7 @@ public class CoreIt0014Mojo
extends AbstractMojo
{
@Parameter( expression = "${project.build.directory}", required = true )
@Parameter( property = "project.build.directory", required = true )
private String outputDirectory;
public void execute()

View File

@ -36,7 +36,7 @@ public class CoreIt0014Mojo
extends AbstractMojo
{
@Parameter( expression = "${project.build.directory}", required = true )
@Parameter( property = "project.build.directory", required = true )
private String outputDirectory;
public void execute()

View File

@ -48,7 +48,7 @@ public class FirstMojo
@Parameter( defaultValue = "${basedir}", readonly = true )
private File basedir;
@Parameter( expression = "first.touchFile", defaultValue = "${project.build.directory}/touch.txt",
@Parameter( property = "first.touchFile", defaultValue = "${project.build.directory}/touch.txt",
required = true )
private File touchFile;

View File

@ -58,7 +58,7 @@ public class DummyReport
/**
* The Maven Project.
*/
@Parameter( expression = "${project}", readonly = true, required = true )
@Parameter( property = "project", readonly = true, required = true )
private MavenProject project;
@ -67,7 +67,7 @@ public class DummyReport
*
* @since 2.4
*/
@Parameter( expression = "${goalPrefix}" )
@Parameter( property = "goalPrefix" )
protected String goalPrefix;
/**
@ -75,7 +75,7 @@ public class DummyReport
*
* @since 2.8
*/
@Parameter( defaultValue = "false", expression = "${maven.plugin.skip}" )
@Parameter( defaultValue = "false", property = "maven.plugin.skip" )
private boolean skip;
/**
@ -83,7 +83,7 @@ public class DummyReport
*
* @since 2.8
*/
@Parameter( defaultValue = "false", expression = "${maven.plugin.report.skip}" )
@Parameter( defaultValue = "false", property = "maven.plugin.report.skip" )
private boolean skipReport;
/**

View File

@ -54,7 +54,7 @@ public class MyMojo
* @deprecated Just testing.
*/
@SuppressWarnings( "unused" )
@Parameter( expression = "${string}", defaultValue = "${project.version}/</markup-must-be-escaped>" )
@Parameter( property = "string", defaultValue = "${project.version}/</markup-must-be-escaped>" )
private String string;
public void execute()

View File

@ -29,6 +29,7 @@ import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.descriptor.DuplicateParameterException;
import org.apache.maven.plugin.descriptor.InvalidParameterException;
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
@ -426,7 +427,7 @@ public class JavaAnnotationsMojoDescriptorExtractor
private List<MojoDescriptor> toMojoDescriptors( Map<String, MojoAnnotatedClass> mojoAnnotatedClasses,
PluginToolsRequest request, Map<String, JavaClass> javaClassesMap )
throws DuplicateParameterException
throws DuplicateParameterException, InvalidParameterException
{
List<MojoDescriptor> mojoDescriptors = new ArrayList<MojoDescriptor>( mojoAnnotatedClasses.size() );
for ( MojoAnnotatedClass mojoAnnotatedClass : mojoAnnotatedClasses.values() )
@ -490,7 +491,14 @@ public class JavaAnnotationsMojoDescriptorExtractor
parameter.setDeprecated( parameterAnnotationContent.getDeprecated() );
parameter.setDescription( parameterAnnotationContent.getDescription() );
parameter.setEditable( !parameterAnnotationContent.readonly() );
parameter.setExpression( parameterAnnotationContent.expression() );
String property = parameterAnnotationContent.property();
if ( StringUtils.contains( property, '$' ) || StringUtils.contains( property, '{' )
|| StringUtils.contains( property, '}' ) )
{
throw new InvalidParameterException( "Invalid property for parameter '" + parameter.getName() + "', "
+ "forbidden characters ${}: " + property, null );
}
parameter.setExpression( StringUtils.isEmpty( property ) ? "" : "${" + property + "}" );
parameter.setType( parameterAnnotationContent.getClassName() );
parameter.setSince( parameterAnnotationContent.getSince() );
parameter.setRequired( parameterAnnotationContent.required() );

View File

@ -34,7 +34,7 @@ public class ParameterAnnotationContent
private String alias;
private String expression;
private String property;
private String defaultValue;
@ -50,12 +50,12 @@ public class ParameterAnnotationContent
this.className = className;
}
public ParameterAnnotationContent( String fieldName, String alias, String expression, String defaultValue,
public ParameterAnnotationContent( String fieldName, String alias, String property, String defaultValue,
boolean required, boolean readonly, String className )
{
this( fieldName, className );
this.alias = alias;
this.expression = expression;
this.property = property;
this.defaultValue = defaultValue;
this.required = required;
this.readonly = readonly;
@ -71,14 +71,14 @@ public class ParameterAnnotationContent
this.alias = alias;
}
public String expression()
public String property()
{
return expression;
return property;
}
public void expression( String expression )
public void property( String property )
{
this.expression = expression;
this.property = property;
}
public String defaultValue()
@ -133,7 +133,7 @@ public class ParameterAnnotationContent
sb.append( super.toString() );
sb.append( "ParameterAnnotationContent" );
sb.append( "{alias='" ).append( alias ).append( '\'' );
sb.append( ", expression='" ).append( expression ).append( '\'' );
sb.append( ", property='" ).append( property ).append( '\'' );
sb.append( ", defaultValue='" ).append( defaultValue ).append( '\'' );
sb.append( ", required=" ).append( required );
sb.append( ", readonly=" ).append( readonly );
@ -177,7 +177,7 @@ public class ParameterAnnotationContent
{
return false;
}
if ( expression != null ? !expression.equals( that.expression ) : that.expression != null )
if ( property != null ? !property.equals( that.property ) : that.property != null )
{
return false;
}
@ -190,7 +190,7 @@ public class ParameterAnnotationContent
{
int result = alias != null ? alias.hashCode() : 0;
result = 31 * result + ( getFieldName() != null ? getFieldName().hashCode() : 0 );
result = 31 * result + ( expression != null ? expression.hashCode() : 0 );
result = 31 * result + ( property != null ? property.hashCode() : 0 );
result = 31 * result + ( defaultValue != null ? defaultValue.hashCode() : 0 );
result = 31 * result + ( required ? 1 : 0 );
result = 31 * result + ( readonly ? 1 : 0 );

View File

@ -42,14 +42,14 @@ public class FooMojo
* the cool bar to go
* @since 1.0
*/
@Parameter( expression = "${thebar}", required = true, defaultValue = "coolbar" )
@Parameter( property = "thebar", required = true, defaultValue = "coolbar" )
protected String bar;
/**
* beer for non french folks
* @deprecated wine is better
*/
@Parameter( expression = "${thebeer}", defaultValue = "coolbeer" )
@Parameter( property = "thebeer", defaultValue = "coolbeer" )
protected String beer;
/**

View File

@ -83,8 +83,8 @@ public class TestAnnotationsReader
Collection<ParameterAnnotationContent> parameters = mojoAnnotatedClass.getParameters().values();
Assertions.assertThat( parameters ).isNotNull().isNotEmpty().hasSize( 2 ).contains(
new ParameterAnnotationContent( "bar", null, "${thebar}", "coolbar", true, false, String.class.getName() ),
new ParameterAnnotationContent( "beer", null, "${thebeer}", "coolbeer", false, false,
new ParameterAnnotationContent( "bar", null, "thebar", "coolbar", true, false, String.class.getName() ),
new ParameterAnnotationContent( "beer", null, "thebeer", "coolbeer", false, false,
String.class.getName() ) );
}
}