Update JavaFXPatcher (#1955)
This commit is contained in:
@@ -154,23 +154,15 @@ tasks.getByName<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("sha
|
|||||||
"Add-Opens" to listOf(
|
"Add-Opens" to listOf(
|
||||||
"java.base/java.lang",
|
"java.base/java.lang",
|
||||||
"java.base/java.lang.reflect",
|
"java.base/java.lang.reflect",
|
||||||
"javafx.graphics/javafx.css",
|
"java.base/jdk.internal.loader",
|
||||||
"javafx.base/com.sun.javafx.runtime",
|
|
||||||
"javafx.controls/com.sun.javafx.scene.control.behavior",
|
|
||||||
"javafx.controls/javafx.scene.control.skin",
|
|
||||||
"javafx.controls/com.sun.javafx.scene.control",
|
|
||||||
"javafx.base/com.sun.javafx.binding",
|
"javafx.base/com.sun.javafx.binding",
|
||||||
"javafx.base/com.sun.javafx.event",
|
"javafx.base/com.sun.javafx.event",
|
||||||
"javafx.graphics/com.sun.javafx.stage"
|
"javafx.base/com.sun.javafx.runtime",
|
||||||
).joinToString(" "),
|
"javafx.graphics/javafx.css",
|
||||||
"Add-Exports" to listOf(
|
|
||||||
"java.base/jdk.internal.loader",
|
|
||||||
"javafx.controls/com.sun.javafx.scene.control.behavior",
|
|
||||||
"javafx.controls/javafx.scene.control.skin",
|
|
||||||
"javafx.controls/com.sun.javafx.scene.control",
|
|
||||||
"javafx.base/com.sun.javafx.binding",
|
|
||||||
"javafx.graphics/com.sun.javafx.stage",
|
"javafx.graphics/com.sun.javafx.stage",
|
||||||
"javafx.base/com.sun.javafx.event"
|
"javafx.controls/com.sun.javafx.scene.control",
|
||||||
|
"javafx.controls/com.sun.javafx.scene.control.behavior",
|
||||||
|
"javafx.controls/javafx.scene.control.skin"
|
||||||
).joinToString(" ")
|
).joinToString(" ")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public final class JavaFXPatcher {
|
|||||||
private JavaFXPatcher() {
|
private JavaFXPatcher() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void patch(Set<String> modules, Path... jarPaths) {
|
public static void patch(Set<String> modules, Path[] jarPaths, String[] addOpens) {
|
||||||
LOG.info("No need to patch JavaFX with Java 8");
|
LOG.info("No need to patch JavaFX with Java 8");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
import org.jackhuang.hmcl.ui.SwingUtils;
|
import org.jackhuang.hmcl.ui.SwingUtils;
|
||||||
import org.jackhuang.hmcl.util.io.ChecksumMismatchException;
|
import org.jackhuang.hmcl.util.io.ChecksumMismatchException;
|
||||||
import org.jackhuang.hmcl.util.io.IOUtils;
|
import org.jackhuang.hmcl.util.io.IOUtils;
|
||||||
|
import org.jackhuang.hmcl.util.io.JarUtils;
|
||||||
import org.jackhuang.hmcl.util.platform.Platform;
|
import org.jackhuang.hmcl.util.platform.Platform;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@@ -269,7 +270,9 @@ public final class SelfDependencyPatcher {
|
|||||||
.map(DependencyDescriptor::localPath)
|
.map(DependencyDescriptor::localPath)
|
||||||
.toArray(Path[]::new);
|
.toArray(Path[]::new);
|
||||||
|
|
||||||
JavaFXPatcher.patch(modules, jars);
|
String[] addOpens = JarUtils.getManifestAttribute("Add-Opens", "").split(" ");
|
||||||
|
|
||||||
|
JavaFXPatcher.patch(modules, jars, addOpens);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ import java.nio.file.Path;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import jdk.internal.loader.BuiltinClassLoader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility for Adding JavaFX to module path.
|
* Utility for Adding JavaFX to module path.
|
||||||
*
|
*
|
||||||
@@ -38,26 +36,6 @@ public final class JavaFXPatcher {
|
|||||||
private JavaFXPatcher() {
|
private JavaFXPatcher() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[] addOpens = {
|
|
||||||
"javafx.base/com.sun.javafx.runtime",
|
|
||||||
"javafx.base/com.sun.javafx.binding",
|
|
||||||
"javafx.base/com.sun.javafx.event",
|
|
||||||
"javafx.graphics/javafx.css",
|
|
||||||
"javafx.graphics/com.sun.javafx.stage",
|
|
||||||
"javafx.controls/com.sun.javafx.scene.control.behavior",
|
|
||||||
"javafx.controls/javafx.scene.control.skin",
|
|
||||||
"javafx.controls/com.sun.javafx.scene.control"
|
|
||||||
};
|
|
||||||
|
|
||||||
private static final String[] addExports = {
|
|
||||||
"javafx.base/com.sun.javafx.binding",
|
|
||||||
"javafx.base/com.sun.javafx.event",
|
|
||||||
"javafx.graphics/com.sun.javafx.stage",
|
|
||||||
"javafx.controls/com.sun.javafx.scene.control.behavior",
|
|
||||||
"javafx.controls/javafx.scene.control.skin",
|
|
||||||
"javafx.controls/com.sun.javafx.scene.control"
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add JavaFX to module path at runtime.
|
* Add JavaFX to module path at runtime.
|
||||||
*
|
*
|
||||||
@@ -65,13 +43,13 @@ public final class JavaFXPatcher {
|
|||||||
* @param jarPaths All jar paths
|
* @param jarPaths All jar paths
|
||||||
* @throws ReflectiveOperationException When the call to add these jars to the system module path failed.
|
* @throws ReflectiveOperationException When the call to add these jars to the system module path failed.
|
||||||
*/
|
*/
|
||||||
public static void patch(Set<String> modules, Path... jarPaths) throws ReflectiveOperationException {
|
public static void patch(Set<String> modules, Path[] jarPaths, String[] addOpens) throws ReflectiveOperationException {
|
||||||
// Find all modules
|
// Find all modules
|
||||||
ModuleFinder finder = ModuleFinder.of(jarPaths);
|
ModuleFinder finder = ModuleFinder.of(jarPaths);
|
||||||
|
|
||||||
// Load all modules as unnamed module
|
// Load all modules as unnamed module
|
||||||
for (ModuleReference mref : finder.findAll()) {
|
for (ModuleReference mref : finder.findAll()) {
|
||||||
((BuiltinClassLoader) ClassLoader.getSystemClassLoader()).loadModule(mref);
|
((jdk.internal.loader.BuiltinClassLoader) ClassLoader.getSystemClassLoader()).loadModule(mref);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define all modules
|
// Define all modules
|
||||||
@@ -82,23 +60,19 @@ public final class JavaFXPatcher {
|
|||||||
try {
|
try {
|
||||||
// Some hacks
|
// Some hacks
|
||||||
MethodHandles.Lookup lookup = MethodHandles.privateLookupIn(Module.class, MethodHandles.lookup());
|
MethodHandles.Lookup lookup = MethodHandles.privateLookupIn(Module.class, MethodHandles.lookup());
|
||||||
addExportsOrOpens(addExports, layer, lookup.findVirtual(Module.class, "implAddExportsToAllUnnamed", MethodType.methodType(void.class, String.class)));
|
MethodHandle handle = lookup.findVirtual(Module.class, "implAddOpensToAllUnnamed", MethodType.methodType(void.class, String.class));
|
||||||
addExportsOrOpens(addOpens, layer, lookup.findVirtual(Module.class, "implAddOpensToAllUnnamed", MethodType.methodType(void.class, String.class)));
|
for (String target : addOpens) {
|
||||||
|
String[] name = target.split("/", 2); // <module>/<package>
|
||||||
|
layer.findModule(name[0]).ifPresent(m -> {
|
||||||
|
try {
|
||||||
|
handle.invokeWithArguments(m, name[1]);
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
throw new RuntimeException(throwable);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
throw new ReflectiveOperationException(t);
|
throw new ReflectiveOperationException(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addExportsOrOpens(String[] targets, ModuleLayer layer, MethodHandle handle) {
|
|
||||||
for (String target : targets) {
|
|
||||||
String[] name = target.split("/", 2); // <module>/<package>
|
|
||||||
layer.findModule(name[0]).ifPresent(m -> {
|
|
||||||
try {
|
|
||||||
handle.invokeWithArguments(m, name[1]);
|
|
||||||
} catch (Throwable throwable) {
|
|
||||||
throw new RuntimeException(throwable);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user