From cbbc601d8844d761d4a95d23185a11dc33b9b650 Mon Sep 17 00:00:00 2001 From: Joe Lauer Date: Fri, 3 Nov 2023 01:10:51 -0400 Subject: [PATCH] More tweaks to how java homes are detected --- src/main/java/com/fizzed/jne/JavaHomes.java | 13 +++++++++++++ .../mockjdks/jdk-zulu-11-arm64-musl/jmods/test.txt | 0 .../mockjdks/jdk-zulu-11-armel/jmods/test.txt | 0 .../mockjdks/jdk-zulu-11-armhf/jmods/test.txt | 0 .../resources/mockjdks/jdk-zulu-11/jmods/test.txt | 0 src/test/resources/mockjdks/jdk-zulu-8/jre/test.txt | 0 6 files changed, 13 insertions(+) create mode 100644 src/test/resources/mockjdks/jdk-zulu-11-arm64-musl/jmods/test.txt create mode 100644 src/test/resources/mockjdks/jdk-zulu-11-armel/jmods/test.txt create mode 100644 src/test/resources/mockjdks/jdk-zulu-11-armhf/jmods/test.txt create mode 100644 src/test/resources/mockjdks/jdk-zulu-11/jmods/test.txt create mode 100644 src/test/resources/mockjdks/jdk-zulu-8/jre/test.txt diff --git a/src/main/java/com/fizzed/jne/JavaHomes.java b/src/main/java/com/fizzed/jne/JavaHomes.java index 94358f2..8438bf4 100644 --- a/src/main/java/com/fizzed/jne/JavaHomes.java +++ b/src/main/java/com/fizzed/jne/JavaHomes.java @@ -72,6 +72,18 @@ static public JavaHome fromDirectory(Path javaHomeDir, boolean requireReleaseFil throw new FileNotFoundException("Java lib directory " + javaLibDir + " was not found in " + javaHomeDir); } + // Test #3: must also have jmods and/or a jre + final Path jmodsDir = javaHomeDir.resolve("jmods"); + if (!Files.isDirectory(jmodsDir)) { + final Path jreDir = javaHomeDir.resolve("jre"); + if (!Files.isDirectory(jreDir)) { + final Path rtJarFile = javaLibDir.resolve("rt.jar"); + if (!Files.exists(rtJarFile)) { + throw new FileNotFoundException("Java jmods/jre directory not found in " + javaHomeDir); + } + } + } + final String javacExeFileName = NativeTarget.resolveExecutableFileName(thisOs, "javac"); final Path _javacExeFile = javaHomeDir.resolve("bin").resolve(javacExeFileName); final Path javacExeFile; @@ -98,6 +110,7 @@ static public JavaHome fromDirectory(Path javaHomeDir, boolean requireReleaseFil if (requireReleaseFile){ throw new FileNotFoundException("Java release file " + releaseFile + " was not found in " + javaHomeDir); } + // otherwise, we could do "java -version" to try and detect it try { String versionOutput = executeJavaVersion(javaExeFile); diff --git a/src/test/resources/mockjdks/jdk-zulu-11-arm64-musl/jmods/test.txt b/src/test/resources/mockjdks/jdk-zulu-11-arm64-musl/jmods/test.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/mockjdks/jdk-zulu-11-armel/jmods/test.txt b/src/test/resources/mockjdks/jdk-zulu-11-armel/jmods/test.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/mockjdks/jdk-zulu-11-armhf/jmods/test.txt b/src/test/resources/mockjdks/jdk-zulu-11-armhf/jmods/test.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/mockjdks/jdk-zulu-11/jmods/test.txt b/src/test/resources/mockjdks/jdk-zulu-11/jmods/test.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/mockjdks/jdk-zulu-8/jre/test.txt b/src/test/resources/mockjdks/jdk-zulu-8/jre/test.txt new file mode 100644 index 0000000..e69de29