Skip to content

Commit

Permalink
fix: looking for compiler executables on Windows (#1395)
Browse files Browse the repository at this point in the history
  • Loading branch information
quintesse authored Jul 7, 2022
1 parent 077422d commit b08c05b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/main/java/dev/jbang/source/builders/BaseBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,9 @@ private static String resolveInGraalVMHome(String cmd, String requestedVersion)

private static String resolveInEnv(String env, String cmd) {
if (System.getenv(env) != null) {
if (Util.isWindows()) {
cmd = cmd + ".exe";
}
return new File(System.getenv(env)).toPath().resolve("bin").resolve(cmd).toAbsolutePath().toString();
Path dir = Paths.get(System.getenv(env)).toAbsolutePath().resolve("bin");
Path cmdPath = Util.searchPath(cmd, dir.toString());
return cmdPath != null ? cmdPath.toString() : cmd;
} else {
return cmd;
}
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/dev/jbang/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -1197,14 +1197,25 @@ public static Optional<String> getSourcePackage(String content) {
/**
* Searches the locations defined by PATH for the given executable
*
* @param name The name of the executable to look for
* @param cmd The name of the executable to look for
* @return A Path to the executable, if found, null otherwise
*/
public static Path searchPath(String name) {
public static Path searchPath(String cmd) {
String envPath = System.getenv("PATH");
envPath = envPath != null ? envPath : "";
return Arrays .stream(envPath.split(File.pathSeparator))
.map(dir -> Paths.get(dir).resolve(name))
return searchPath(cmd, envPath);
}

/**
* Searches the locations defined by `paths` for the given executable
*
* @param cmd The name of the executable to look for
* @param paths A string containing the paths to search
* @return A Path to the executable, if found, null otherwise
*/
public static Path searchPath(String cmd, String paths) {
return Arrays .stream(paths.split(File.pathSeparator))
.map(dir -> Paths.get(dir).resolve(cmd))
.flatMap(Util::executables)
.filter(Util::isExecutable)
.findFirst()
Expand Down

0 comments on commit b08c05b

Please sign in to comment.