diff --git a/pom.xml b/pom.xml index 93b386f..74b78e9 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 @@ -81,7 +81,7 @@ under the License. org.junit.jupiter - junit-jupiter + junit-jupiter-api test 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..eb5060b 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; @@ -113,7 +114,7 @@ public class DefaultInvocationRequest implements InvocationRequest { private boolean noTransferProgress; - private List args = new ArrayList<>(); + private final List args = new ArrayList<>(); /** *

getBaseDirectory.

@@ -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..b0e5fc8 100644 --- a/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java +++ b/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java @@ -185,9 +185,7 @@ protected void setToolchainsLocation(InvocationRequest request, Commandline cli) * @param cli a {@link org.apache.maven.shared.utils.cli.Commandline} object. */ protected void setShellEnvironment(InvocationRequest request, Commandline cli) { - if (request.isShellEnvironmentInherited()) { - cli.addSystemEnvironment(); - } + cli.setShellEnvironmentInherited(request.isShellEnvironmentInherited()); if (request.getJavaHome() != null) { cli.addEnvironment("JAVA_HOME", request.getJavaHome().getAbsolutePath()); @@ -213,7 +211,7 @@ protected void setProfiles(InvocationRequest request, Commandline cli) { if ((profiles != null) && !profiles.isEmpty()) { cli.createArg().setValue("-P"); - cli.createArg().setValue(StringUtils.join(profiles.iterator(), ",")); + cli.createArg().setValue(String.join(",", profiles)); } } @@ -229,7 +227,7 @@ protected void setGoals(InvocationRequest request, Commandline cli) throws Comma if ((goals != null) && !goals.isEmpty()) { try { - cli.createArg().setLine(StringUtils.join(goals.iterator(), " ")); + cli.createArg().setLine(String.join(" ", goals)); } catch (CommandLineException e) { throw new CommandLineConfigurationException("Problem setting goals", e); } @@ -381,7 +379,7 @@ protected void setReactorBehavior(InvocationRequest request, Commandline cli) { List projectList = request.getProjects(); if (projectList != null) { cli.createArg().setValue("-pl"); - cli.createArg().setValue(StringUtils.join(projectList.iterator(), ",")); + cli.createArg().setValue(String.join(",", projectList)); if (request.isAlsoMake()) { cli.createArg().setValue("-am"); @@ -471,7 +469,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..5ef3b3f 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; @@ -34,19 +33,20 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class DefaultInvokerTest { +class DefaultInvokerTest { private Invoker invoker = newInvoker(); private InvocationRequest request = new DefaultInvocationRequest(); @BeforeEach - public void setUp() throws Exception { + void setUp() { request.setDebug(true); request.setProperties(getProperties()); } @Test - public void testBuildShouldSucceed() throws MavenInvocationException, URISyntaxException { + @SuppressWarnings("deprecation") + void testBuildShouldSucceed() throws MavenInvocationException, URISyntaxException { File basedir = getBasedirForBuild(); request.setBaseDirectory(basedir); request.setGoals(Arrays.asList("clean", "package")); @@ -57,10 +57,10 @@ public void testBuildShouldSucceed() throws MavenInvocationException, URISyntaxE } @Test - public void testBuildShouldFail() throws MavenInvocationException, URISyntaxException { + 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); @@ -68,10 +68,10 @@ public void testBuildShouldFail() throws MavenInvocationException, URISyntaxExce } @Test - public void testBuildShouldTimeout() throws MavenInvocationException, URISyntaxException { + 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); @@ -89,11 +89,11 @@ public void testBuildShouldTimeout() throws MavenInvocationException, URISyntaxE } @Test - public void testSpacePom() throws Exception { + 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); @@ -101,11 +101,11 @@ public void testSpacePom() throws Exception { } @Test - public void testSpaceAndSpecialCharPom() throws Exception { + 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); @@ -113,11 +113,11 @@ public void testSpaceAndSpecialCharPom() throws Exception { } @Test - public void testSpaceSettings() throws Exception { + 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); @@ -125,11 +125,11 @@ public void testSpaceSettings() throws Exception { } @Test - public void testSpaceLocalRepo() throws Exception { + 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); @@ -137,14 +137,14 @@ public void testSpaceLocalRepo() throws Exception { } @Test - public void testSpaceProperties() throws Exception { + void testSpaceProperties() throws Exception { File basedir = getBasedirForBuild(); request.setBaseDirectory(basedir); Properties props = getProperties(); 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); @@ -152,12 +152,12 @@ public void testSpaceProperties() throws Exception { } @Test - public void testPomOutsideProject() throws Exception { + void testPomOutsideProject() throws Exception { File basedir = getBasedirForBuild(); 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); @@ -165,19 +165,14 @@ public void testPomOutsideProject() throws Exception { } @Test - public void testMavenWrapperInProject() throws Exception { + 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(); - request.setOutputHandler(new InvocationOutputHandler() { - @Override - public void consumeLine(String line) { - outlines.append(line); - } - }); + request.setOutputHandler(outlines::append); InvocationResult result = invoker.execute(request); 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..6d49bfc 100644 --- a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java @@ -46,9 +46,9 @@ import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assumptions.assumeTrue; -public class MavenCommandLineBuilderTest { +class MavenCommandLineBuilderTest { @TempDir - public Path temporaryFolder; + private Path temporaryFolder; private Properties sysProps; private File lrd; @@ -56,7 +56,7 @@ public class MavenCommandLineBuilderTest { private Commandline cli = new Commandline(); @BeforeEach - public void setUp() throws IOException { + void setUp() throws IOException { sysProps = System.getProperties(); Properties p = new Properties(sysProps); @@ -66,12 +66,12 @@ public void setUp() throws IOException { } @AfterEach - public void tearDown() { + void tearDown() { System.setProperties(sysProps); } @Test - public void testShouldFailToSetLocalRepoLocationGloballyWhenItIsAFile() { + void testShouldFailToSetLocalRepoLocationGloballyWhenItIsAFile() { mclb.setLocalRepositoryDirectory(lrd); @@ -83,7 +83,7 @@ public void testShouldFailToSetLocalRepoLocationGloballyWhenItIsAFile() { } @Test - public void testShouldFailToSetLocalRepoLocationFromRequestWhenItIsAFile() { + void testShouldFailToSetLocalRepoLocationFromRequestWhenItIsAFile() { InvocationRequest request = newRequest().setLocalRepositoryDirectory(lrd); try { mclb.setLocalRepository(request, cli); @@ -93,7 +93,7 @@ public void testShouldFailToSetLocalRepoLocationFromRequestWhenItIsAFile() { } @Test - public void testShouldSetLocalRepoLocationGlobally() throws IOException { + void testShouldSetLocalRepoLocationGlobally() throws IOException { File lrd = Files.createDirectory(temporaryFolder.resolve("workdir")) .toFile() .getCanonicalFile(); @@ -104,7 +104,7 @@ public void testShouldSetLocalRepoLocationGlobally() throws IOException { } @Test - public void testShouldSetLocalRepoLocationFromRequest() throws Exception { + void testShouldSetLocalRepoLocationFromRequest() throws Exception { File lrd = Files.createDirectory(temporaryFolder.resolve("workdir")) .toFile() .getCanonicalFile(); @@ -114,7 +114,7 @@ public void testShouldSetLocalRepoLocationFromRequest() throws Exception { } @Test - public void testRequestProvidedLocalRepoLocationShouldOverrideGlobal() throws Exception { + void testRequestProvidedLocalRepoLocationShouldOverrideGlobal() throws Exception { File lrd = Files.createDirectory(temporaryFolder.resolve("workdir")) .toFile() .getCanonicalFile(); @@ -129,7 +129,7 @@ public void testRequestProvidedLocalRepoLocationShouldOverrideGlobal() throws Ex } @Test - public void testShouldSetWorkingDirectoryGlobally() throws Exception { + void testShouldSetWorkingDirectoryGlobally() throws Exception { File wd = Files.createDirectory(temporaryFolder.resolve("workdir")).toFile(); mclb.setBaseDirectory(wd); @@ -139,7 +139,7 @@ public void testShouldSetWorkingDirectoryGlobally() throws Exception { } @Test - public void testShouldSetWorkingDirectoryFromRequest() throws Exception { + void testShouldSetWorkingDirectoryFromRequest() throws Exception { File wd = Files.createDirectory(temporaryFolder.resolve("workdir")).toFile(); InvocationRequest req = newRequest(); @@ -151,7 +151,7 @@ public void testShouldSetWorkingDirectoryFromRequest() throws Exception { } @Test - public void testRequestProvidedWorkingDirectoryShouldOverrideGlobal() throws Exception { + void testRequestProvidedWorkingDirectoryShouldOverrideGlobal() throws Exception { File wd = Files.createDirectory(temporaryFolder.resolve("workdir")).toFile(); File gwd = Files.createDirectory(temporaryFolder.resolve("global-workdir")).toFile(); @@ -167,7 +167,7 @@ public void testRequestProvidedWorkingDirectoryShouldOverrideGlobal() throws Exc } @Test - public void testShouldUseSystemOutLoggerWhenNoneSpecified() throws Exception { + void testShouldUseSystemOutLoggerWhenNoneSpecified() throws Exception { setupTempMavenHomeIfMissing(false); mclb.checkRequiredState(); @@ -204,7 +204,7 @@ private File setupTempMavenHomeIfMissing(boolean forceDummy) throws Exception { } @Test - public void testShouldFailIfLoggerSetToNull() { + void testShouldFailIfLoggerSetToNull() { mclb.setLogger(null); try { @@ -215,7 +215,7 @@ public void testShouldFailIfLoggerSetToNull() { } @Test - public void testShouldFindDummyMavenExecutable() throws Exception { + void testShouldFindDummyMavenExecutable() throws Exception { File dummyMavenHomeBin = Files.createDirectories(temporaryFolder .resolve("invoker-tests") .resolve("dummy-maven-home") @@ -236,7 +236,7 @@ public void testShouldFindDummyMavenExecutable() throws Exception { } @Test - public void testShouldFindDummyPS1MavenExecutable() throws Exception { + void testShouldFindDummyPS1MavenExecutable() throws Exception { File dummyMavenHomeBin = Files.createDirectories(temporaryFolder .resolve("invoker-tests") .resolve("dummy-maven-home") @@ -254,7 +254,7 @@ public void testShouldFindDummyPS1MavenExecutable() throws Exception { } @Test - public void testShouldFindDummyMavenExecutableWithMavenHomeFromRequest() throws Exception { + void testShouldFindDummyMavenExecutableWithMavenHomeFromRequest() throws Exception { File dummyMavenHomeBin = Files.createDirectories(temporaryFolder .resolve("invoker-tests") .resolve("dummy-maven-home") @@ -276,7 +276,7 @@ public void testShouldFindDummyMavenExecutableWithMavenHomeFromRequest() throws } @Test - public void testShouldSetBatchModeFlagFromRequest() { + void testShouldSetBatchModeFlagFromRequest() { mclb.setFlags(newRequest().setBatchMode(true), cli); @@ -284,7 +284,7 @@ public void testShouldSetBatchModeFlagFromRequest() { } @Test - public void testShouldSetOfflineFlagFromRequest() { + void testShouldSetOfflineFlagFromRequest() { mclb.setFlags(newRequest().setOffline(true), cli); @@ -292,7 +292,7 @@ public void testShouldSetOfflineFlagFromRequest() { } @Test - public void testShouldSetUpdateSnapshotsFlagFromRequest() { + void testShouldSetUpdateSnapshotsFlagFromRequest() { mclb.setFlags(newRequest().setUpdateSnapshots(true), cli); @@ -327,7 +327,7 @@ void testShouldSetUpdateSnapshotsPolicyNeverFromRequest() { } @Test - public void testShouldSetDebugFlagFromRequest() { + void testShouldSetDebugFlagFromRequest() { mclb.setFlags(newRequest().setDebug(true), cli); @@ -335,7 +335,7 @@ public void testShouldSetDebugFlagFromRequest() { } @Test - public void testShouldSetErrorFlagFromRequest() { + void testShouldSetErrorFlagFromRequest() { mclb.setFlags(newRequest().setShowErrors(true), cli); @@ -343,7 +343,7 @@ public void testShouldSetErrorFlagFromRequest() { } @Test - public void testShouldSetQuietFlagFromRequest() { + void testShouldSetQuietFlagFromRequest() { mclb.setFlags(newRequest().setQuiet(true), cli); @@ -351,21 +351,21 @@ public void testShouldSetQuietFlagFromRequest() { } @Test - public void testShouldSetNonRecursiveFlagsFromRequest() { + void testShouldSetNonRecursiveFlagsFromRequest() { mclb.setFlags(newRequest().setRecursive(false), cli); assertArgumentsPresent(cli, Collections.singleton("-N")); } @Test - public void testShouldSetShowVersionFlagsFromRequest() { + void testShouldSetShowVersionFlagsFromRequest() { mclb.setFlags(newRequest().setShowVersion(true), cli); assertArgumentsPresent(cli, Collections.singleton("-V")); } @Test - public void testDebugOptionShouldMaskShowErrorsOption() { + void testDebugOptionShouldMaskShowErrorsOption() { mclb.setFlags(newRequest().setDebug(true).setShowErrors(true), cli); @@ -374,14 +374,14 @@ public void testDebugOptionShouldMaskShowErrorsOption() { } @Test - public void testShouldSetBuilderIdOptionsFromRequest() { + void testShouldSetBuilderIdOptionsFromRequest() { mclb.setFlags(newRequest().setBuilder("builder-id-123"), cli); assertArgumentsPresentInOrder(cli, "-b", "builder-id-123"); } @Test - public void testAlsoMake() { + void testAlsoMake() { mclb.setReactorBehavior(newRequest().setAlsoMake(true), cli); @@ -390,7 +390,7 @@ public void testAlsoMake() { } @Test - public void testProjectsAndAlsoMake() { + void testProjectsAndAlsoMake() { mclb.setReactorBehavior( newRequest().setProjects(Collections.singletonList("proj1")).setAlsoMake(true), cli); @@ -399,7 +399,7 @@ public void testProjectsAndAlsoMake() { } @Test - public void testAlsoMakeDependents() { + void testAlsoMakeDependents() { mclb.setReactorBehavior(newRequest().setAlsoMakeDependents(true), cli); @@ -408,7 +408,7 @@ public void testAlsoMakeDependents() { } @Test - public void testProjectsAndAlsoMakeDependents() { + void testProjectsAndAlsoMakeDependents() { mclb.setReactorBehavior( newRequest().setProjects(Collections.singletonList("proj1")).setAlsoMakeDependents(true), cli); @@ -417,7 +417,7 @@ public void testProjectsAndAlsoMakeDependents() { } @Test - public void testProjectsAndAlsoMakeAndAlsoMakeDependents() { + void testProjectsAndAlsoMakeAndAlsoMakeDependents() { mclb.setReactorBehavior( newRequest() @@ -430,7 +430,7 @@ public void testProjectsAndAlsoMakeAndAlsoMakeDependents() { } @Test - public void testShouldSetResumeFrom() { + void testShouldSetResumeFrom() { mclb.setReactorBehavior(newRequest().setResumeFrom(":module3"), cli); @@ -438,7 +438,7 @@ public void testShouldSetResumeFrom() { } @Test - public void testShouldSetStrictChecksumPolityFlagFromRequest() { + void testShouldSetStrictChecksumPolityFlagFromRequest() { mclb.setFlags(newRequest().setGlobalChecksumPolicy(InvocationRequest.CheckSumPolicy.Fail), cli); @@ -446,7 +446,7 @@ public void testShouldSetStrictChecksumPolityFlagFromRequest() { } @Test - public void testShouldSetLaxChecksumPolicyFlagFromRequest() { + void testShouldSetLaxChecksumPolicyFlagFromRequest() { mclb.setFlags(newRequest().setGlobalChecksumPolicy(InvocationRequest.CheckSumPolicy.Warn), cli); @@ -454,7 +454,7 @@ public void testShouldSetLaxChecksumPolicyFlagFromRequest() { } @Test - public void testShouldSetFailAtEndFlagFromRequest() { + void testShouldSetFailAtEndFlagFromRequest() { mclb.setReactorBehavior( newRequest().setReactorFailureBehavior(InvocationRequest.ReactorFailureBehavior.FailAtEnd), cli); @@ -463,7 +463,7 @@ public void testShouldSetFailAtEndFlagFromRequest() { } @Test - public void testShouldSetFailNeverFlagFromRequest() { + void testShouldSetFailNeverFlagFromRequest() { mclb.setReactorBehavior( newRequest().setReactorFailureBehavior(InvocationRequest.ReactorFailureBehavior.FailNever), cli); @@ -472,7 +472,7 @@ public void testShouldSetFailNeverFlagFromRequest() { } @Test - public void testShouldAddArg() throws CommandLineConfigurationException { + void testShouldAddArg() throws CommandLineConfigurationException { InvocationRequest request = newRequest().addArg("arg1").addArg("arg2").setQuiet(true).setBuilder("bId"); @@ -484,7 +484,7 @@ public void testShouldAddArg() throws CommandLineConfigurationException { } @Test - public void testShouldUseDefaultOfFailFastWhenSpecifiedInRequest() { + void testShouldUseDefaultOfFailFastWhenSpecifiedInRequest() { mclb.setReactorBehavior( newRequest().setReactorFailureBehavior(InvocationRequest.ReactorFailureBehavior.FailFast), cli); @@ -497,13 +497,13 @@ public void testShouldUseDefaultOfFailFastWhenSpecifiedInRequest() { } @Test - public void testShouldSetNoTransferProgressFlagFromRequest() { + void testShouldSetNoTransferProgressFlagFromRequest() { mclb.setFlags(newRequest().setNoTransferProgress(true), cli); assertArgumentsPresent(cli, Collections.singleton("-ntp")); } @Test - public void testShouldSpecifyFileOptionUsingNonStandardPomFileLocation() throws Exception { + void testShouldSpecifyFileOptionUsingNonStandardPomFileLocation() throws Exception { File projectDir = Files.createDirectories( temporaryFolder.resolve("invoker-tests").resolve("file-option-nonstd-pom-file-location")) .toFile(); @@ -524,7 +524,7 @@ public void testShouldSpecifyFileOptionUsingNonStandardPomFileLocation() throws } @Test - public void testShouldNotSpecifyFileOptionUsingStandardPomFileLocation() throws Exception { + void testShouldNotSpecifyFileOptionUsingStandardPomFileLocation() throws Exception { File projectDir = Files.createDirectories( temporaryFolder.resolve("invoker-tests").resolve("std-pom-file-location")) .toFile(); @@ -545,7 +545,7 @@ public void testShouldNotSpecifyFileOptionUsingStandardPomFileLocation() throws } @Test - public void testShouldSetPomForOutsideWorkspace() throws Exception { + void testShouldSetPomForOutsideWorkspace() throws Exception { File projectDir = Files.createDirectories( temporaryFolder.resolve("invoker-tests").resolve("std-pom-file-location")) .toFile(); @@ -566,7 +566,7 @@ public void testShouldSetPomForOutsideWorkspace() throws Exception { } @Test - public void testShouldNotSpecifyFileOptionUsingStandardPomInBasedir() throws Exception { + void testShouldNotSpecifyFileOptionUsingStandardPomInBasedir() throws Exception { File projectDir = Files.createDirectories( temporaryFolder.resolve("invoker-tests").resolve("std-basedir-is-pom-file")) .toFile(); @@ -587,7 +587,7 @@ public void testShouldNotSpecifyFileOptionUsingStandardPomInBasedir() throws Exc } @Test - public void testShouldUseDefaultPomFileWhenBasedirSpecifiedWithoutPomFileName() throws Exception { + void testShouldUseDefaultPomFileWhenBasedirSpecifiedWithoutPomFileName() throws Exception { File projectDir = Files.createDirectories( temporaryFolder.resolve("invoker-tests").resolve("std-basedir-no-pom-filename")) .toFile(); @@ -606,7 +606,7 @@ public void testShouldUseDefaultPomFileWhenBasedirSpecifiedWithoutPomFileName() } @Test - public void testShouldSpecifyPomFileWhenBasedirSpecifiedWithPomFileName() throws Exception { + void testShouldSpecifyPomFileWhenBasedirSpecifiedWithPomFileName() throws Exception { File projectDir = Files.createDirectories( temporaryFolder.resolve("invoker-tests").resolve("std-basedir-with-pom-filename")) .toFile(); @@ -625,7 +625,7 @@ public void testShouldSpecifyPomFileWhenBasedirSpecifiedWithPomFileName() throws } @Test - public void testShouldSpecifyCustomUserSettingsLocationFromRequest() throws Exception { + void testShouldSpecifyCustomUserSettingsLocationFromRequest() throws Exception { File projectDir = Files.createDirectories( temporaryFolder.resolve("invoker-tests").resolve("custom-settings")) .toFile(); @@ -642,7 +642,7 @@ public void testShouldSpecifyCustomUserSettingsLocationFromRequest() throws Exce } @Test - public void testShouldSpecifyCustomGlobalSettingsLocationFromRequest() throws Exception { + void testShouldSpecifyCustomGlobalSettingsLocationFromRequest() throws Exception { File projectDir = Files.createDirectories( temporaryFolder.resolve("invoker-tests").resolve("custom-settings")) .toFile() @@ -660,7 +660,7 @@ public void testShouldSpecifyCustomGlobalSettingsLocationFromRequest() throws Ex } @Test - public void testShouldSpecifyCustomToolchainsLocationFromRequest() throws Exception { + void testShouldSpecifyCustomToolchainsLocationFromRequest() throws Exception { File projectDir = Files.createDirectories( temporaryFolder.resolve("invoker-tests").resolve("custom-toolchains")) .toFile(); @@ -677,7 +677,7 @@ public void testShouldSpecifyCustomToolchainsLocationFromRequest() throws Except } @Test - public void testShouldSpecifyCustomPropertyFromRequest() { + void testShouldSpecifyCustomPropertyFromRequest() { Properties properties = new Properties(); properties.setProperty("key", "value"); @@ -688,7 +688,7 @@ public void testShouldSpecifyCustomPropertyFromRequest() { } @Test - public void testShouldSpecifyCustomPropertyWithSpacesInValueFromRequest() { + void testShouldSpecifyCustomPropertyWithSpacesInValueFromRequest() { Properties properties = new Properties(); properties.setProperty("key", "value with spaces"); @@ -699,7 +699,7 @@ public void testShouldSpecifyCustomPropertyWithSpacesInValueFromRequest() { } @Test - public void testShouldSpecifyCustomPropertyWithSpacesInKeyFromRequest() { + void testShouldSpecifyCustomPropertyWithSpacesInKeyFromRequest() { Properties properties = new Properties(); properties.setProperty("key with spaces", "value with spaces"); @@ -710,7 +710,8 @@ public void testShouldSpecifyCustomPropertyWithSpacesInKeyFromRequest() { } @Test - public void testShouldSpecifySingleGoalFromRequest() throws CommandLineConfigurationException { + @SuppressWarnings("deprecation") + void testShouldSpecifySingleGoalFromRequest() throws CommandLineConfigurationException { List goals = new ArrayList<>(); goals.add("test"); @@ -721,7 +722,16 @@ public void testShouldSpecifySingleGoalFromRequest() throws CommandLineConfigura } @Test - public void testShouldSpecifyTwoGoalsFromRequest() throws CommandLineConfigurationException { + void testShouldSpecifySingleGoalFromRequestArg() throws CommandLineConfigurationException { + + mclb.setArgs(newRequest().addArg("test"), cli); + + assertArgumentsPresent(cli, Collections.singleton("test")); + } + + @Test + @SuppressWarnings("deprecation") + void testShouldSpecifyTwoGoalsFromRequest() throws CommandLineConfigurationException { List goals = new ArrayList<>(); goals.add("test"); goals.add("clean"); @@ -733,14 +743,26 @@ public void testShouldSpecifyTwoGoalsFromRequest() throws CommandLineConfigurati } @Test - public void testShouldSpecifyThreadsFromRequest() { + 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 + void testShouldSpecifyThreadsFromRequest() { mclb.setThreads(newRequest().setThreads("2.0C"), cli); assertArgumentsPresentInOrder(cli, "-T", "2.0C"); } @Test - public void testBuildTypicalMavenInvocationEndToEnd() throws Exception { + void testBuildTypicalMavenInvocationEndToEnd() throws Exception { File mavenDir = setupTempMavenHomeIfMissing(false); InvocationRequest request = newRequest(); @@ -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); @@ -793,7 +815,7 @@ public void testBuildTypicalMavenInvocationEndToEnd() throws Exception { } @Test - public void testShouldInsertActivatedProfiles() throws Exception { + void testShouldInsertActivatedProfiles() throws Exception { setupTempMavenHomeIfMissing(false); String profile1 = "profile-1"; @@ -813,7 +835,7 @@ public void testShouldInsertActivatedProfiles() throws Exception { } @Test - public void testMvnExecutableFromInvoker() throws Exception { + void testMvnExecutableFromInvoker() throws Exception { assumeTrue(Objects.nonNull(System.getProperty("maven.home")), "Test only works when maven.home is set"); File mavenExecutable = new File("mvnDebug"); @@ -827,7 +849,7 @@ public void testMvnExecutableFromInvoker() throws Exception { } @Test - public void testMvnExecutableFormRequest() throws Exception { + void testMvnExecutableFormRequest() throws Exception { assumeTrue(Objects.nonNull(System.getProperty("maven.home")), "Test only works when maven.home is set"); File mavenExecutable = new File("mvnDebug"); @@ -840,7 +862,7 @@ public void testMvnExecutableFormRequest() throws Exception { } @Test - public void testDefaultMavenCommand() throws Exception { + void testDefaultMavenCommand() throws Exception { assumeTrue(Objects.nonNull(System.getProperty("maven.home")), "Test only works when maven.home is set"); mclb.build(newRequest()); @@ -850,7 +872,7 @@ public void testDefaultMavenCommand() throws Exception { } @Test - public void testAddShellEnvironment() throws Exception { + void testAddShellEnvironment() throws Exception { setupTempMavenHomeIfMissing(false); InvocationRequest request = newRequest(); diff --git a/src/test/java/org/apache/maven/shared/invoker/SystemOutHandlerTest.java b/src/test/java/org/apache/maven/shared/invoker/SystemOutHandlerTest.java index ff80abb..cf210f5 100644 --- a/src/test/java/org/apache/maven/shared/invoker/SystemOutHandlerTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/SystemOutHandlerTest.java @@ -20,22 +20,22 @@ import org.junit.jupiter.api.Test; -public class SystemOutHandlerTest { +class SystemOutHandlerTest { @Test - public void testConsumeWithoutAlwaysFlush() { + void testConsumeWithoutAlwaysFlush() { logTestStart(); new SystemOutHandler(false).consumeLine("This is a test."); } @Test - public void testConsumeWithAlwaysFlush() { + void testConsumeWithAlwaysFlush() { logTestStart(); new SystemOutHandler(true).consumeLine("This is a test."); } @Test - public void testConsumeNullLine() { + void testConsumeNullLine() { logTestStart(); new SystemOutHandler().consumeLine(null); } diff --git a/src/test/java/org/apache/maven/shared/invoker/SystemOutLoggerTest.java b/src/test/java/org/apache/maven/shared/invoker/SystemOutLoggerTest.java index 33b781f..1b6dfff 100644 --- a/src/test/java/org/apache/maven/shared/invoker/SystemOutLoggerTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/SystemOutLoggerTest.java @@ -26,7 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -public class SystemOutLoggerTest { +class SystemOutLoggerTest { private static final Throwable EXCEPTION = new MalformedURLException("This is meant to happen. It's part of the test."); @@ -34,162 +34,162 @@ public class SystemOutLoggerTest { private static final String MESSAGE = "This is a test message."; @Test - public void testDebugWithMessageOnly() { + void testDebugWithMessageOnly() { logTestStart(); new SystemOutLogger().debug(MESSAGE); } @Test - public void testDebugWithMessageAndError() { + void testDebugWithMessageAndError() { logTestStart(); new SystemOutLogger().debug(MESSAGE, EXCEPTION); } @Test - public void testDebugWithNullMessageAndNoError() { + void testDebugWithNullMessageAndNoError() { logTestStart(); new SystemOutLogger().debug(null); } @Test - public void testDebugWithNullMessageError() { + void testDebugWithNullMessageError() { logTestStart(); new SystemOutLogger().debug(null, EXCEPTION); } @Test - public void testDebugWithMessageNullError() { + void testDebugWithMessageNullError() { logTestStart(); new SystemOutLogger().debug(MESSAGE, null); } @Test - public void testInfoWithMessageOnly() { + void testInfoWithMessageOnly() { logTestStart(); new SystemOutLogger().info(MESSAGE); } @Test - public void testInfoWithMessageAndError() { + void testInfoWithMessageAndError() { logTestStart(); new SystemOutLogger().info(MESSAGE, EXCEPTION); } @Test - public void testInfoWithNullMessageAndNoError() { + void testInfoWithNullMessageAndNoError() { logTestStart(); new SystemOutLogger().info(null); } @Test - public void testInfoWithNullMessageError() { + void testInfoWithNullMessageError() { logTestStart(); new SystemOutLogger().info(null, EXCEPTION); } @Test - public void testInfoWithMessageNullError() { + void testInfoWithMessageNullError() { logTestStart(); new SystemOutLogger().info(MESSAGE, null); } @Test - public void testWarnWithMessageOnly() { + void testWarnWithMessageOnly() { logTestStart(); new SystemOutLogger().warn(MESSAGE); } @Test - public void testWarnWithMessageAndError() { + void testWarnWithMessageAndError() { logTestStart(); new SystemOutLogger().warn(MESSAGE, EXCEPTION); } @Test - public void testWarnWithNullMessageAndNoError() { + void testWarnWithNullMessageAndNoError() { logTestStart(); new SystemOutLogger().warn(null); } @Test - public void testWarnWithNullMessageError() { + void testWarnWithNullMessageError() { logTestStart(); new SystemOutLogger().warn(null, EXCEPTION); } @Test - public void testWarnWithMessageNullError() { + void testWarnWithMessageNullError() { logTestStart(); new SystemOutLogger().warn(MESSAGE, null); } @Test - public void testErrorWithMessageOnly() { + void testErrorWithMessageOnly() { logTestStart(); new SystemOutLogger().error(MESSAGE); } @Test - public void testErrorWithMessageAndError() { + void testErrorWithMessageAndError() { logTestStart(); new SystemOutLogger().error(MESSAGE, EXCEPTION); } @Test - public void testErrorWithNullMessageAndNoError() { + void testErrorWithNullMessageAndNoError() { logTestStart(); new SystemOutLogger().error(null); } @Test - public void testErrorWithNullMessageError() { + void testErrorWithNullMessageError() { logTestStart(); new SystemOutLogger().error(null, EXCEPTION); } @Test - public void testErrorWithMessageNullError() { + void testErrorWithMessageNullError() { logTestStart(); new SystemOutLogger().error(MESSAGE, null); } @Test - public void testFatalErrorWithMessageOnly() { + void testFatalErrorWithMessageOnly() { logTestStart(); new SystemOutLogger().fatalError(MESSAGE); } @Test - public void testFatalErrorWithMessageAndError() { + void testFatalErrorWithMessageAndError() { logTestStart(); new SystemOutLogger().fatalError(MESSAGE, EXCEPTION); } @Test - public void testFatalErrorWithNullMessageAndNoError() { + void testFatalErrorWithNullMessageAndNoError() { logTestStart(); new SystemOutLogger().fatalError(null); } @Test - public void testFatalErrorWithNullMessageError() { + void testFatalErrorWithNullMessageError() { logTestStart(); new SystemOutLogger().fatalError(null, EXCEPTION); } @Test - public void testFatalErrorWithMessageNullError() { + void testFatalErrorWithMessageNullError() { logTestStart(); new SystemOutLogger().fatalError(MESSAGE, null); } @Test - public void testDefaultThresholdInfo() { + void testDefaultThresholdInfo() { assertEquals(InvokerLogger.INFO, new SystemOutLogger().getThreshold()); } @Test - public void testThresholdDebug() { + void testThresholdDebug() { InvokerLogger logger = new SystemOutLogger(); logger.setThreshold(InvokerLogger.DEBUG); assertTrue(logger.isDebugEnabled()); @@ -200,7 +200,7 @@ public void testThresholdDebug() { } @Test - public void testThresholdInfo() { + void testThresholdInfo() { InvokerLogger logger = new SystemOutLogger(); logger.setThreshold(InvokerLogger.INFO); assertFalse(logger.isDebugEnabled()); @@ -211,7 +211,7 @@ public void testThresholdInfo() { } @Test - public void testThresholdWarn() { + void testThresholdWarn() { InvokerLogger logger = new SystemOutLogger(); logger.setThreshold(InvokerLogger.WARN); assertFalse(logger.isDebugEnabled()); @@ -222,7 +222,7 @@ public void testThresholdWarn() { } @Test - public void testThresholdError() { + void testThresholdError() { InvokerLogger logger = new SystemOutLogger(); logger.setThreshold(InvokerLogger.ERROR); assertFalse(logger.isDebugEnabled()); @@ -233,7 +233,7 @@ public void testThresholdError() { } @Test - public void testThresholdFatal() { + void testThresholdFatal() { InvokerLogger logger = new SystemOutLogger(); logger.setThreshold(InvokerLogger.FATAL); assertFalse(logger.isDebugEnabled());