This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-help-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new ea12a9d Allow defining complex expression like in interactive mode
ea12a9d is described below
commit ea12a9d466c4a47f8771263a08e8c43825f6710e
Author: Grzegorz KochaĆski <[email protected]>
AuthorDate: Fri May 23 13:22:13 2025 +0200
Allow defining complex expression like in interactive mode
---
.../apache/maven/plugins/help/EvaluateMojo.java | 7 +++--
.../maven/plugins/help/EvaluateMojoTest.java | 34 ++++++++++++++++++++++
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
index 8f6a173..4121208 100644
--- a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
@@ -113,7 +113,7 @@ public class EvaluateMojo extends AbstractHelpMojo {
private String artifact;
/**
- * An expression to evaluate instead of prompting. Note that this <i>must
not</i> include the surrounding ${...}.
+ * An expression to evaluate instead of prompting. Note that this <i>may
not</i> include the surrounding ${...}.
*/
@Parameter(property = "expression")
private String expression;
@@ -200,7 +200,10 @@ public class EvaluateMojo extends AbstractHelpMojo {
}
}
} else {
- handleResponse("${" + expression + "}", output);
+ if (!expression.contains("${")) {
+ expression = "${" + expression + "}";
+ }
+ handleResponse(expression, output);
}
}
diff --git a/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java
b/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java
index eb4a016..ac6fe6e 100644
--- a/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java
@@ -114,6 +114,40 @@ class EvaluateMojoTest {
verify(inputHandler, times(2)).readLine();
}
+ /**
+ * Tests evaluation of a complex expression.
+ *
+ * @throws Exception in case of errors.
+ */
+ @Test
+ @ResourceLock(Resources.SYSTEM_OUT)
+ @InjectMojo(goal = "evaluate")
+ @MojoParameter(name = "forceStdout", value = "true")
+ @MojoParameter(name = "expression", value =
"project_groupId=${project.groupId}")
+ void testEvaluateForComplexExpression(EvaluateMojo mojo) throws Exception {
+
when(expressionEvaluator.evaluate(anyString())).thenReturn("project_groupId=org.apache.maven.its.help");
+
+ // Quiet mode given on command line.(simulation)
+ when(log.isInfoEnabled()).thenReturn(false);
+
+ setVariableValueToObject(mojo, "evaluator", expressionEvaluator);
+
+ PrintStream saveOut = System.out;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(baos));
+
+ try {
+ mojo.execute();
+ } finally {
+ System.setOut(saveOut);
+ baos.close();
+ }
+
+ String stdResult = baos.toString();
+ assertEquals("project_groupId=org.apache.maven.its.help", stdResult);
+ verify(log, times(0)).warn(anyString());
+ }
+
/**
* This test will check that only the <code>project.groupId</code> is
printed to
* stdout nothing else.