Skip to content

Commit

Permalink
[MSHARED-1390] Deprecate InvocationRequest#setGoals
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed May 5, 2024
1 parent d956445 commit 4e21683
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 20 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ under the License.
</parent>

<artifactId>maven-invoker</artifactId>
<version>3.2.1-SNAPSHOT</version>
<version>3.3.0-SNAPSHOT</version>

<name>Apache Maven Invoker</name>
<description>A component to programmatically invoke Maven.</description>
Expand Down Expand Up @@ -65,7 +65,7 @@ under the License.

<properties>
<javaVersion>8</javaVersion>
<project.build.outputTimestamp>2022-04-05T18:45:23Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2024-05-04T12:59:43Z</project.build.outputTimestamp>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
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;
import java.util.Map;
import java.util.Properties;

import org.apache.maven.shared.utils.StringUtils;

/**
* Specifies the parameters used to control a Maven invocation.
*
Expand Down Expand Up @@ -465,9 +464,13 @@ public String getPomFileName() {

@Override
public InvocationRequest addArg(String arg) {
if (StringUtils.isNotBlank(arg)) {
args.add(arg);
}
args.add(arg);
return this;
}

@Override
public InvocationRequest addArgs(Collection<String> args) {
this.args.addAll(args);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -543,7 +544,7 @@ enum CheckSumPolicy {
InvocationRequest setPomFileName(String pomFilename);

/**
* Add a raw argument to Maven cli command at the end of other arguments.
* Add a raw argument to Maven cli command at the end of other arguments.
* Can be called multiple time in order to add many arguments.
*
* @param arg a raw Maven arg line
Expand All @@ -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<String> args);

/**
* Sets the path to the base directory of the POM for the Maven invocation. If {@link #getPomFile()} does not return
* <code>null</code>, this setting only affects the working directory for the Maven invocation.
Expand Down Expand Up @@ -583,7 +594,9 @@ enum CheckSumPolicy {
*
* @param goals The goals for the Maven invocation, may be <code>null</code> 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<String> goals);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,6 +45,7 @@ public void setUp() throws Exception {
}

@Test
@SuppressWarnings("deprecation")
public void testBuildShouldSucceed() throws MavenInvocationException, URISyntaxException {
File basedir = getBasedirForBuild();
request.setBaseDirectory(basedir);
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ public void testShouldSpecifyCustomPropertyWithSpacesInKeyFromRequest() {
}

@Test
@SuppressWarnings("deprecation")
public void testShouldSpecifySingleGoalFromRequest() throws CommandLineConfigurationException {

List<String> goals = new ArrayList<>();
Expand All @@ -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<String> goals = new ArrayList<>();
goals.add("test");
Expand All @@ -732,6 +742,18 @@ public void testShouldSpecifyTwoGoalsFromRequest() throws CommandLineConfigurati
assertArgumentsPresentInOrder(cli, goals);
}

@Test
void testShouldSpecifyTwoGoalsFromRequestArgs() throws CommandLineConfigurationException {
List<String> 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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 4e21683

Please sign in to comment.