diff --git a/pom.xml b/pom.xml
index 93b386f..22720d7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@ under the License.
maven-invoker
- 3.2.1-SNAPSHOT
+ 3.3.0-SNAPSHOT
Apache Maven Invoker
A component to programmatically invoke Maven.
@@ -65,7 +65,7 @@ under the License.
8
- 2022-04-05T18:45:23Z
+ 2024-05-04T12:59:43Z
diff --git a/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java b/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java
index 7b1c6fb..470f1f2 100644
--- a/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java
+++ b/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java
@@ -21,6 +21,7 @@
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -471,6 +472,12 @@ public InvocationRequest addArg(String arg) {
return this;
}
+ @Override
+ public InvocationRequest addArgs(Collection args) {
+ args.stream().filter(arg -> !StringUtils.isBlank(arg)).forEach(this.args::add);
+ return this;
+ }
+
public List getArgs() {
return args;
}
diff --git a/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java b/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java
index f4a499c..0a5b968 100644
--- a/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java
+++ b/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java
@@ -20,6 +20,7 @@
import java.io.File;
import java.io.InputStream;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -552,6 +553,16 @@ enum CheckSumPolicy {
*/
InvocationRequest addArg(String arg);
+ /**
+ * Add a raw arguments list to Maven cli command at the end of other arguments.
+ * Can be called multiple time in order to add many arguments.
+ *
+ * @param args a raw Maven args line
+ * @return This invocation request.
+ * @since 3.3.0
+ */
+ InvocationRequest addArgs(Collection args);
+
/**
* Sets the path to the base directory of the POM for the Maven invocation. If {@link #getPomFile()} does not return
* null
, this setting only affects the working directory for the Maven invocation.
@@ -583,7 +594,9 @@ enum CheckSumPolicy {
*
* @param goals The goals for the Maven invocation, may be null
to execute the POMs default goal.
* @return This invocation request.
+ * @deprecated simply {@link #addArg(String)} or {@link #addArgs(Collection)} should be used
*/
+ @Deprecated
InvocationRequest setGoals(List goals);
/**
diff --git a/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java b/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
index 22e67dc..b6f2eb5 100644
--- a/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
+++ b/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
@@ -471,7 +471,7 @@ protected void setThreads(InvocationRequest request, Commandline cli) {
}
}
- private void setArgs(InvocationRequest request, Commandline cli) {
+ protected void setArgs(InvocationRequest request, Commandline cli) {
for (String arg : request.getArgs()) {
cli.createArg().setValue(arg);
}
diff --git a/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java b/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java
index 3335564..e23e804 100644
--- a/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java
+++ b/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java
@@ -23,7 +23,6 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
-import java.util.Collections;
import java.util.Properties;
import org.apache.maven.shared.utils.Os;
@@ -46,6 +45,7 @@ public void setUp() throws Exception {
}
@Test
+ @SuppressWarnings("deprecation")
public void testBuildShouldSucceed() throws MavenInvocationException, URISyntaxException {
File basedir = getBasedirForBuild();
request.setBaseDirectory(basedir);
@@ -60,7 +60,7 @@ public void testBuildShouldSucceed() throws MavenInvocationException, URISyntaxE
public void testBuildShouldFail() throws MavenInvocationException, URISyntaxException {
File basedir = getBasedirForBuild();
request.setBaseDirectory(basedir);
- request.setGoals(Arrays.asList("clean", "package"));
+ request.addArgs(Arrays.asList("clean", "package"));
InvocationResult result = invoker.execute(request);
@@ -71,7 +71,7 @@ public void testBuildShouldFail() throws MavenInvocationException, URISyntaxExce
public void testBuildShouldTimeout() throws MavenInvocationException, URISyntaxException {
File basedir = getBasedirForBuild();
request.setBaseDirectory(basedir);
- request.setGoals(Arrays.asList("clean", "package"));
+ request.addArgs(Arrays.asList("clean", "package"));
request.setTimeoutInSeconds(4);
InvocationResult result = invoker.execute(request);
@@ -93,7 +93,7 @@ public void testSpacePom() throws Exception {
File basedir = getBasedirForBuild();
request.setBaseDirectory(basedir);
request.setPomFileName("pom with spaces.xml");
- request.setGoals(Collections.singletonList("clean"));
+ request.addArg("clean");
InvocationResult result = invoker.execute(request);
@@ -105,7 +105,7 @@ public void testSpaceAndSpecialCharPom() throws Exception {
File basedir = getBasedirForBuild();
request.setBaseDirectory(basedir);
request.setPomFileName("pom with spaces & special char.xml");
- request.setGoals(Collections.singletonList("clean"));
+ request.addArg("clean");
InvocationResult result = invoker.execute(request);
@@ -117,7 +117,7 @@ public void testSpaceSettings() throws Exception {
File basedir = getBasedirForBuild();
request.setBaseDirectory(basedir);
request.setUserSettingsFile(new File(basedir, "settings with spaces.xml"));
- request.setGoals(Collections.singletonList("validate"));
+ request.addArg("validate");
InvocationResult result = invoker.execute(request);
@@ -129,7 +129,7 @@ public void testSpaceLocalRepo() throws Exception {
File basedir = getBasedirForBuild();
request.setBaseDirectory(basedir);
request.setLocalRepositoryDirectory(new File(basedir, "repo with spaces"));
- request.setGoals(Collections.singletonList("validate"));
+ request.addArg("validate");
InvocationResult result = invoker.execute(request);
@@ -144,7 +144,7 @@ public void testSpaceProperties() throws Exception {
props.setProperty("key", "value with spaces");
props.setProperty("key with spaces", "value");
request.setProperties(props);
- request.setGoals(Collections.singletonList("validate"));
+ request.addArg("validate");
InvocationResult result = invoker.execute(request);
@@ -157,7 +157,7 @@ public void testPomOutsideProject() throws Exception {
request.setBaseDirectory(basedir);
File pom = new File(basedir, "temp/pom.xml");
request.setPomFile(pom);
- request.setGoals(Collections.singletonList("validate"));
+ request.addArg("validate");
InvocationResult result = invoker.execute(request);
@@ -168,7 +168,7 @@ public void testPomOutsideProject() throws Exception {
public void testMavenWrapperInProject() throws Exception {
File basedir = getBasedirForBuild();
request.setBaseDirectory(basedir);
- request.setGoals(Collections.singletonList("test-wrapper-goal"));
+ request.addArg("test-wrapper-goal");
request.setMavenExecutable(new File("./mvnw"));
final StringBuilder outlines = new StringBuilder();
diff --git a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
index 13b1b2e..00a41d4 100644
--- a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
+++ b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
@@ -710,6 +710,7 @@ public void testShouldSpecifyCustomPropertyWithSpacesInKeyFromRequest() {
}
@Test
+ @SuppressWarnings("deprecation")
public void testShouldSpecifySingleGoalFromRequest() throws CommandLineConfigurationException {
List goals = new ArrayList<>();
@@ -721,6 +722,15 @@ public void testShouldSpecifySingleGoalFromRequest() throws CommandLineConfigura
}
@Test
+ void testShouldSpecifySingleGoalFromRequestArg() throws CommandLineConfigurationException {
+
+ mclb.setArgs(newRequest().addArg("test"), cli);
+
+ assertArgumentsPresent(cli, Collections.singleton("test"));
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
public void testShouldSpecifyTwoGoalsFromRequest() throws CommandLineConfigurationException {
List goals = new ArrayList<>();
goals.add("test");
@@ -732,6 +742,18 @@ public void testShouldSpecifyTwoGoalsFromRequest() throws CommandLineConfigurati
assertArgumentsPresentInOrder(cli, goals);
}
+ @Test
+ void testShouldSpecifyTwoGoalsFromRequestArgs() throws CommandLineConfigurationException {
+ List goals = new ArrayList<>();
+ goals.add("test");
+ goals.add("clean");
+
+ mclb.setArgs(newRequest().addArgs(goals), cli);
+
+ assertArgumentsPresent(cli, new HashSet<>(goals));
+ assertArgumentsPresentInOrder(cli, goals);
+ }
+
@Test
public void testShouldSpecifyThreadsFromRequest() {
mclb.setThreads(newRequest().setThreads("2.0C"), cli);
@@ -777,7 +799,7 @@ public void testBuildTypicalMavenInvocationEndToEnd() throws Exception {
goals.add("deploy");
goals.add("site-deploy");
- request.setGoals(goals);
+ request.addArgs(goals);
Commandline commandline = mclb.build(request);