mirror of https://github.com/apache/maven.git
change expressions to use ${} instead of #
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@164171 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c8b5f21331
commit
c289cf4f7f
|
@ -43,22 +43,30 @@ public class PluginParameterExpressionEvaluator
|
|||
this.pathTranslator = pathTranslator;
|
||||
}
|
||||
|
||||
public Object evaluate( String expression )
|
||||
public Object evaluate( String expr )
|
||||
throws ExpressionEvaluationException
|
||||
{
|
||||
Object value = null;
|
||||
|
||||
if ( expression == null )
|
||||
if ( expr == null )
|
||||
{
|
||||
// todo : verify if it's fixed with trygvis modification in Plexus
|
||||
// TODO: this should not have happened - previously there was a note about a fix to plexus Trygve was going to make - investigate
|
||||
return null;
|
||||
}
|
||||
if ( expression.startsWith( "#component" ) )
|
||||
|
||||
String expression = stripTokens( expr );
|
||||
if ( expression.equals( expr ) )
|
||||
{
|
||||
// Was not an expression
|
||||
return expression;
|
||||
}
|
||||
|
||||
if ( expression.startsWith( "component" ) )
|
||||
{
|
||||
context.getLog().warn( "WARNING: plugin is using deprecated expression " + expression );
|
||||
|
||||
// TODO: deprecated... and can remove the lookup method in context afterwards
|
||||
String role = expression.substring( 11 );
|
||||
String role = expression.substring( 10 );
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -69,20 +77,20 @@ public class PluginParameterExpressionEvaluator
|
|||
throw new ExpressionEvaluationException( "Cannot lookup component: " + role + ".", e );
|
||||
}
|
||||
}
|
||||
else if ( expression.equals( "#localRepository" ) )
|
||||
else if ( expression.equals( "localRepository" ) )
|
||||
{
|
||||
value = context.getLocalRepository();
|
||||
}
|
||||
else if ( expression.equals( "#maven.final.name" ) )
|
||||
else if ( expression.equals( "maven.final.name" ) )
|
||||
{
|
||||
// TODO: remove this alias
|
||||
value = context.getProject().getBuild().getFinalName();
|
||||
}
|
||||
else if ( expression.equals( "#project" ) )
|
||||
else if ( expression.equals( "project" ) )
|
||||
{
|
||||
value = context.getProject();
|
||||
}
|
||||
else if ( expression.startsWith( "#project" ) )
|
||||
else if ( expression.startsWith( "project" ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -106,15 +114,15 @@ public class PluginParameterExpressionEvaluator
|
|||
e );
|
||||
}
|
||||
}
|
||||
else if ( "#settings".equals( expression ) )
|
||||
else if ( "settings".equals( expression ) )
|
||||
{
|
||||
value = context.getSettings();
|
||||
}
|
||||
else if ( expression.equals( "#basedir" ) )
|
||||
else if ( expression.equals( "basedir" ) )
|
||||
{
|
||||
value = context.getProject().getBasedir().getAbsolutePath();
|
||||
}
|
||||
else if ( expression.startsWith( "#basedir" ) )
|
||||
else if ( expression.startsWith( "basedir" ) )
|
||||
{
|
||||
int pathSeparator = expression.indexOf( "/" );
|
||||
|
||||
|
@ -125,52 +133,59 @@ public class PluginParameterExpressionEvaluator
|
|||
}
|
||||
else
|
||||
{
|
||||
new Exception( "Got expression '" + expression + "' that was not recognised" ).printStackTrace();
|
||||
context.getLog().error( "Got expression '" + expression + "' that was not recognised" );
|
||||
}
|
||||
}
|
||||
else if ( expression.startsWith( "#" ) )
|
||||
else
|
||||
{
|
||||
// We will attempt to get nab a system property as a way to specify a
|
||||
// parameter to a plugins. My particular case here is allowing the surefire
|
||||
// plugin to run a single test so I want to specify that class on the cli
|
||||
// as a parameter.
|
||||
|
||||
value = System.getProperty( expression.substring( 1 ) );
|
||||
value = System.getProperty( expression );
|
||||
}
|
||||
|
||||
if ( value instanceof String )
|
||||
{
|
||||
// Note that we only half support nesting of expressions due to endsWith above
|
||||
String val = (String) value;
|
||||
int sharpSeparator = val.indexOf( "#" );
|
||||
|
||||
if ( sharpSeparator > 0 )
|
||||
if ( sharpSeparator < 0 )
|
||||
{
|
||||
val = val.substring( 0, sharpSeparator ) + evaluate( val.substring( sharpSeparator ) );
|
||||
value = val;
|
||||
sharpSeparator = val.indexOf( "${" );
|
||||
}
|
||||
else if ( sharpSeparator > 0 )
|
||||
|
||||
if ( sharpSeparator >= 0 )
|
||||
{
|
||||
value = evaluate( val.substring( sharpSeparator ) );
|
||||
if ( sharpSeparator > 0 )
|
||||
{
|
||||
value = val.substring( 0, sharpSeparator ) + evaluate( val.substring( sharpSeparator ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
value = evaluate( val.substring( sharpSeparator ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// If we strike and we are not dealing with an expression then we will
|
||||
// will let the value pass through unaltered so that users can hardcode
|
||||
// literal values. Expressions that evaluate to null will be passed
|
||||
// through as null so that the validator can see the null value and
|
||||
// act in accordance with the requirements laid out in the
|
||||
// mojo descriptor.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
if ( value == null && expression.length() > 0 && !expression.startsWith( "#" ) )
|
||||
{
|
||||
value = expression;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private String stripTokens( String expr )
|
||||
{
|
||||
if ( expr.startsWith( "#" ) )
|
||||
{
|
||||
context.getLog().warn( "DEPRECATED: use ${} to delimit expressions instead of # for '" + expr + "'" );
|
||||
expr = expr.substring( 1 );
|
||||
}
|
||||
else if ( expr.startsWith( "${" ) && expr.endsWith( "}" ) )
|
||||
{
|
||||
expr = expr.substring( 2, expr.length() - 1 );
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
|
||||
public File alignToBaseDirectory( File file )
|
||||
{
|
||||
File basedir = context.getProject().getFile().getParentFile();
|
||||
|
|
|
@ -75,6 +75,7 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
private ArtifactResolver artifactResolver;
|
||||
|
||||
// TODO: comes from Maven CORE
|
||||
private ArtifactFactory artifactFactory;
|
||||
|
||||
private ModelInheritanceAssembler modelInheritanceAssembler;
|
||||
|
@ -89,6 +90,7 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
private ModelInterpolator modelInterpolator;
|
||||
|
||||
// TODO: comes from Maven CORE
|
||||
private ArtifactRepositoryFactory artifactRepositoryFactory;
|
||||
|
||||
private final Map modelCache = new HashMap();
|
||||
|
@ -265,6 +267,7 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
if ( resolveDependencies )
|
||||
{
|
||||
// TODO: comes from Maven CORE
|
||||
MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver, this );
|
||||
|
||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(),
|
||||
|
|
|
@ -183,7 +183,8 @@ public class PluginDescriptorGenerator
|
|||
element( w, "validator", parameter.getValidator() );
|
||||
|
||||
String value = null;
|
||||
if ( parameter.getExpression().startsWith( "#component" ) )
|
||||
if ( parameter.getExpression().startsWith( "#component." ) ||
|
||||
parameter.getExpression().startsWith( "${component." ) )
|
||||
{
|
||||
requirements.add( parameter );
|
||||
}
|
||||
|
@ -253,7 +254,18 @@ public class PluginDescriptorGenerator
|
|||
|
||||
w.startElement( "requirement" );
|
||||
|
||||
element( w, "role", requirement.getExpression().substring( 11 ) );
|
||||
String role;
|
||||
// remove "component." plus expression delimiters
|
||||
String expression = requirement.getExpression();
|
||||
if ( expression.startsWith( "${" ) )
|
||||
{
|
||||
role = expression.substring( "${component.".length(), expression.length() - 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
role = expression.substring( "#component.".length() );
|
||||
}
|
||||
element( w, "role", role );
|
||||
|
||||
element( w, "field-name", requirement.getName() );
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.io.File;
|
|||
* type="String"
|
||||
* required="true"
|
||||
* validator=""
|
||||
* expression="#project.build.directory"
|
||||
* expression="${project.build.directory}"
|
||||
* description=""
|
||||
*/
|
||||
public class CleanPlugin
|
||||
|
|
Loading…
Reference in New Issue