From 84543b85f35fc4165e56003a149b669d516e45f3 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Wed, 11 Mar 2020 16:28:22 +0100 Subject: [PATCH] [FIX] Hikari and launch4j resolving. --- LaunchServer/build.gradle | 38 ++++++------------- .../launchserver/ASMTransformersTest.java | 24 ++++++------ 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index cf91ce83..21d39219 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -22,9 +22,8 @@ hikari pack launch4j - launch4jCJ bundleOnly.extendsFrom bundle - api.extendsFrom bundle, hikari, pack, launch4jCJ, launch4j + api.extendsFrom bundle, hikari, pack, launch4j } jar { @@ -86,7 +85,6 @@ pack project(':LauncherAPI') bundle group: 'net.sf.proguard', name: 'proguard-base', version: rootProject['verProguard'] testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: rootProject['verJunit'] - //TODO rewrite hikari 'io.micrometer:micrometer-core:1.0.6' hikari('com.zaxxer:HikariCP:3.4.1') { exclude group: 'javassist' @@ -102,14 +100,13 @@ pack project(':LauncherAPI') exclude group: 'org.slf4j' } - launch4jCJ('net.sf.launch4j:launch4j:3.12:workdir-win32') { + launch4j('net.sf.launch4j:launch4j:3.12:workdir-win32') { exclude group: '*' } - launch4jCJ('net.sf.launch4j:launch4j:3.12:workdir-linux') { + launch4j('net.sf.launch4j:launch4j:3.12:workdir-linux') { exclude group: '*' } - // Rewrite end. compileOnly group: 'com.google.guava', name: 'guava', version: rootProject['verGuavaC'] // Do not update (laggy deps). @@ -117,23 +114,24 @@ pack project(':LauncherAPI') compileOnlyA 'org.apache.logging.log4j:log4j-core:2.11.2' } -//TODO rewrite task hikari(type: Copy) { duplicatesStrategy = 'EXCLUDE' into "$buildDir/libs/libraries/hikaricp" from configurations.hikari } -task launch4jM(type: Copy) { +task launch4j(type: Copy) { duplicatesStrategy = 'EXCLUDE' into "$buildDir/libs/libraries/launch4j" - from(configurations.launch4jCJ.collect { it.isDirectory() ? it : zipTree(it) }) + from(configurations.launch4j.collect { it.isDirectory() ? it : (it.getName().contains("workdir") ? zipTree(it) : it) }) includeEmptyDirs false eachFile { FileCopyDetails fcp -> if (fcp.relativePath.pathString.startsWith("launch4j-")) { - def segments = fcp.relativePath.segments - def pathSegments = segments[1..-1] as String[] - fcp.relativePath = new RelativePath(!fcp.file.isDirectory(), pathSegments) + if (fcp.relativePath.pathString.contains("workdir")) { + def segments = fcp.relativePath.segments + def pathSegments = segments[1..-1] as String[] + fcp.relativePath = new RelativePath(!fcp.file.isDirectory(), pathSegments) + } fcp.mode = 0755 } else { fcp.exclude() @@ -141,23 +139,9 @@ task launch4jM(type: Copy) { } } -task launch4jA(type: Copy) { - duplicatesStrategy = 'EXCLUDE' - into "$buildDir/libs/libraries/launch4j" - from(configurations.launch4j) - includeEmptyDirs false - eachFile { FileCopyDetails fcp -> - if (fcp.name.startsWith("launch4j")) { - fcp.name = "launch4j.jar" - } - fcp.mode = 0755 - } -} -// Rewrite end. - task dumpLibs(type: Copy) { duplicatesStrategy = 'EXCLUDE' - dependsOn tasks.hikari, tasks.launch4jM, tasks.launch4jA //TODO rewrite this + dependsOn tasks.hikari, tasks.launch4j into "$buildDir/libs/libraries" from configurations.bundleOnly } diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java index fe27cab0..f1f620ce 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java @@ -10,6 +10,8 @@ import pro.gravit.launchserver.asm.InjectClassAcceptor; import pro.gravit.utils.helper.JarHelper; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; @@ -38,11 +40,11 @@ public static class TestClass public Map map; } @BeforeAll - public static void prepare() throws Exception { + public static void prepare() throws Throwable { classLoader = new ASMClassLoader(ASMTransformersTest.class.getClassLoader()); } @Test - void testASM() throws Exception + void testASM() throws Throwable { ClassReader reader = new ClassReader(JarHelper.getClassBytes(TestClass.class)); ClassNode node = new ClassNode(); @@ -65,15 +67,13 @@ void testASM() throws Exception byte[] bytes = writer.toByteArray(); classLoader.rawDefineClass("ASMTestClass", bytes, 0, bytes.length); Class clazz = classLoader.loadClass("ASMTestClass"); - Object instance = clazz.newInstance(); - Field field = clazz.getField("test"); - Object result = field.get(instance); - Assertions.assertEquals(1234, (int) (Integer) result); - field = clazz.getField("s"); - result = field.get(instance); - Assertions.assertEquals(strings, result); - field = clazz.getField("map"); - result = field.get(instance); - Assertions.assertEquals(byteMap, result); + Object instance = MethodHandles.publicLookup().findConstructor(clazz, MethodType.methodType(void.class)).invoke(); + Assertions.assertEquals(1234, (int) + MethodHandles.publicLookup().findGetter(clazz, "test", int.class).invoke(instance)); + Assertions.assertEquals(strings, (List) + MethodHandles.publicLookup().findGetter(clazz, "s", List.class).invoke(instance)); + + Assertions.assertEquals(byteMap, (Map) + MethodHandles.publicLookup().findGetter(clazz, "map", Map.class).invoke(instance)); } }