From 82f6f5866e0711f2244b85c9186c9d966d8380c6 Mon Sep 17 00:00:00 2001 From: arlaneenalra Date: Sun, 2 Apr 2023 18:11:40 -0500 Subject: [PATCH 1/2] Look for `javac` instead of `java` There are some situations where using `bin/java` as a heuristic to find JAVA_HOME within a JDK package can result in mistakenly finding a JRE root instead. Looking for `bin/javac` fixes this since JREs do not have `javac`. This should fix https://github.com/palantir/gradle-jdks/issues/97 --- .../src/main/java/com/palantir/gradle/jdks/JdkManager.java | 2 +- .../main/java/com/palantir/gradle/jdks/SystemTools.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkManager.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkManager.java index f984e443..0a26f702 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkManager.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/JdkManager.java @@ -194,7 +194,7 @@ private Path findJavaHome(Path temporaryJdkPath) { return files.filter(file -> Files.isRegularFile(file) // macos JDKs have a `bin/java` symlink to `Contents/Home/bin/java` && !Files.isSymbolicLink(file) - && file.endsWith(Paths.get("bin", SystemTools.java()))) + && file.endsWith(Paths.get("bin", SystemTools.javac()))) .findFirst() // JAVA_HOME/bin/java .orElseThrow(() -> new RuntimeException("Failed to find java home in " + temporaryJdkPath)) diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/SystemTools.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/SystemTools.java index 9bec56db..cc05bb01 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/SystemTools.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/SystemTools.java @@ -26,6 +26,13 @@ static String java() { return "java"; } + static String javac() { + if (Os.current() == Os.WINDOWS) { + return "javac.exe"; + } + return "javac"; + } + static String keytool() { if (Os.current() == Os.WINDOWS) { return "keytool.exe"; From d5cac7f20a1ac39ca13689036494032d63a29b89 Mon Sep 17 00:00:00 2001 From: arlaneenalra Date: Fri, 6 Oct 2023 10:18:26 -0500 Subject: [PATCH 2/2] Attempt to add changelog note ... --- changelog/@unreleased/pr-184.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/@unreleased/pr-184.yml diff --git a/changelog/@unreleased/pr-184.yml b/changelog/@unreleased/pr-184.yml new file mode 100644 index 00000000..eb644985 --- /dev/null +++ b/changelog/@unreleased/pr-184.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: Use bin/javac to find JAVA_HOME instead of bin/java to avoid accidentally installing a JRE instead of a JDK. + links: + - https://github.com/palantir/gradle-jdks/pull/184