From 59063daed38ad28423c5978f59d24837539c419b Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Wed, 9 Jan 2019 12:29:54 +0400 Subject: [PATCH] Gradle build change. --- LaunchServer/build.gradle | 12 ++++--- .../ru/gravit/launchserver/LaunchServer.java | 5 ++- .../ru/gravit/launchserver/StarterAgent.java | 4 +-- .../binary/JARLauncherBinary.java | 31 +++++-------------- ...ckBuildTask.java => PrepareBuildTask.java} | 26 ++++++++++++++-- Launcher/build.gradle | 28 ++++++++++------- LauncherAPI/build.gradle | 8 ++--- ServerWrapper/build.gradle | 1 - .../gravit/launcher/server/ServerWrapper.java | 1 - build.gradle | 10 +++--- libLauncher/build.gradle | 2 +- modules | 2 +- 12 files changed, 72 insertions(+), 58 deletions(-) rename LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/{UnpackBuildTask.java => PrepareBuildTask.java} (54%) diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index ec76c121..383605f8 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -23,7 +23,7 @@ } jar { - dependsOn parent.childProjects.Launcher.tasks.build, parent.childProjects.Launcher.tasks.genRuntimeJS, parent.childProjects.Launcher.tasks.jar + dependsOn parent.childProjects.Launcher.tasks.build 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, @@ -60,8 +60,6 @@ pack project(':libLauncher') // pack compileOnly('net.sf.launch4j:launch4j:3.12') { // need user exclude group: '*' } - - //compile 'org.mozilla:rhino:1.7.10' will be module } task hikari(type: Copy) { @@ -75,4 +73,10 @@ task dumpLibs(type: Copy) { from configurations.bundleOnly } -build.dependsOn tasks.dumpLibs +task dumpClientLibs(type: Copy) { + dependsOn parent.childProjects.Launcher.tasks.build + into "$buildDir/libs/launcher-libraries" + from parent.childProjects.Launcher.tasks.dumpLibs.destinationDir +} + +build.dependsOn tasks.dumpLibs, tasks.dumpClientLibs diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index f219de5e..2c12a91b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -330,7 +330,10 @@ public static void main(String... args) throws Throwable { public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecException { this.dir = dir; launcherLibraries = dir.resolve("launcher-libraries"); - if (!Files.isDirectory(launcherLibraries)) Files.createDirectory(launcherLibraries); + if (!Files.isDirectory(launcherLibraries)) { + Files.deleteIfExists(launcherLibraries); + Files.createDirectory(launcherLibraries); + } this.args = Arrays.asList(args); configFile = dir.resolve("LaunchServer.conf"); publicKeyFile = dir.resolve("public.key"); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java b/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java index 9806bbc4..9f6fb300 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java @@ -12,9 +12,9 @@ import java.util.Collections; import java.util.jar.JarFile; -public class StarterAgent { +public final class StarterAgent { - public static final class StarterVisitor extends SimpleFileVisitor { + private static final class StarterVisitor extends SimpleFileVisitor { private final Instrumentation inst; private StarterVisitor(Instrumentation inst) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java index 0af66163..ba79df3d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java @@ -1,11 +1,8 @@ package ru.gravit.launchserver.binary; import java.io.IOException; -import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicLong; @@ -17,27 +14,12 @@ import ru.gravit.launchserver.binary.tasks.MainBuildTask; import ru.gravit.launchserver.binary.tasks.ProGuardBuildTask; import ru.gravit.launchserver.binary.tasks.AdditionalFixesApplyTask; -import ru.gravit.launchserver.binary.tasks.UnpackBuildTask; +import ru.gravit.launchserver.binary.tasks.PrepareBuildTask; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; public final class JARLauncherBinary extends LauncherBinary { - private static final class ListFileVisitor extends SimpleFileVisitor { - private final List lst; - - private ListFileVisitor(List lst) { - this.lst = lst; - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - if (file.toFile().getName().endsWith(".jar")) - lst.add(file); - return super.visitFile(file, attrs); - } - } - public final AtomicLong count; public final Path runtimeDir; public final Path guardDir; @@ -54,12 +36,15 @@ public JARLauncherBinary(LaunchServer server) throws IOException { buildDir = server.dir.resolve("build"); tasks = new ArrayList<>(); coreLibs = new ArrayList<>(); - Files.createDirectory(buildDir); + if (!Files.isDirectory(buildDir)) { + Files.deleteIfExists(buildDir); + Files.createDirectory(buildDir); + } } @Override public void init() { - tasks.add(new UnpackBuildTask(server)); + tasks.add(new PrepareBuildTask(server)); tasks.add(new MainBuildTask(server)); tasks.add(new ProGuardBuildTask(server)); tasks.add(new AttachJarsTask(server)); @@ -69,9 +54,7 @@ public void init() { @Override public void build() throws IOException { LogHelper.info("Building launcher binary file"); - count.set(0); - coreLibs.clear(); - IOHelper.walk(server.launcherLibraries, new ListFileVisitor(coreLibs), true); + count.set(0); // set jar number Path thisPath = null; boolean isNeedDelete = false; long time_start = System.currentTimeMillis(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/UnpackBuildTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/PrepareBuildTask.java similarity index 54% rename from LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/UnpackBuildTask.java rename to LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/PrepareBuildTask.java index 59b43d4e..61ec274c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/UnpackBuildTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/PrepareBuildTask.java @@ -6,13 +6,18 @@ import ru.gravit.utils.helper.UnpackHelper; import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.List; -public class UnpackBuildTask implements LauncherBuildTask { +public class PrepareBuildTask implements LauncherBuildTask { private final LaunchServer server; private final Path result; - public UnpackBuildTask(LaunchServer server) { + public PrepareBuildTask(LaunchServer server) { this.server = server; result = server.launcherBinary.buildDir.resolve(server.config.binaryName + "-clean.jar"); } @@ -24,6 +29,8 @@ public String getName() { @Override public Path process(Path inputFile) throws IOException { + server.launcherBinary.coreLibs.clear(); + IOHelper.walk(server.launcherLibraries, new ListFileVisitor(server.launcherBinary.coreLibs), true); UnpackHelper.unpack(IOHelper.getResourceURL("Launcher.jar"), result); tryUnpack(); return result; @@ -39,4 +46,19 @@ public void tryUnpack() throws IOException { UnpackHelper.unpackZipNoCheck("guard.zip", server.launcherBinary.guardDir); UnpackHelper.unpackZipNoCheck("runtime.zip", server.launcherBinary.runtimeDir); } + + private static final class ListFileVisitor extends SimpleFileVisitor { + private final List lst; + + private ListFileVisitor(List lst) { + this.lst = lst; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if (!Files.isDirectory(file) && file.toFile().getName().endsWith(".jar")) + lst.add(file); + return super.visitFile(file, attrs); + } + } } diff --git a/Launcher/build.gradle b/Launcher/build.gradle index b41df9a2..cb0e0c9b 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -1,19 +1,17 @@ String mainClassName = "ru.gravit.launcher.ClientLauncherWrapper" String mainAgentName = "ru.gravit.launcher.LauncherAgent" - repositories { - maven { - url "http://repo.spring.io/plugins-release/" - } + maven { + url "http://repo.spring.io/plugins-release/" + } } sourceCompatibility = '1.8' targetCompatibility = '1.8' jar { - from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } } - manifest.attributes("Main-Class": mainClassName, + manifest.attributes("Main-Class": mainClassName, "Premain-Class": mainAgentName, "Can-Redefine-Classes": "true", "Can-Retransform-Classes": "true", @@ -21,14 +19,20 @@ } dependencies { - compile project(':LauncherAPI') - compile 'com.github.oshi:oshi-core:3.11.0' + compile project(':LauncherAPI') + compile 'com.github.oshi:oshi-core:3.11.0' } task genRuntimeJS(type: Zip) { - archiveName = "runtime.zip" - destinationDir = file("${buildDir}/tmp") - from "runtime/" + archiveName = "runtime.zip" + destinationDir = file("${buildDir}/tmp") + from "runtime/" } -build.dependsOn tasks.genRuntimeJS +task dumpLibs(type: Copy) { + into "$buildDir/libs/libraries" + from configurations.runtime +} + + +build.dependsOn tasks.genRuntimeJS, tasks.dumpLibs diff --git a/LauncherAPI/build.gradle b/LauncherAPI/build.gradle index e7f413a1..102de532 100644 --- a/LauncherAPI/build.gradle +++ b/LauncherAPI/build.gradle @@ -2,8 +2,8 @@ targetCompatibility = '1.8' dependencies { - compile project(':libLauncher') - compile 'javax.websocket:javax.websocket-client-api:1.1' - compileOnly 'com.google.guava:guava:26.0-jre' - compile files('../compat/authlib/authlib-clean.jar') + compile project(':libLauncher') + compile 'javax.websocket:javax.websocket-client-api:1.1' + compileOnly 'com.google.guava:guava:26.0-jre' + compile files('../compat/authlib/authlib-clean.jar') } diff --git a/ServerWrapper/build.gradle b/ServerWrapper/build.gradle index ad5d0e30..d8996fa0 100644 --- a/ServerWrapper/build.gradle +++ b/ServerWrapper/build.gradle @@ -22,5 +22,4 @@ dependencies { compile project(':LauncherAPI') - compile 'org.javassist:javassist:3.23.1-GA' } diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java index 8fa85a88..f742962e 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -1,6 +1,5 @@ package ru.gravit.launcher.server; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; import ru.gravit.launcher.ClientPermissions; diff --git a/build.gradle b/build.gradle index 871960d4..6c9468a2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,18 @@ allprojects { apply plugin: 'eclipse' apply plugin: 'idea' - +} + +subprojects { + apply plugin: 'java' + repositories { mavenCentral() maven { url "http://clojars.org/repo/" } } -} -subprojects { - apply plugin: 'java' - configurations { apt aptCompileOnly diff --git a/libLauncher/build.gradle b/libLauncher/build.gradle index 2d77906e..0e527171 100644 --- a/libLauncher/build.gradle +++ b/libLauncher/build.gradle @@ -3,5 +3,5 @@ dependencies { compileOnly 'org.fusesource.jansi:jansi:1.17.1' - compile 'com.google.code.gson:gson:2.8.5' + compile 'com.google.code.gson:gson:2.8.5' } diff --git a/modules b/modules index f87bdf0e..5e37ef4d 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit f87bdf0e1eeed4ca097e4ab90b99b0639aa4b52a +Subproject commit 5e37ef4d9a6d001e70b4ea5c3cd837e30b692d51