@@ -22,8 +22,8 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.LinkOption;
|
import java.nio.file.LinkOption;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
@@ -194,7 +194,7 @@ public final class JavaVersion implements Serializable {
|
|||||||
javaVersions = queryMacintosh();
|
javaVersions = queryMacintosh();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
javaVersions = Collections.emptyList();
|
javaVersions = new ArrayList<>();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,6 +214,7 @@ public final class JavaVersion implements Serializable {
|
|||||||
LATCH.countDown();
|
LATCH.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==== Linux ====
|
||||||
private static List<JavaVersion> queryLinux() throws IOException {
|
private static List<JavaVersion> queryLinux() throws IOException {
|
||||||
Path jvmDir = Paths.get("/usr/lib/jvm");
|
Path jvmDir = Paths.get("/usr/lib/jvm");
|
||||||
if (Files.isDirectory(jvmDir)) {
|
if (Files.isDirectory(jvmDir)) {
|
||||||
@@ -234,9 +235,11 @@ public final class JavaVersion implements Serializable {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ====
|
||||||
|
|
||||||
|
// ==== OSX ====
|
||||||
private static List<JavaVersion> queryMacintosh() throws IOException {
|
private static List<JavaVersion> queryMacintosh() throws IOException {
|
||||||
LinkedList<JavaVersion> res = new LinkedList<>();
|
List<JavaVersion> res = new ArrayList<>();
|
||||||
|
|
||||||
File currentJRE = new File("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home");
|
File currentJRE = new File("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home");
|
||||||
if (currentJRE.exists())
|
if (currentJRE.exists())
|
||||||
@@ -248,9 +251,11 @@ public final class JavaVersion implements Serializable {
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
// ====
|
||||||
|
|
||||||
|
// ==== Windows ====
|
||||||
private static List<JavaVersion> queryWindows() {
|
private static List<JavaVersion> queryWindows() {
|
||||||
LinkedList<JavaVersion> res = new LinkedList<>();
|
List<JavaVersion> res = new ArrayList<>();
|
||||||
Lang.ignoringException(() -> res.addAll(queryRegisterKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\")));
|
Lang.ignoringException(() -> res.addAll(queryRegisterKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\")));
|
||||||
Lang.ignoringException(() -> res.addAll(queryRegisterKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\")));
|
Lang.ignoringException(() -> res.addAll(queryRegisterKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\")));
|
||||||
Lang.ignoringException(() -> res.addAll(queryRegisterKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\JRE\\")));
|
Lang.ignoringException(() -> res.addAll(queryRegisterKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\JRE\\")));
|
||||||
@@ -259,7 +264,7 @@ public final class JavaVersion implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> querySubFolders(String location) throws IOException, InterruptedException {
|
private static List<String> querySubFolders(String location) throws IOException, InterruptedException {
|
||||||
List<String> res = new LinkedList<>();
|
List<String> res = new ArrayList<>();
|
||||||
String[] cmd = new String[] { "cmd", "/c", "reg", "query", location };
|
String[] cmd = new String[] { "cmd", "/c", "reg", "query", location };
|
||||||
Process process = Runtime.getRuntime().exec(cmd);
|
Process process = Runtime.getRuntime().exec(cmd);
|
||||||
process.waitFor();
|
process.waitFor();
|
||||||
@@ -273,7 +278,7 @@ public final class JavaVersion implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static List<JavaVersion> queryRegisterKey(String location) throws IOException, InterruptedException {
|
private static List<JavaVersion> queryRegisterKey(String location) throws IOException, InterruptedException {
|
||||||
List<JavaVersion> res = new LinkedList<>();
|
List<JavaVersion> res = new ArrayList<>();
|
||||||
for (String java : querySubFolders(location)) {
|
for (String java : querySubFolders(location)) {
|
||||||
String home = queryRegisterValue(java, "JavaHome");
|
String home = queryRegisterValue(java, "JavaHome");
|
||||||
if (home != null)
|
if (home != null)
|
||||||
@@ -306,4 +311,5 @@ public final class JavaVersion implements Serializable {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// ====
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user