diff --git a/src/main/java/org/codehaus/mojo/exec/ExecMojo.java b/src/main/java/org/codehaus/mojo/exec/ExecMojo.java index 8d2f9bb5..740fb301 100644 --- a/src/main/java/org/codehaus/mojo/exec/ExecMojo.java +++ b/src/main/java/org/codehaus/mojo/exec/ExecMojo.java @@ -36,6 +36,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.TreeSet; import java.util.function.Consumer; @@ -488,8 +489,7 @@ private Map handleSystemEnvVariables() throws MojoExecutionExcep } if (this.getLog().isDebugEnabled()) { - Set keys = new TreeSet<>(); - keys.addAll(enviro.keySet()); + Set keys = new TreeSet<>(enviro.keySet()); for (String key : keys) { this.getLog().debug("env: " + key + "=" + enviro.get(key)); } @@ -825,10 +825,13 @@ private List getExecutablePaths(Map enviro) { List paths = new ArrayList<>(); paths.add(""); - String path = enviro.get("PATH"); - if (path != null) { - paths.addAll(Arrays.asList(StringUtils.split(path, File.pathSeparator))); - } + enviro.entrySet().stream() + .filter(entry -> "PATH".equalsIgnoreCase(entry.getKey())) + .map(Map.Entry::getValue) + .filter(Objects::nonNull) + .map(path -> path.split(File.pathSeparator)) + .map(Arrays::asList) + .forEach(paths::addAll); return paths; } diff --git a/src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java b/src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java index 3a0773a2..43b24eeb 100644 --- a/src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java +++ b/src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java @@ -149,12 +149,15 @@ public void testGetExecutablePath() throws IOException { assertTrue( "is bat file on windows, execute using ComSpec.", cmd.getExecutable().equals(comSpec)); + assertTrue("is /c argument pass using ComSpec.", cmd.getArguments()[0].equals("/c")); enviro.put("PATH", workdir.getAbsolutePath() + File.separator + "target"); cmd = realMojo.getExecutablePath(enviro, workdir); assertTrue( "is bat file on windows' PATH, execute using ComSpec.", cmd.getExecutable().equals(comSpec)); + assertTrue("is /c argument pass using ComSpec.", cmd.getArguments()[0].equals("/c")); + f.delete(); assertFalse("file deleted...", f.exists()); }