mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-05-05 16:46:34 +03:00
[FEATURE] Support enableNativeAccess, fix libraries modularity
This commit is contained in:
parent
18419fcd3a
commit
e2e0ef6ea4
4 changed files with 32 additions and 3 deletions
|
@ -75,9 +75,9 @@
|
||||||
pack project(':LauncherAPI')
|
pack project(':LauncherAPI')
|
||||||
bundle group: 'me.tongfei', name: 'progressbar', version: '0.10.1'
|
bundle group: 'me.tongfei', name: 'progressbar', version: '0.10.1'
|
||||||
bundle group: 'org.fusesource.jansi', name: 'jansi', version: rootProject['verJansi']
|
bundle group: 'org.fusesource.jansi', name: 'jansi', version: rootProject['verJansi']
|
||||||
bundle group: 'org.jline', name: 'jline', version: rootProject['verJline']
|
bundle group: 'org.jline', name: 'jline-native', version: rootProject['verJline']
|
||||||
bundle group: 'org.jline', name: 'jline-reader', version: rootProject['verJline']
|
bundle group: 'org.jline', name: 'jline-reader', version: rootProject['verJline']
|
||||||
bundle group: 'org.jline', name: 'jline-terminal', version: rootProject['verJline']
|
bundle group: 'org.jline', name: 'jline-terminal-ffm', version: rootProject['verJline']
|
||||||
bundle group: 'org.bouncycastle', name: 'bcprov-jdk18on', version: rootProject['verBcpkix']
|
bundle group: 'org.bouncycastle', name: 'bcprov-jdk18on', version: rootProject['verBcpkix']
|
||||||
bundle group: 'org.bouncycastle', name: 'bcpkix-jdk18on', version: rootProject['verBcpkix']
|
bundle group: 'org.bouncycastle', name: 'bcpkix-jdk18on', version: rootProject['verBcpkix']
|
||||||
bundle group: 'org.ow2.asm', name: 'asm-commons', version: rootProject['verAsm']
|
bundle group: 'org.ow2.asm', name: 'asm-commons', version: rootProject['verAsm']
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
private static final List<String> classpathOnly = List.of("proguard", "jline", "progressbar", "kotlin");
|
private static final List<String> classpathOnly = List.of("proguard", "progressbar", "kotlin");
|
||||||
private static final String LOG4J_PROPERTY = "log4j2.configurationFile";
|
private static final String LOG4J_PROPERTY = "log4j2.configurationFile";
|
||||||
private static final String DEBUG_PROPERTY = "launchserver.main.debug";
|
private static final String DEBUG_PROPERTY = "launchserver.main.debug";
|
||||||
private static final String LIBRARIES_PROPERTY = "launchserver.dir.libraries";
|
private static final String LIBRARIES_PROPERTY = "launchserver.dir.libraries";
|
||||||
|
@ -74,6 +74,8 @@ public static void main(String[] args) throws Throwable {
|
||||||
classpath.add(IOHelper.getCodeSource(LaunchServerStarter.class));
|
classpath.add(IOHelper.getCodeSource(LaunchServerStarter.class));
|
||||||
options.moduleConf.modulePath.addAll(modulepath);
|
options.moduleConf.modulePath.addAll(modulepath);
|
||||||
options.moduleConf.modules.add("ALL-MODULE-PATH");
|
options.moduleConf.modules.add("ALL-MODULE-PATH");
|
||||||
|
options.moduleConf.enableNativeAccess.add("org.fusesource.jansi");
|
||||||
|
options.moduleConf.enableNativeAccess.add("io.netty.common");
|
||||||
ClassLoaderControl control = launch.init(classpath, "natives", options);
|
ClassLoaderControl control = launch.init(classpath, "natives", options);
|
||||||
control.clearLauncherPackages();
|
control.clearLauncherPackages();
|
||||||
control.addLauncherPackage("pro.gravit.utils.launch");
|
control.addLauncherPackage("pro.gravit.utils.launch");
|
||||||
|
|
|
@ -14,5 +14,6 @@ public static final class ModuleConf {
|
||||||
public Map<String, String> exports = new HashMap<>();
|
public Map<String, String> exports = new HashMap<>();
|
||||||
public Map<String, String> opens = new HashMap<>();
|
public Map<String, String> opens = new HashMap<>();
|
||||||
public Map<String, String> reads = new HashMap<>();
|
public Map<String, String> reads = new HashMap<>();
|
||||||
|
public List<String> enableNativeAccess = new ArrayList<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,18 @@ public class ModuleLaunch implements Launch {
|
||||||
private ModuleLayer layer;
|
private ModuleLayer layer;
|
||||||
private MethodHandles.Lookup hackLookup;
|
private MethodHandles.Lookup hackLookup;
|
||||||
private boolean disablePackageDelegateSupport;
|
private boolean disablePackageDelegateSupport;
|
||||||
|
private static final MethodHandle ENABLE_NATIVE_ACCESS;
|
||||||
|
|
||||||
|
static {
|
||||||
|
MethodHandle mh;
|
||||||
|
try {
|
||||||
|
mh = MethodHandles.lookup().findVirtual(ModuleLayer.Controller.class, "enableNativeAccess", MethodType.methodType(ModuleLayer.Controller.class, Module.class));
|
||||||
|
} catch (NoSuchMethodException | IllegalAccessException e) {
|
||||||
|
mh = null;
|
||||||
|
}
|
||||||
|
ENABLE_NATIVE_ACCESS = mh;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClassLoaderControl init(List<Path> files, String nativePath, LaunchOptions options) {
|
public ClassLoaderControl init(List<Path> files, String nativePath, LaunchOptions options) {
|
||||||
this.disablePackageDelegateSupport = options.disablePackageDelegateSupport;
|
this.disablePackageDelegateSupport = options.disablePackageDelegateSupport;
|
||||||
|
@ -120,6 +132,20 @@ public ClassLoaderControl init(List<Path> files, String nativePath, LaunchOption
|
||||||
controller.addReads(source, target);
|
controller.addReads(source, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for(var e : options.moduleConf.enableNativeAccess) {
|
||||||
|
LogHelper.dev("Enable Native Access %s", e);
|
||||||
|
Module source = layer.findModule(e).orElse(null);
|
||||||
|
if(source == null) {
|
||||||
|
throw new RuntimeException(String.format("Module %s not found", e));
|
||||||
|
}
|
||||||
|
if(ENABLE_NATIVE_ACCESS != null) {
|
||||||
|
try {
|
||||||
|
ENABLE_NATIVE_ACCESS.invoke(controller, source);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
moduleClassLoader.initializeWithLayer(layer);
|
moduleClassLoader.initializeWithLayer(layer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue