From 42d3692970da4eb21e52045acf4f689ab3986f6c Mon Sep 17 00:00:00 2001 From: Stephanie Gawroriski Date: Fri, 16 Sep 2022 03:49:56 +0000 Subject: [PATCH] Try to use the current Java executable rather than whatever one is found in the system. --- .../plugin/util/SimpleJavaExecSpecFiller.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/cc/squirreljme/plugin/util/SimpleJavaExecSpecFiller.java b/buildSrc/src/main/java/cc/squirreljme/plugin/util/SimpleJavaExecSpecFiller.java index f746713092..15ac03f0bd 100644 --- a/buildSrc/src/main/java/cc/squirreljme/plugin/util/SimpleJavaExecSpecFiller.java +++ b/buildSrc/src/main/java/cc/squirreljme/plugin/util/SimpleJavaExecSpecFiller.java @@ -11,6 +11,7 @@ package cc.squirreljme.plugin.util; import cc.squirreljme.plugin.multivm.VMHelpers; import java.io.File; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -18,6 +19,7 @@ import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.gradle.internal.os.OperatingSystem; /** * This is a simple Java execution specification filler which provides the @@ -167,7 +169,24 @@ public class SimpleJavaExecSpecFiller */ private static Path __findJavaExe() { - // TODO: This is somewhere in "java.home" + String javaHomeRaw = System.getProperty("java.home"); + Path javaHome = (javaHomeRaw != null ? Paths.get(javaHomeRaw) : null); + + // Name differs per operating system + Path javaExeName; + if (OperatingSystem.current() == OperatingSystem.WINDOWS) + javaExeName = Paths.get("java.exe"); + else + javaExeName = Paths.get("java"); + + // Check to see if the Java executable exists here + Path binPath = (javaHome != null ? javaHome.resolve("bin") + .resolve(javaExeName) : null); + if (binPath != null && Files.exists(binPath) && + Files.isExecutable(binPath)) + return binPath; + + // Fallback to the system Java, assuming it exists return Paths.get("java"); } } -- 2.11.4.GIT