Skip to content

Commit 4e21683

Browse files
[MSHARED-1390] Deprecate InvocationRequest#setGoals
1 parent d956445 commit 4e21683

File tree

6 files changed

+58
-20
lines changed

6 files changed

+58
-20
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ under the License.
2828
</parent>
2929

3030
<artifactId>maven-invoker</artifactId>
31-
<version>3.2.1-SNAPSHOT</version>
31+
<version>3.3.0-SNAPSHOT</version>
3232

3333
<name>Apache Maven Invoker</name>
3434
<description>A component to programmatically invoke Maven.</description>
@@ -65,7 +65,7 @@ under the License.
6565

6666
<properties>
6767
<javaVersion>8</javaVersion>
68-
<project.build.outputTimestamp>2022-04-05T18:45:23Z</project.build.outputTimestamp>
68+
<project.build.outputTimestamp>2024-05-04T12:59:43Z</project.build.outputTimestamp>
6969
</properties>
7070

7171
<dependencies>

src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
import java.io.File;
2222
import java.io.InputStream;
2323
import java.util.ArrayList;
24+
import java.util.Collection;
2425
import java.util.Collections;
2526
import java.util.HashMap;
2627
import java.util.List;
2728
import java.util.Map;
2829
import java.util.Properties;
2930

30-
import org.apache.maven.shared.utils.StringUtils;
31-
3231
/**
3332
* Specifies the parameters used to control a Maven invocation.
3433
*
@@ -465,9 +464,13 @@ public String getPomFileName() {
465464

466465
@Override
467466
public InvocationRequest addArg(String arg) {
468-
if (StringUtils.isNotBlank(arg)) {
469-
args.add(arg);
470-
}
467+
args.add(arg);
468+
return this;
469+
}
470+
471+
@Override
472+
public InvocationRequest addArgs(Collection<String> args) {
473+
this.args.addAll(args);
471474
return this;
472475
}
473476

src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.File;
2222
import java.io.InputStream;
23+
import java.util.Collection;
2324
import java.util.List;
2425
import java.util.Map;
2526
import java.util.Properties;
@@ -543,7 +544,7 @@ enum CheckSumPolicy {
543544
InvocationRequest setPomFileName(String pomFilename);
544545

545546
/**
546-
* Add a raw argument to Maven cli command at the end of other arguments.
547+
* Add a raw argument to Maven cli command at the end of other arguments.
547548
* Can be called multiple time in order to add many arguments.
548549
*
549550
* @param arg a raw Maven arg line
@@ -552,6 +553,16 @@ enum CheckSumPolicy {
552553
*/
553554
InvocationRequest addArg(String arg);
554555

556+
/**
557+
* Add a raw arguments list to Maven cli command at the end of other arguments.
558+
* Can be called multiple time in order to add many arguments.
559+
*
560+
* @param args a raw Maven args line
561+
* @return This invocation request.
562+
* @since 3.3.0
563+
*/
564+
InvocationRequest addArgs(Collection<String> args);
565+
555566
/**
556567
* Sets the path to the base directory of the POM for the Maven invocation. If {@link #getPomFile()} does not return
557568
* <code>null</code>, this setting only affects the working directory for the Maven invocation.
@@ -583,7 +594,9 @@ enum CheckSumPolicy {
583594
*
584595
* @param goals The goals for the Maven invocation, may be <code>null</code> to execute the POMs default goal.
585596
* @return This invocation request.
597+
* @deprecated simply {@link #addArg(String)} or {@link #addArgs(Collection)} should be used
586598
*/
599+
@Deprecated
587600
InvocationRequest setGoals(List<String> goals);
588601

