Fix: not recognizing java 12

This commit is contained in:
huanghongxun 2019-09-29 18:46:03 +08:00
parent d4155bc14d
commit 993ce660aa
3 changed files with 11 additions and 15 deletions

View File

@ -303,7 +303,7 @@ public final class LauncherHelper {
} }
// LaunchWrapper 1.12 will crash because of assuming the system class loader is an instance of URLClassLoader. // LaunchWrapper 1.12 will crash because of assuming the system class loader is an instance of URLClassLoader.
if (!flag && java.getParsedVersion() >= JavaVersion.JAVA_9 if (!flag && java.getParsedVersion() >= JavaVersion.JAVA_9_AND_LATER
&& version.getMainClass().contains("launchwrapper") && version.getMainClass().contains("launchwrapper")
&& version.getLibraries().stream() && version.getLibraries().stream()
.filter(library -> "launchwrapper".equals(library.getArtifactId())) .filter(library -> "launchwrapper".equals(library.getArtifactId()))

View File

@ -206,7 +206,7 @@ public class DefaultLauncher extends Launcher {
} }
private final Map<String, Supplier<Boolean>> forbiddens = mapOf( private final Map<String, Supplier<Boolean>> forbiddens = mapOf(
pair("-Xincgc", () -> options.getJava().getParsedVersion() >= JavaVersion.JAVA_9) pair("-Xincgc", () -> options.getJava().getParsedVersion() >= JavaVersion.JAVA_9_AND_LATER)
); );
protected Map<String, Supplier<Boolean>> getForbiddens() { protected Map<String, Supplier<Boolean>> getForbiddens() {

View File

@ -17,6 +17,7 @@
*/ */
package org.jackhuang.hmcl.util.platform; package org.jackhuang.hmcl.util.platform;
import org.jackhuang.hmcl.util.Lang;
import org.jackhuang.hmcl.util.StringUtils; import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.versioning.VersionNumber; import org.jackhuang.hmcl.util.versioning.VersionNumber;
@ -76,9 +77,6 @@ public final class JavaVersion {
/** /**
* The major version of Java installation. * The major version of Java installation.
* *
* @see org.jackhuang.hmcl.util.platform.JavaVersion#JAVA_11
* @see org.jackhuang.hmcl.util.platform.JavaVersion#JAVA_10
* @see org.jackhuang.hmcl.util.platform.JavaVersion#JAVA_9
* @see org.jackhuang.hmcl.util.platform.JavaVersion#JAVA_8 * @see org.jackhuang.hmcl.util.platform.JavaVersion#JAVA_8
* @see org.jackhuang.hmcl.util.platform.JavaVersion#JAVA_7 * @see org.jackhuang.hmcl.util.platform.JavaVersion#JAVA_7
* @see org.jackhuang.hmcl.util.platform.JavaVersion#UNKNOWN * @see org.jackhuang.hmcl.util.platform.JavaVersion#UNKNOWN
@ -88,22 +86,20 @@ public final class JavaVersion {
} }
private static final Pattern REGEX = Pattern.compile("version \"(?<version>(.*?))\""); private static final Pattern REGEX = Pattern.compile("version \"(?<version>(.*?))\"");
private static final Pattern VERSION = Pattern.compile("^(?<version>[0-9]+)");
public static final int UNKNOWN = -1; public static final int UNKNOWN = -1;
public static final int JAVA_7 = 70; public static final int JAVA_7 = 70;
public static final int JAVA_8 = 80; public static final int JAVA_8 = 80;
public static final int JAVA_9 = 90; public static final int JAVA_9_AND_LATER = 90;
public static final int JAVA_10 = 100;
public static final int JAVA_11 = 110;
private static int parseVersion(String version) { private static int parseVersion(String version) {
if (version.startsWith("11")) Matcher matcher = VERSION.matcher(version);
return JAVA_11; if (matcher.find()) {
else if (version.startsWith("10")) int head = Lang.parseInt(matcher.group(), -1);
return JAVA_10; if (head > 1) return JAVA_9_AND_LATER;
else if (version.startsWith("9")) }
return JAVA_9; if (version.contains("1.8"))
else if (version.contains("1.8"))
return JAVA_8; return JAVA_8;
else if (version.contains("1.7")) else if (version.contains("1.7"))
return JAVA_7; return JAVA_7;