mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FIX] JavaVersion cache
This commit is contained in:
parent
1abab46ce4
commit
5ba36c3a1c
1 changed files with 21 additions and 1 deletions
|
@ -10,6 +10,7 @@
|
|||
import java.util.Properties;
|
||||
|
||||
public class JavaHelper {
|
||||
private static List<JavaVersion> 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<Path> paths, String moduleName, StringBu
|
|||
return false;
|
||||
}
|
||||
|
||||
public static List<JavaVersion> findJava() {
|
||||
public synchronized static List<JavaVersion> findJava() {
|
||||
if(javaVersionsCache != null) {
|
||||
return javaVersionsCache;
|
||||
}
|
||||
List<String> javaPaths = new ArrayList<>(4);
|
||||
List<JavaVersion> result = new ArrayList<>(4);
|
||||
try {
|
||||
|
@ -94,9 +98,19 @@ public static List<JavaVersion> 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<String> javaPaths, List<JavaVersion> 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)) {
|
||||
|
|
Loading…
Reference in a new issue