diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index 9d6df28f..1e52008a 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -17,13 +17,14 @@ bundleOnly bundle hikari - bundle.extendsFrom bundleOnly - compileOnly.extendsFrom bundle, hikari + pack + bundleOnly.extendsFrom bundle + compile.extendsFrom bundle, hikari, pack } jar { dependsOn parent.childProjects.Launcher.tasks.build, parent.childProjects.Launcher.tasks.genRuntimeJS, parent.childProjects.Launcher.tasks.jar - from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } } + from { configurations.pack.collect { it.isDirectory() ? it : zipTree(it) } } from(parent.childProjects.Launcher.tasks.jar.archivePath, parent.childProjects.Launcher.tasks.genRuntimeJS.archivePath) manifest.attributes("Main-Class": mainClassName, "Premain-Class": mainAgentName, @@ -34,7 +35,7 @@ } dependencies { - compile project(':libLauncher') // pack + pack project(':libLauncher') // pack bundle 'org.ow2.asm:asm-commons:7.0' bundle 'org.ow2.asm:asm-util:7.0' bundle 'mysql:mysql-connector-java:8.0.12' @@ -70,7 +71,7 @@ task hikari(type: Copy) { task dumpLibs(type: Copy) { dependsOn tasks.hikari into "$buildDir/libs/libraries" - from configurations.bundle + from configurations.bundleOnly } build.dependsOn tasks.dumpLibs diff --git a/Launcher/build.gradle b/Launcher/build.gradle index 7521000f..b41df9a2 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -22,8 +22,7 @@ dependencies { compile project(':LauncherAPI') - compile 'org.javassist:javassist:3.23.1-GA' - compile group: 'com.github.oshi', name: 'oshi-core', version: '3.11.0' + compile 'com.github.oshi:oshi-core:3.11.0' } task genRuntimeJS(type: Zip) { diff --git a/libLauncher/build.gradle b/libLauncher/build.gradle index 41b686dd..2d77906e 100644 --- a/libLauncher/build.gradle +++ b/libLauncher/build.gradle @@ -3,6 +3,5 @@ dependencies { compileOnly 'org.fusesource.jansi:jansi:1.17.1' - compileOnly 'org.javassist:javassist:3.23.1-GA' compile 'com.google.code.gson:gson:2.8.5' } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java index ba4b128b..6ee80895 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java @@ -2,17 +2,12 @@ import java.io.IOException; import java.lang.instrument.Instrumentation; -import java.lang.instrument.UnmodifiableClassException; -import java.util.ArrayList; import java.util.jar.JarFile; -import javassist.bytecode.ClassFile; -import ru.gravit.launcher.transformers.SystemClassLoaderTransformer; import ru.gravit.utils.helper.LogHelper; @LauncherAPI public class LauncherAgent { - private static final boolean enabled = false; private static boolean isAgentStarted = false; public static Instrumentation inst; @@ -33,22 +28,6 @@ public static void premain(String agentArgument, Instrumentation instrumentation System.out.println("Launcher Agent"); inst = instrumentation; isAgentStarted = true; - - if (ClassFile.MAJOR_VERSION > ClassFile.JAVA_8 || enabled) { - inst.addTransformer(new SystemClassLoaderTransformer()); - Class[] classes = inst.getAllLoadedClasses(); // Получаем список уже загруженных классов, которые могут быть изменены. Классы, которые ещё не загружены, будут изменены при загрузке - ArrayList> classList = new ArrayList<>(); - for (Class classe : classes) - if (inst.isModifiableClass(classe)) - classList.add(classe); - // Reload classes, if possible. - Class[] workaround = new Class[classList.size()]; - try { - inst.retransformClasses(classList.toArray(workaround)); // Запускаем процесс трансформации - } catch (UnmodifiableClassException e) { - System.err.println("MainClass was unable to retransform early loaded classes: " + e); - } - } } public static boolean isStarted() { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/NeedGarbageCollection.java b/libLauncher/src/main/java/ru/gravit/launcher/NeedGarbageCollection.java index a2b5f567..04c69b14 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/NeedGarbageCollection.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/NeedGarbageCollection.java @@ -1,6 +1,5 @@ package ru.gravit.launcher; - @FunctionalInterface public interface NeedGarbageCollection { void garbageCollection(); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/transformers/SystemClassLoaderTransformer.java b/libLauncher/src/main/java/ru/gravit/launcher/transformers/SystemClassLoaderTransformer.java deleted file mode 100644 index ec76f96e..00000000 --- a/libLauncher/src/main/java/ru/gravit/launcher/transformers/SystemClassLoaderTransformer.java +++ /dev/null @@ -1,49 +0,0 @@ -package ru.gravit.launcher.transformers; - -import java.io.ByteArrayInputStream; -import java.lang.instrument.ClassFileTransformer; -import java.security.ProtectionDomain; - -import javassist.ClassPool; -import javassist.CodeConverter; -import javassist.CtClass; -import javassist.CtConstructor; -import javassist.CtMethod; -import javassist.LoaderClassPath; -import ru.gravit.utils.PublicURLClassLoader; - -public class SystemClassLoaderTransformer implements ClassFileTransformer { - @Override - public byte[] transform(ClassLoader classLoader, String classname, Class aClass, ProtectionDomain protectionDomain, byte[] bytes) { - if (classname.startsWith("ru/gravit/launcher/")) return bytes; - if (classname.startsWith("java/")) return bytes; - if (classname.startsWith("sun/")) return bytes; - if (classname.startsWith("com/sun/")) return bytes; - if (classname.startsWith("javax/")) return bytes; - if (classname.startsWith("jdk/")) return bytes; - try { - ClassPool pool = ClassPool.getDefault(); - pool.appendClassPath(new LoaderClassPath(PublicURLClassLoader.systemclassloader)); - pool.appendClassPath(new LoaderClassPath(classLoader)); - CtClass s1 = pool.get("java.lang.ClassLoader"); - CtMethod m11 = s1.getDeclaredMethod("getSystemClassLoader"); // Находим метод, который нам нужно заменить - CtClass s2 = pool.get(PublicURLClassLoader.class.getName()); - CtMethod m21 = s2.getDeclaredMethod("getSystemClassLoader"); // Находим метод, на который мы будем заменять - CodeConverter cc = new CodeConverter(); - cc.redirectMethodCall(m11, m21); // Указываем что на что нам нужно заменить - - CtClass cl = pool.makeClass(new ByteArrayInputStream(bytes), false); // Загружаем класс, переданный для трансформации - if (cl.isFrozen()) return null; - CtConstructor[] constructors = cl.getConstructors(); // Находим все конструкторы класса - for (CtConstructor constructor : constructors) - constructor.instrument(cc); // Заменяем вызовы - CtMethod[] methods = cl.getDeclaredMethods(); // Находим все методы класса - for (CtMethod method : methods) - method.instrument(cc); // Заменяем вызовы - return cl.toBytecode(); - } catch (Exception ignored) { - - } - return bytes; - } -}