From 8d4ca04b2d0ff97bc05f2d4aabeff6f958202246 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Mon, 2 May 2005 07:22:18 +0000 Subject: [PATCH] fix bad expression handling git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@165597 13f79535-47bb-0310-9956-ffa450edef68 --- .../PluginParameterExpressionEvaluator.java | 2 +- ...luginParameterExpressionEvaluatorTest.java | 51 +++++++++++++------ 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java index 164a1e6d45..69f31c38df 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java @@ -193,7 +193,7 @@ public class PluginParameterExpressionEvaluator context.getLog().warn( "DEPRECATED: use ${} to delimit expressions instead of # for '" + expr + "'" ); 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 ); } diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java index 7625d9f667..8ee67c4982 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java @@ -45,13 +45,6 @@ public class PluginParameterExpressionEvaluatorTest { 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.setDirectory( expected.substring( 0, expected.length() - "/classes".length() ) ); @@ -61,9 +54,7 @@ public class PluginParameterExpressionEvaluatorTest MavenProject project = new MavenProject( model ); project.setFile( new File( "pom.xml" ).getCanonicalFile() ); - MavenSession session = createSession( project, container, repo ); - - ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null ); + ExpressionEvaluator expressionEvaluator = createExpressionEvaluator( project ); Object value = expressionEvaluator.evaluate( "${project.build.directory}/classes" ); String actual = new File( value.toString() ).getCanonicalPath(); @@ -88,7 +79,7 @@ public class PluginParameterExpressionEvaluatorTest ArtifactRepository repo = new ArtifactRepository( "test", "http://www.test.com", repoLayout ); PlexusContainer container = getContainer(); - MavenSession session = createSession( new MavenProject(new Model()), container, repo ); + MavenSession session = createSession( createDefaultProject(), container, repo ); ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null ); @@ -97,6 +88,38 @@ public class PluginParameterExpressionEvaluatorTest public void testLocalRepositoryExtraction() 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, "legacy" ); @@ -104,11 +127,9 @@ public class PluginParameterExpressionEvaluatorTest ArtifactRepository repo = new ArtifactRepository( "local", "target/repo", repoLayout ); PlexusContainer container = getContainer(); - MavenSession session = createSession( new MavenProject(new Model()), container, repo ); + MavenSession session = createSession( project, container, repo ); ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null ); - Object value = expressionEvaluator.evaluate( "${localRepository}" ); - - assertEquals( "local", ( (ArtifactRepository) value ).getId() ); + return expressionEvaluator; } } \ No newline at end of file