[FEATURE][EXPERIMENTAL] Использование своего ClassLoader'а вместо системного

This commit is contained in:
Gravit 2019-12-09 00:56:16 +07:00
parent b21c8b04c3
commit 38580b23bc
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 37 additions and 4 deletions

View file

@ -53,7 +53,7 @@ task javadocJar(type: Jar) {
} }
dependencies { dependencies {
pack project(':LauncherAuthlib') pack project(':LauncherAPI')
bundle 'com.github.oshi:oshi-core:3.13.0' bundle 'com.github.oshi:oshi-core:3.13.0'
pack 'io.netty:netty-codec-http:4.1.43.Final' pack 'io.netty:netty-codec-http:4.1.43.Final'
pack 'org.ow2.asm:asm-tree:7.1' pack 'org.ow2.asm:asm-tree:7.1'

View file

@ -292,6 +292,10 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl
LogHelper.debug("Args: " + copy); LogHelper.debug("Args: " + copy);
// Resolve main class and method // Resolve main class and method
Class<?> mainClass = classLoader.loadClass(profile.getMainClass()); Class<?> mainClass = classLoader.loadClass(profile.getMainClass());
for(URL u : classLoader.getURLs())
{
LogHelper.info("ClassLoader URL: %s", u.toString());
}
MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)).asFixedArity(); MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)).asFixedArity();
Launcher.LAUNCHED.set(true); Launcher.LAUNCHED.set(true);
JVMHelper.fullGC(); JVMHelper.fullGC();
@ -468,12 +472,12 @@ public static void main(String... args) throws Throwable {
LogHelper.debug("Verifying ClientLauncher sign and classpath"); LogHelper.debug("Verifying ClientLauncher sign and classpath");
LinkedList<Path> classPath = resolveClassPathList(params.clientDir, profile.getClassPath()); LinkedList<Path> classPath = resolveClassPathList(params.clientDir, profile.getClassPath());
for (Path classpathURL : classPath) { for (Path classpathURL : classPath) {
LauncherAgent.addJVMClassPath(classpathURL.normalize().toAbsolutePath()); //LauncherAgent.addJVMClassPath(classpathURL.normalize().toAbsolutePath());
} }
profile.pushOptionalClassPath(cp -> { profile.pushOptionalClassPath(cp -> {
LinkedList<Path> optionalClassPath = resolveClassPathList(params.clientDir, cp); LinkedList<Path> optionalClassPath = resolveClassPathList(params.clientDir, cp);
for (Path classpathURL : optionalClassPath) { for (Path classpathURL : optionalClassPath) {
LauncherAgent.addJVMClassPath(classpathURL.normalize().toAbsolutePath()); //LauncherAgent.addJVMClassPath(classpathURL.normalize().toAbsolutePath());
} }
}); });
URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath()); URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath());
@ -507,6 +511,8 @@ public static void main(String... args) throws Throwable {
AuthService.uuid = params.pp.uuid; AuthService.uuid = params.pp.uuid;
ClientService.instrumentation = LauncherAgent.inst; ClientService.instrumentation = LauncherAgent.inst;
ClientService.classLoader = classLoader; ClientService.classLoader = classLoader;
classLoader.addURL(IOHelper.getCodeSource(ClientLauncher.class).toUri().toURL());
//classForName(classLoader, "com.google.common.collect.ForwardingMultimap");
ClientService.baseURLs = classpathurls; ClientService.baseURLs = classpathurls;
LogHelper.debug("Starting JVM and client WatchService"); LogHelper.debug("Starting JVM and client WatchService");
FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher(); FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher();
@ -532,6 +538,13 @@ public static void main(String... args) throws Throwable {
launch(profile, params); launch(profile, params);
} }
} }
public static void classForName(ClassLoader loader, String name)
{
try {
Class.forName(name, false, loader);
} catch (ClassNotFoundException ignored) {
}
}
private static URL[] resolveClassPath(Path clientDir, String... classPath) throws IOException { private static URL[] resolveClassPath(Path clientDir, String... classPath) throws IOException {
return resolveClassPathStream(clientDir, classPath).map(IOHelper::toURL).toArray(URL[]::new); return resolveClassPathStream(clientDir, classPath).map(IOHelper::toURL).toArray(URL[]::new);

View file

@ -1,6 +1,8 @@
package pro.gravit.utils; package pro.gravit.utils;
import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherAPI;
import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.JVMHelper;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
@ -66,7 +68,25 @@ public PublicURLClassLoader(URL[] urls, ClassLoader parent) {
@Override @Override
public String findLibrary(String name) { public String findLibrary(String name) {
return nativePath.concat(name); return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(getNativePrefix()).concat(name).concat(getNativeEx());
}
public String getNativeEx()
{
if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE)
return ".dll";
else if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX)
return ".so";
else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX)
return ".dylib";
return "";
}
public String getNativePrefix()
{
if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX)
return "lib";
else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX)
return "lib";
return "";
} }
@Override @Override