mirror of https://github.com/apache/maven.git
fix bad expression handling
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@165597 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e7b911416f
commit
8d4ca04b2d
|
@ -193,7 +193,7 @@ public class PluginParameterExpressionEvaluator
|
||||||
context.getLog().warn( "DEPRECATED: use ${} to delimit expressions instead of # for '" + expr + "'" );
|
context.getLog().warn( "DEPRECATED: use ${} to delimit expressions instead of # for '" + expr + "'" );
|
||||||
expr = expr.substring( 1 );
|
expr = expr.substring( 1 );
|
||||||
}
|
}
|
||||||
else if ( expr.startsWith( "${" ) && expr.endsWith( "}" ) )
|
else if ( expr.startsWith( "${" ) && expr.indexOf( "}" ) == expr.length() - 1 )
|
||||||
{
|
{
|
||||||
expr = expr.substring( 2, expr.length() - 1 );
|
expr = expr.substring( 2, expr.length() - 1 );
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,13 +45,6 @@ public class PluginParameterExpressionEvaluatorTest
|
||||||
{
|
{
|
||||||
String expected = getTestFile( "target/test-classes/target/classes" ).getCanonicalPath();
|
String expected = getTestFile( "target/test-classes/target/classes" ).getCanonicalPath();
|
||||||
|
|
||||||
ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
|
|
||||||
"legacy" );
|
|
||||||
|
|
||||||
ArtifactRepository repo = new ArtifactRepository( "local", "here", repoLayout );
|
|
||||||
|
|
||||||
PlexusContainer container = getContainer();
|
|
||||||
|
|
||||||
Build build = new Build();
|
Build build = new Build();
|
||||||
build.setDirectory( expected.substring( 0, expected.length() - "/classes".length() ) );
|
build.setDirectory( expected.substring( 0, expected.length() - "/classes".length() ) );
|
||||||
|
|
||||||
|
@ -61,9 +54,7 @@ public class PluginParameterExpressionEvaluatorTest
|
||||||
MavenProject project = new MavenProject( model );
|
MavenProject project = new MavenProject( model );
|
||||||
project.setFile( new File( "pom.xml" ).getCanonicalFile() );
|
project.setFile( new File( "pom.xml" ).getCanonicalFile() );
|
||||||
|
|
||||||
MavenSession session = createSession( project, container, repo );
|
ExpressionEvaluator expressionEvaluator = createExpressionEvaluator( project );
|
||||||
|
|
||||||
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null );
|
|
||||||
|
|
||||||
Object value = expressionEvaluator.evaluate( "${project.build.directory}/classes" );
|
Object value = expressionEvaluator.evaluate( "${project.build.directory}/classes" );
|
||||||
String actual = new File( value.toString() ).getCanonicalPath();
|
String actual = new File( value.toString() ).getCanonicalPath();
|
||||||
|
@ -88,7 +79,7 @@ public class PluginParameterExpressionEvaluatorTest
|
||||||
ArtifactRepository repo = new ArtifactRepository( "test", "http://www.test.com", repoLayout );
|
ArtifactRepository repo = new ArtifactRepository( "test", "http://www.test.com", repoLayout );
|
||||||
|
|
||||||
PlexusContainer container = getContainer();
|
PlexusContainer container = getContainer();
|
||||||
MavenSession session = createSession( new MavenProject(new Model()), container, repo );
|
MavenSession session = createSession( createDefaultProject(), container, repo );
|
||||||
|
|
||||||
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null );
|
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null );
|
||||||
|
|
||||||
|
@ -97,6 +88,38 @@ public class PluginParameterExpressionEvaluatorTest
|
||||||
|
|
||||||
public void testLocalRepositoryExtraction()
|
public void testLocalRepositoryExtraction()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
{
|
||||||
|
ExpressionEvaluator expressionEvaluator = createExpressionEvaluator( createDefaultProject() );
|
||||||
|
Object value = expressionEvaluator.evaluate( "${localRepository}" );
|
||||||
|
|
||||||
|
assertEquals( "local", ( (ArtifactRepository) value ).getId() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testTwoExpressions()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
Build build = new Build();
|
||||||
|
build.setDirectory( "expected-directory" );
|
||||||
|
build.setFinalName( "expected-finalName" );
|
||||||
|
|
||||||
|
Model model = new Model();
|
||||||
|
model.setBuild( build );
|
||||||
|
|
||||||
|
|
||||||
|
ExpressionEvaluator expressionEvaluator = createExpressionEvaluator( new MavenProject( model ) );
|
||||||
|
|
||||||
|
Object value = expressionEvaluator.evaluate( "${project.build.directory}/${project.build.finalName}" );
|
||||||
|
|
||||||
|
assertEquals( "expected-directory/expected-finalName", value );
|
||||||
|
}
|
||||||
|
|
||||||
|
private MavenProject createDefaultProject()
|
||||||
|
{
|
||||||
|
return new MavenProject( new Model() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExpressionEvaluator createExpressionEvaluator( MavenProject project )
|
||||||
|
throws Exception
|
||||||
{
|
{
|
||||||
ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
|
ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
|
||||||
"legacy" );
|
"legacy" );
|
||||||
|
@ -104,11 +127,9 @@ public class PluginParameterExpressionEvaluatorTest
|
||||||
ArtifactRepository repo = new ArtifactRepository( "local", "target/repo", repoLayout );
|
ArtifactRepository repo = new ArtifactRepository( "local", "target/repo", repoLayout );
|
||||||
|
|
||||||
PlexusContainer container = getContainer();
|
PlexusContainer container = getContainer();
|
||||||
MavenSession session = createSession( new MavenProject(new Model()), container, repo );
|
MavenSession session = createSession( project, container, repo );
|
||||||
|
|
||||||
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null );
|
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null );
|
||||||
Object value = expressionEvaluator.evaluate( "${localRepository}" );
|
return expressionEvaluator;
|
||||||
|
|
||||||
assertEquals( "local", ( (ArtifactRepository) value ).getId() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue