修复在精简 JRE 上崩溃的问题 (#1893)

* Do not load javafx.web on unsupported platforms

* No longer requires jdk.zipfs to exist
This commit is contained in:
Glavo
2022-12-02 17:23:08 +08:00
committed by GitHub
parent 9e2c46a6f8
commit d4c0c30283
2 changed files with 22 additions and 5 deletions

View File

@@ -61,6 +61,7 @@ import java.util.List;
import java.util.*;
import java.util.concurrent.CancellationException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.stream.Collectors.toSet;
@@ -102,14 +103,26 @@ public final class SelfDependencyPatcher {
private static final Path DEPENDENCIES_DIR_PATH = HMCL_DIRECTORY.resolve("dependencies").resolve(Platform.getPlatform().toString()).resolve("openjfx");
static List<DependencyDescriptor> readDependencies() {
ArrayList<DependencyDescriptor> dependencies;
//noinspection ConstantConditions
try (Reader reader = new InputStreamReader(SelfDependencyPatcher.class.getResourceAsStream(DEPENDENCIES_LIST_FILE), UTF_8)) {
Map<String, List<DependencyDescriptor>> allDependencies =
new Gson().fromJson(reader, new TypeToken<Map<String, List<DependencyDescriptor>>>(){}.getType());
return allDependencies.get(Platform.getPlatform().toString());
Map<String, ArrayList<DependencyDescriptor>> allDependencies =
new Gson().fromJson(reader, new TypeToken<Map<String, ArrayList<DependencyDescriptor>>>(){}.getType());
dependencies = allDependencies.get(Platform.getPlatform().toString());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
try {
ClassLoader classLoader = SelfDependencyPatcher.class.getClassLoader();
Class.forName("netscape.javascript.JSObject", false, classLoader);
Class.forName("org.w3c.dom.html.HTMLDocument", false, classLoader);
} catch (Throwable e) {
LOG.log(Level.WARNING, "Disable javafx.web because JRE is incomplete", e);
dependencies.removeIf(it -> "javafx.web".equals(it.module) || "javafx.media".equals(it.module));
}
return dependencies;
}
public String module;

View File

@@ -19,6 +19,7 @@ package org.jackhuang.hmcl.util.io;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.jackhuang.hmcl.util.Lang;
import org.jackhuang.hmcl.util.platform.OperatingSystem;
import java.io.File;
@@ -43,7 +44,7 @@ public final class CompressingUtils {
private static final FileSystemProvider ZIPFS_PROVIDER = FileSystemProvider.installedProviders().stream()
.filter(it -> "jar".equalsIgnoreCase(it.getScheme()))
.findFirst()
.orElseThrow(() -> new IllegalStateException("Zipfs not supported"));
.orElse(null);
private CompressingUtils() {
}
@@ -197,6 +198,9 @@ public final class CompressingUtils {
if (useTempFile)
env.put("useTempFile", true);
try {
if (ZIPFS_PROVIDER == null)
throw new FileSystemNotFoundException("Module jdk.zipfs does not exist");
return ZIPFS_PROVIDER.newFileSystem(zipFile, env);
} catch (ZipError error) {
// Since Java 8 throws ZipError stupidly
@@ -204,7 +208,7 @@ public final class CompressingUtils {
} catch (UnsupportedOperationException ex) {
throw new ZipException("Not a zip file");
} catch (FileSystemNotFoundException ex) {
throw new ZipException("Java Environment is broken");
throw Lang.apply(new ZipException("Java Environment is broken"), it -> it.initCause(ex));
}
}