diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java index 01a1e48a..f901da42 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java @@ -10,6 +10,7 @@ import java.util.Properties; public class JavaHelper { + private static List javaVersionsCache; public static Path tryGetOpenJFXPath(Path jvmDir) { String dirName = jvmDir.getFileName().toString(); Path parent = jvmDir.getParent(); @@ -54,7 +55,10 @@ public static boolean tryAddModule(List paths, String moduleName, StringBu return false; } - public static List findJava() { + public synchronized static List findJava() { + if(javaVersionsCache != null) { + return javaVersionsCache; + } List javaPaths = new ArrayList<>(4); List result = new ArrayList<>(4); try { @@ -94,9 +98,19 @@ public static List findJava() { LogHelper.error(e); } } + javaVersionsCache = result; return result; } + private static JavaVersion tryFindJavaByPath(Path path) { + for(JavaVersion version : javaVersionsCache) { + if(version.jvmDir.equals(path)) { + return version; + } + } + return null; + } + public static boolean tryAddJava(List javaPaths, List result, JavaVersion version) throws IOException { if (version == null) return false; String path = version.jvmDir.toAbsolutePath().toString(); @@ -187,6 +201,12 @@ private static boolean isCurrentJavaSupportJavaFX() { } public static JavaVersion getByPath(Path jvmDir) throws IOException { + { + JavaVersion version = JavaHelper.tryFindJavaByPath(jvmDir); + if(version != null) { + return version; + } + } Path releaseFile = jvmDir.resolve("release"); JavaVersionAndBuild versionAndBuild; if (IOHelper.isFile(releaseFile)) {