589602
/**

src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ protected void setThreads(InvocationRequest request, Commandline cli) {
471471
}
472472
}
473473

474-
private void setArgs(InvocationRequest request, Commandline cli) {
474+
protected void setArgs(InvocationRequest request, Commandline cli) {
475475
for (String arg : request.getArgs()) {
476476
cli.createArg().setValue(arg);
477477
}

src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.net.URISyntaxException;
2424
import java.net.URL;
2525
import java.util.Arrays;
26-
import java.util.Collections;
2726
import java.util.Properties;
2827

2928
import org.apache.maven.shared.utils.Os;
@@ -46,6 +45,7 @@ public void setUp() throws Exception {
4645
}
4746

4847
@Test
48+
@SuppressWarnings("deprecation")
4949
public void testBuildShouldSucceed() throws MavenInvocationException, URISyntaxException {
5050
File basedir = getBasedirForBuild();
5151
request.setBaseDirectory(basedir);
@@ -60,7 +60,7 @@ public void testBuildShouldSucceed() throws MavenInvocationException, URISyntaxE
6060
public void testBuildShouldFail() throws MavenInvocationException, URISyntaxException {
6161
File basedir = getBasedirForBuild();
6262
request.setBaseDirectory(basedir);
63-
request.setGoals(Arrays.asList("clean", "package"));
63+
request.addArgs(Arrays.asList("clean", "package"));
6464

6565
InvocationResult result = invoker.execute(request);
6666

@@ -71,7 +71,7 @@ public void testBuildShouldFail() throws MavenInvocationException, URISyntaxExce
7171
public void testBuildShouldTimeout() throws MavenInvocationException, URISyntaxException {
7272
File basedir = getBasedirForBuild();
7373
request.setBaseDirectory(basedir);
74-
request.setGoals(Arrays.asList("clean", "package"));
74+
request.addArgs(Arrays.asList("clean", "package"));
7575
request.setTimeoutInSeconds(4);
7676

7777
InvocationResult result = invoker.execute(request);
@@ -93,7 +93,7 @@ public void testSpacePom() throws Exception {
9393
File basedir = getBasedirForBuild();
9494
request.setBaseDirectory(basedir);
9595
request.setPomFileName("pom with spaces.xml");
96-
request.setGoals(Collections.singletonList("clean"));
96+
request.addArg("clean");
9797

9898
InvocationResult result = invoker.execute(request);
9999

@@ -105,7 +105,7 @@ public void testSpaceAndSpecialCharPom() throws Exception {
105105
File basedir = getBasedirForBuild();
106106
request.setBaseDirectory(basedir);
107107
request.setPomFileName("pom with spaces & special char.xml");
108-
request.setGoals(Collections.singletonList("clean"));
108+
request.addArg("clean");
109109

110110
InvocationResult result = invoker.execute(request);
111111

@@ -117,7 +117,7 @@ public void testSpaceSettings() throws Exception {
117117
File basedir = getBasedirForBuild();
118118
request.setBaseDirectory(basedir);
119119
request.setUserSettingsFile(new File(basedir, "settings with spaces.xml"));
120-
request.setGoals(Collections.singletonList("validate"));
120+
request.addArg("validate");
121121

122122
InvocationResult result = invoker.execute(request);
123123

@@ -129,7 +129,7 @@ public void testSpaceLocalRepo() throws Exception {
129129
File basedir = getBasedirForBuild();
130130
request.setBaseDirectory(basedir);
131131
request.setLocalRepositoryDirectory(new File(basedir, "repo with spaces"));
132-
request.setGoals(Collections.singletonList("validate"));
132+
request.addArg("validate");
133133

134134
InvocationResult result = invoker.execute(request);
135135

@@ -144,7 +144,7 @@ public void testSpaceProperties() throws Exception {
144144
props.setProperty("key", "value with spaces");
145145
props.setProperty("key with spaces", "value");
146146
request.setProperties(props);
147-
request.setGoals(Collections.singletonList("validate"));
147+
request.addArg("validate");
148148

149149
InvocationResult result = invoker.execute(request);
150150

@@ -157,7 +157,7 @@ public void testPomOutsideProject() throws Exception {
157157
request.setBaseDirectory(basedir);
158158
File pom = new File(basedir, "temp/pom.xml");
159159
request.setPomFile(pom);
160-
request.setGoals(Collections.singletonList("validate"));
160+
request.addArg("validate");
161161

162162
InvocationResult result = invoker.execute(request);
163163

@@ -168,7 +168,7 @@ public void testPomOutsideProject() throws Exception {
168168
public void testMavenWrapperInProject() throws Exception {
169169
File basedir = getBasedirForBuild();
170170
request.setBaseDirectory(basedir);
171-
request.setGoals(Collections.singletonList("test-wrapper-goal"));
171+
request.addArg("test-wrapper-goal");
172172
request.setMavenExecutable(new File("./mvnw"));
173173

174174
final StringBuilder outlines = new StringBuilder();

src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ public void testShouldSpecifyCustomPropertyWithSpacesInKeyFromRequest() {
710710
}
711711

712712
@Test
713+
@SuppressWarnings("deprecation")
713714
public void testShouldSpecifySingleGoalFromRequest() throws CommandLineConfigurationException {
714715

715716
List<String> goals = new ArrayList<>();
@@ -721,6 +722,15 @@ public void testShouldSpecifySingleGoalFromRequest() throws CommandLineConfigura
721722
}
722723

723724
@Test
725+
void testShouldSpecifySingleGoalFromRequestArg() throws CommandLineConfigurationException {
726+
727+
mclb.setArgs(newRequest().addArg("test"), cli);
728+
729+
assertArgumentsPresent(cli, Collections.singleton("test"));
730+
}
731+
732+
@Test
733+
@SuppressWarnings("deprecation")
724734
public void testShouldSpecifyTwoGoalsFromRequest() throws CommandLineConfigurationException {
725735
List<String> goals = new ArrayList<>();
726736
goals.add("test");
@@ -732,6 +742,18 @@ public void testShouldSpecifyTwoGoalsFromRequest() throws CommandLineConfigurati
732742
assertArgumentsPresentInOrder(cli, goals);
733743
}
734744

745+
@Test
746+
void testShouldSpecifyTwoGoalsFromRequestArgs() throws CommandLineConfigurationException {
747+
List<String> goals = new ArrayList<>();
748+
goals.add("test");
749+
goals.add("clean");
750+
751+
mclb.setArgs(newRequest().addArgs(goals), cli);
752+
753+
assertArgumentsPresent(cli, new HashSet<>(goals));
754+
assertArgumentsPresentInOrder(cli, goals);
755+
}
756+
735757
@Test
736758
public void testShouldSpecifyThreadsFromRequest() {
737759
mclb.setThreads(newRequest().setThreads("2.0C"), cli);
@@ -777,7 +799,7 @@ public void testBuildTypicalMavenInvocationEndToEnd() throws Exception {
777799
goals.add("deploy");
778800
goals.add("site-deploy");
779801

780-
request.setGoals(goals);
802+
request.addArgs(goals);
781803

782804
Commandline commandline = mclb.build(request);
783805

0 commit comments

Comments
 (0)