Skip to content

Commit 5ac4f80

Browse files
Environment variable Path should be used as case-insensitive
fix #438
1 parent cfb3a9f commit 5ac4f80

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/main/java/org/codehaus/mojo/exec/ExecMojo.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Iterator;
3737
import java.util.List;
3838
import java.util.Map;
39+
import java.util.Objects;
3940
import java.util.Set;
4041
import java.util.TreeSet;
4142
import java.util.function.Consumer;
@@ -488,8 +489,7 @@ private Map<String, String> handleSystemEnvVariables() throws MojoExecutionExcep
488489
}
489490

490491
if (this.getLog().isDebugEnabled()) {
491-
Set<String> keys = new TreeSet<>();
492-
keys.addAll(enviro.keySet());
492+
Set<String> keys = new TreeSet<>(enviro.keySet());
493493
for (String key : keys) {
494494
this.getLog().debug("env: " + key + "=" + enviro.get(key));
495495
}
@@ -825,10 +825,13 @@ private List<String> getExecutablePaths(Map<String, String> enviro) {
825825
List<String> paths = new ArrayList<>();
826826
paths.add("");
827827

828-
String path = enviro.get("PATH");
829-
if (path != null) {
830-
paths.addAll(Arrays.asList(StringUtils.split(path, File.pathSeparator)));
831-
}
828+
enviro.entrySet().stream()
829+
.filter(entry -> "PATH".equalsIgnoreCase(entry.getKey()))
830+
.map(Map.Entry::getValue)
831+
.filter(Objects::nonNull)
832+
.map(path -> path.split(File.pathSeparator))
833+
.map(Arrays::asList)
834+
.forEach(paths::addAll);
832835

833836
return paths;
834837
}

src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,20 @@ public void testGetExecutablePath() throws IOException {
144144

145145
final String comSpec = System.getenv("ComSpec");
146146

147+
// for windows scripts cmd should be used
147148
realMojo.setExecutable("javax.bat");
148149
cmd = realMojo.getExecutablePath(enviro, workdir);
149-
assertTrue(
150-
"is bat file on windows, execute using ComSpec.",
151-
cmd.getExecutable().equals(comSpec));
150+
assertEquals("is bat file on windows, execute using ComSpec.", comSpec, cmd.getExecutable());
151+
assertEquals("is /c argument pass using ComSpec.", "/c", cmd.getArguments()[0]);
152152

153-
enviro.put("PATH", workdir.getAbsolutePath() + File.separator + "target");
153+
String path = workdir.getAbsolutePath() + File.separator + "target";
154+
enviro.put("Path", path);
155+
realMojo.setExecutable("javax"); // FIXME javax.bat should be also allowed
154156
cmd = realMojo.getExecutablePath(enviro, workdir);
155-
assertTrue(
156-
"is bat file on windows' PATH, execute using ComSpec.",
157-
cmd.getExecutable().equals(comSpec));
157+
assertEquals("is bat file on windows, execute using ComSpec.", comSpec, cmd.getExecutable());
158+
assertEquals("is /c argument pass using ComSpec.", "/c", cmd.getArguments()[0]);
159+
assertEquals("full path is discovered.", path + File.separator + "javax.bat", cmd.getArguments()[1]);
160+
158161
f.delete();
159162
assertFalse("file deleted...", f.exists());
160163
}

0 commit comments

Comments
 (0)