Adding '$' as an escape character for variable-syntax which should be passed through.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@328885 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-10-27 14:47:55 +00:00
parent e0aaa6acc9
commit 69fda56d91
2 changed files with 65 additions and 3 deletions

View File

@ -115,7 +115,7 @@ public class PluginParameterExpressionEvaluator
{
return null;
}
String expression = stripTokens( expr );
if ( expression.equals( expr ) )
{
@ -126,14 +126,23 @@ public class PluginParameterExpressionEvaluator
if ( lastIndex >= 0 )
{
String retVal = expr.substring( 0, index );
retVal += evaluate( expr.substring( index, lastIndex + 1 ) );
if ( index > 0 && expr.charAt( index - 1 ) == '$' )
{
retVal += expr.substring( index + 1, lastIndex + 1 );
}
else
{
retVal += evaluate( expr.substring( index, lastIndex + 1 ) );
}
retVal += evaluate( expr.substring( lastIndex + 1 ) );
return retVal;
}
}
// Was not an expression
return expression;
return expression.replaceAll( "\\$\\$", "$" );
}
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();

View File

@ -73,6 +73,59 @@ public class PluginParameterExpressionEvaluatorTest
assertEquals( expected, actual );
}
public void testEscapedVariablePassthrough()
throws Exception
{
String var = "${var}";
Model model = new Model();
model.setVersion( "1" );
MavenProject project = new MavenProject( model );
ExpressionEvaluator ee = createExpressionEvaluator( project, null, new Properties() );
Object value = ee.evaluate( "$" + var );
assertEquals( var, value );
}
public void testEscapedVariablePassthroughInLargerExpression()
throws Exception
{
String var = "${var}";
String key = var + " with version: ${project.version}";
Model model = new Model();
model.setVersion( "1" );
MavenProject project = new MavenProject( model );
ExpressionEvaluator ee = createExpressionEvaluator( project, null, new Properties() );
Object value = ee.evaluate( "$" + key );
assertEquals( "${var} with version: 1", value );
}
public void testMultipleSubExpressionsInLargerExpression()
throws Exception
{
String key = "${project.artifactId} with version: ${project.version}";
Model model = new Model();
model.setArtifactId( "test" );
model.setVersion( "1" );
MavenProject project = new MavenProject( model );
ExpressionEvaluator ee = createExpressionEvaluator( project, null, new Properties() );
Object value = ee.evaluate( key );
assertEquals( "test with version: 1", value );
}
public void testPOMPropertyExtractionWithMissingProject_WithDotNotation()
throws Exception
{