mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE][EXPERIMENTAL] JVMHelper.getBuild()
This commit is contained in:
parent
438b62b3ca
commit
e5cd39e544
3 changed files with 45 additions and 2 deletions
|
@ -29,6 +29,7 @@ public final class JVMHelper {
|
||||||
public static final Runtime RUNTIME = Runtime.getRuntime();
|
public static final Runtime RUNTIME = Runtime.getRuntime();
|
||||||
public static final ClassLoader LOADER = ClassLoader.getSystemClassLoader();
|
public static final ClassLoader LOADER = ClassLoader.getSystemClassLoader();
|
||||||
public static final int JVM_VERSION = getVersion();
|
public static final int JVM_VERSION = getVersion();
|
||||||
|
public static final int JVM_BUILD = getBuild();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
|
@ -54,6 +55,25 @@ public static int getVersion() {
|
||||||
return Integer.parseInt(version);
|
return Integer.parseInt(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getBuild() {
|
||||||
|
String version = System.getProperty("java.version");
|
||||||
|
int dot;
|
||||||
|
if (version.startsWith("1.")) {
|
||||||
|
dot = version.indexOf("_");
|
||||||
|
} else {
|
||||||
|
dot = version.lastIndexOf(".");
|
||||||
|
}
|
||||||
|
if (dot != -1) {
|
||||||
|
version = version.substring(dot + 1);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(version);
|
||||||
|
} catch (NumberFormatException exception) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static void appendVars(ProcessBuilder builder, Map<String, String> vars) {
|
public static void appendVars(ProcessBuilder builder, Map<String, String> vars) {
|
||||||
builder.environment().putAll(vars);
|
builder.environment().putAll(vars);
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,12 +170,14 @@ public static class JavaVersion {
|
||||||
public final Path jvmDir;
|
public final Path jvmDir;
|
||||||
public final int version;
|
public final int version;
|
||||||
public final int build;
|
public final int build;
|
||||||
|
public final int bitness;
|
||||||
public boolean enabledJavaFX;
|
public boolean enabledJavaFX;
|
||||||
|
|
||||||
public JavaVersion(Path jvmDir, int version) {
|
public JavaVersion(Path jvmDir, int version) {
|
||||||
this.jvmDir = jvmDir;
|
this.jvmDir = jvmDir;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.build = 0;
|
this.build = 0;
|
||||||
|
this.bitness = JVMHelper.OS_BITS;
|
||||||
this.enabledJavaFX = true;
|
this.enabledJavaFX = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,11 +185,20 @@ public JavaVersion(Path jvmDir, int version, int build, boolean enabledJavaFX) {
|
||||||
this.jvmDir = jvmDir;
|
this.jvmDir = jvmDir;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.build = build;
|
this.build = build;
|
||||||
|
this.bitness = JVMHelper.OS_BITS;
|
||||||
|
this.enabledJavaFX = enabledJavaFX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JavaVersion(Path jvmDir, int version, int build, int bitness, boolean enabledJavaFX) {
|
||||||
|
this.jvmDir = jvmDir;
|
||||||
|
this.version = version;
|
||||||
|
this.build = build;
|
||||||
|
this.bitness = bitness;
|
||||||
this.enabledJavaFX = enabledJavaFX;
|
this.enabledJavaFX = enabledJavaFX;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JavaVersion getCurrentJavaVersion() {
|
public static JavaVersion getCurrentJavaVersion() {
|
||||||
return new JavaVersion(Paths.get(System.getProperty("java.home")), JVMHelper.getVersion(), 0, isCurrentJavaSupportJavaFX());
|
return new JavaVersion(Paths.get(System.getProperty("java.home")), JVMHelper.getVersion(), JVMHelper.JVM_BUILD, JVMHelper.JVM_BITS, isCurrentJavaSupportJavaFX());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isCurrentJavaSupportJavaFX() {
|
private static boolean isCurrentJavaSupportJavaFX() {
|
||||||
|
@ -212,14 +223,21 @@ public static JavaVersion getByPath(Path jvmDir) throws IOException {
|
||||||
}
|
}
|
||||||
Path releaseFile = jvmDir.resolve("release");
|
Path releaseFile = jvmDir.resolve("release");
|
||||||
JavaVersionAndBuild versionAndBuild;
|
JavaVersionAndBuild versionAndBuild;
|
||||||
|
int bitness = JVMHelper.OS_BITS;
|
||||||
if (IOHelper.isFile(releaseFile)) {
|
if (IOHelper.isFile(releaseFile)) {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.load(IOHelper.newReader(releaseFile));
|
properties.load(IOHelper.newReader(releaseFile));
|
||||||
versionAndBuild = getJavaVersion(properties.getProperty("JAVA_VERSION").replaceAll("\"", ""));
|
versionAndBuild = getJavaVersion(properties.getProperty("JAVA_VERSION").replaceAll("\"", ""));
|
||||||
|
String arch = properties.getProperty("JAVA_VERSION").replaceAll("\"", "");
|
||||||
|
if (arch.contains("x86_64")) {
|
||||||
|
bitness = 64;
|
||||||
|
} else if (arch.contains("x86") || arch.contains("x32")) {
|
||||||
|
bitness = 32;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
versionAndBuild = new JavaVersionAndBuild(isExistExtJavaLibrary(jvmDir, "jfxrt") ? 8 : 9, 0);
|
versionAndBuild = new JavaVersionAndBuild(isExistExtJavaLibrary(jvmDir, "jfxrt") ? 8 : 9, 0);
|
||||||
}
|
}
|
||||||
JavaVersion resultJavaVersion = new JavaVersion(jvmDir, versionAndBuild.version, versionAndBuild.build, false);
|
JavaVersion resultJavaVersion = new JavaVersion(jvmDir, versionAndBuild.version, versionAndBuild.build, bitness, false);
|
||||||
if (versionAndBuild.version <= 8) {
|
if (versionAndBuild.version <= 8) {
|
||||||
resultJavaVersion.enabledJavaFX = isExistExtJavaLibrary(jvmDir, "jfxrt");
|
resultJavaVersion.enabledJavaFX = isExistExtJavaLibrary(jvmDir, "jfxrt");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -29,6 +29,7 @@ public final class JVMHelper {
|
||||||
public static final Runtime RUNTIME = Runtime.getRuntime();
|
public static final Runtime RUNTIME = Runtime.getRuntime();
|
||||||
public static final ClassLoader LOADER = ClassLoader.getSystemClassLoader();
|
public static final ClassLoader LOADER = ClassLoader.getSystemClassLoader();
|
||||||
public static final int JVM_VERSION = getVersion();
|
public static final int JVM_VERSION = getVersion();
|
||||||
|
public static final int JVM_BUILD = getBuild();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
|
@ -46,6 +47,10 @@ public static int getVersion() {
|
||||||
return Runtime.version().feature();
|
return Runtime.version().feature();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getBuild() {
|
||||||
|
return Runtime.version().patch();
|
||||||
|
}
|
||||||
|
|
||||||
public static void appendVars(ProcessBuilder builder, Map<String, String> vars) {
|
public static void appendVars(ProcessBuilder builder, Map<String, String> vars) {
|
||||||
builder.environment().putAll(vars);
|
builder.environment().putAll(vars);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue