Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}
} else {
handleResponse("${" + expression + "}", output);
if (!expression.contains("${")) {
expression = "${" + expression + "}";
}
handleResponse(expression, output);
}
}

Expand Down
23 changes: 23 additions & 0 deletions src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@ public void testEvaluateWithoutExpressionWithOutput() throws Exception {
verify(inputHandler, times(2)).readLine();
}

/**
* Tests evaluation of a complex expression.
* @throws Exception in case of errors.
*/
public void testEvaluateForComplexExpression() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/evaluate/plugin-config-complex.xml");

EvaluateMojo mojo = (EvaluateMojo) lookupMojo("evaluate", testPom);

ExpressionEvaluator expressionEvaluator = mock(PluginParameterExpressionEvaluator.class);
when(expressionEvaluator.evaluate("project_version=${project.version}"))
.thenReturn("project_version=1.0.0-SNAPSHOT");

setUpMojo(mojo, null, expressionEvaluator);

mojo.execute();

String ls = System.getProperty("line.separator");

assertTrue(interceptingLogger.infoLogs.contains(ls + "project_version=1.0.0-SNAPSHOT"));
verify(expressionEvaluator).evaluate("project_version=${project.version}");
}

/**
* This test will check that only the <code>project.groupId</code> is printed to
* stdout nothing else.
Expand Down
38 changes: 38 additions & 0 deletions src/test/resources/unit/evaluate/plugin-config-complex.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.help</groupId>
<artifactId>evaluate</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<configuration>
<expression><![CDATA[project_version=${project.version}]]></expression>
</configuration>
</plugin>
</plugins>
</build>
</project>