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 b6f2eb5..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"); 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 e23e804..978e0ed 100644 --- a/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java @@ -39,7 +39,7 @@ public class DefaultInvokerTest { private InvocationRequest request = new DefaultInvocationRequest(); @BeforeEach - public void setUp() throws Exception { + public void setUp() { request.setDebug(true); request.setProperties(getProperties()); } @@ -172,12 +172,7 @@ public void testMavenWrapperInProject() throws Exception { 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 00a41d4..ed26f8e 100644 --- a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java @@ -37,13 +37,15 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.OS; import org.junit.jupiter.api.io.TempDir; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assumptions.assumeTrue; public class MavenCommandLineBuilderTest { @@ -75,21 +77,15 @@ public void testShouldFailToSetLocalRepoLocationGloballyWhenItIsAFile() { mclb.setLocalRepositoryDirectory(lrd); - try { - mclb.setLocalRepository(newRequest(), cli); - fail("Should not set local repo location to point to a file."); - } catch (IllegalArgumentException expected) { - } + InvocationRequest request = newRequest(); + assertThrows(IllegalArgumentException.class, () -> mclb.setLocalRepository(request, cli)); } @Test public void testShouldFailToSetLocalRepoLocationFromRequestWhenItIsAFile() { InvocationRequest request = newRequest().setLocalRepositoryDirectory(lrd); - try { - mclb.setLocalRepository(request, cli); - fail("Should not set local repo location to point to a file."); - } catch (IllegalArgumentException expected) { - } + + assertThrows(IllegalArgumentException.class, () -> mclb.setLocalRepository(request, cli)); } @Test @@ -207,11 +203,7 @@ private File setupTempMavenHomeIfMissing(boolean forceDummy) throws Exception { public void testShouldFailIfLoggerSetToNull() { mclb.setLogger(null); - try { - mclb.checkRequiredState(); - fail("Should not allow execution to proceed when logger is missing."); - } catch (IllegalStateException expected) { - } + assertThrows(IllegalStateException.class, () -> mclb.checkRequiredState()); } @Test @@ -236,6 +228,7 @@ public void testShouldFindDummyMavenExecutable() throws Exception { } @Test + @EnabledOnOs(OS.WINDOWS) public void testShouldFindDummyPS1MavenExecutable() throws Exception { File dummyMavenHomeBin = Files.createDirectories(temporaryFolder .resolve("invoker-tests") @@ -243,14 +236,11 @@ public void testShouldFindDummyPS1MavenExecutable() throws Exception { .resolve("bin")) .toFile(); - File check; - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - check = createDummyFile(dummyMavenHomeBin, "mvn.ps1"); - mclb.setMavenHome(dummyMavenHomeBin.getParentFile()); - mclb.setupMavenExecutable(newRequest()); + File check = createDummyFile(dummyMavenHomeBin, "mvn.ps1"); + mclb.setMavenHome(dummyMavenHomeBin.getParentFile()); + mclb.setupMavenExecutable(newRequest()); - assertEquals(check.getCanonicalPath(), mclb.getMavenExecutable().getCanonicalPath()); - } + assertEquals(check.getCanonicalPath(), mclb.getMavenExecutable().getCanonicalPath()); } @Test