From 9da5191738b5f3f2db48284f92ae2da97f56b4ba Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 16 Jul 2019 02:47:07 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20CompressBuildTask=20=D1=81=D0=B6?= =?UTF-8?q?=D0=B0=D1=82=D0=B8=D0=B5=20JAR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/LaunchServer.java | 2 + .../binary/JARLauncherBinary.java | 8 +--- .../binary/tasks/CompressBuildTask.java | 43 +++++++++++++++++++ 3 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CompressBuildTask.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index d4edeee6..4c11c536 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -275,6 +275,7 @@ public static class NettyUpdatesBind { public class LauncherConf { public String guardType; public boolean attachLibraryBeforeProGuard; + public boolean compress; } public class NettyConfig { @@ -810,6 +811,7 @@ private void generateConfigIfNotExists(boolean testEnv) throws IOException { newConfig.launcher = new LauncherConf(); newConfig.launcher.guardType = "no"; + newConfig.launcher.compress = true; newConfig.genMappings = true; newConfig.enabledProGuard = true; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java index 2e7b8de5..01ecec9e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java @@ -9,12 +9,7 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.binary.tasks.AdditionalFixesApplyTask; -import pro.gravit.launchserver.binary.tasks.AttachJarsTask; -import pro.gravit.launchserver.binary.tasks.LauncherBuildTask; -import pro.gravit.launchserver.binary.tasks.MainBuildTask; -import pro.gravit.launchserver.binary.tasks.PrepareBuildTask; -import pro.gravit.launchserver.binary.tasks.ProGuardBuildTask; +import pro.gravit.launchserver.binary.tasks.*; import pro.gravit.utils.helper.CommonHelper; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; @@ -51,6 +46,7 @@ public void init() { tasks.add(new ProGuardBuildTask(server)); tasks.add(new AdditionalFixesApplyTask(server)); if (!server.config.launcher.attachLibraryBeforeProGuard) tasks.add(new AttachJarsTask(server)); + if(server.config.launcher.compress) tasks.add(new CompressBuildTask(server)); } @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CompressBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CompressBuildTask.java new file mode 100644 index 00000000..9084d05a --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CompressBuildTask.java @@ -0,0 +1,43 @@ +package pro.gravit.launchserver.binary.tasks; + +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.utils.helper.IOHelper; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.zip.Deflater; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; + +public class CompressBuildTask implements LauncherBuildTask { + public transient final LaunchServer server; + + public CompressBuildTask(LaunchServer server) { + this.server = server; + } + + @Override + public String getName() { + return "compress"; + } + + @Override + public Path process(Path inputFile) throws IOException { + Path output = server.launcherBinary.nextPath(this); + try(ZipOutputStream outputStream = new ZipOutputStream(IOHelper.newOutput(output))) + { + outputStream.setMethod(ZipOutputStream.DEFLATED); + outputStream.setLevel(Deflater.BEST_COMPRESSION); + try(ZipInputStream inputStream = IOHelper.newZipInput(inputFile)) + { + + } + } + return output; + } + + @Override + public boolean allowDelete() { + return true; + } +}