From 18020a78d37b8a11c5285124ca1986cfd8cc579f Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 5 Jan 2019 22:28:25 +0700 Subject: [PATCH] =?UTF-8?q?LauncherBuildTask=20=D0=B2=D0=B2=D0=B5=D0=B4?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20?= =?UTF-8?q?=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D1=8B=20=D1=81=D0=B1=D0=BE?= =?UTF-8?q?=D1=80=D0=BA=D0=B8=20=D0=BB=D0=B0=D1=83=D0=BD=D1=87=D0=B5=D1=80?= =?UTF-8?q?=D0=B0=20=D0=A7=D0=B0=D1=81=D1=82=D1=8C=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launchserver/binary/JARLauncherBinary.java | 10 ++++++++-- .../launchserver/binary/tasks/LauncherBuildTask.java | 1 + .../launchserver/binary/tasks/MainBuildTask.java | 6 ++++++ .../launchserver/binary/tasks/ProGuardBuildTask.java | 5 +++++ .../launchserver/binary/tasks/UnpackBuildTask.java | 5 +++++ 5 files changed, 25 insertions(+), 2 deletions(-) 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 e4623493..80b2576c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java @@ -6,6 +6,7 @@ import java.io.ByteArrayOutputStream; 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; @@ -53,6 +54,7 @@ public JARLauncherBinary(LaunchServer server) throws IOException { tasks.add(new UnpackBuildTask()); tasks.add(new MainBuildTask()); tasks.add(new ProGuardBuildTask()); + syncBinaryFile = server.dir.resolve(server.config.binaryName + ".jar"); /*runtimeDir = server.dir.resolve(Launcher.RUNTIME_DIR); guardDir = server.dir.resolve(Launcher.GUARD_DIR); initScriptFile = runtimeDir.resolve(Launcher.INIT_SCRIPT_FILE); @@ -70,13 +72,17 @@ public void build() throws IOException { // Build launcher binary LogHelper.info("Building launcher binary file"); Path thisPath = null; + boolean isNeedDelete = false; for(LauncherBuildTask task : tasks) { LogHelper.subInfo("Task %s",task.getName()); - thisPath = task.process(thisPath); + Path oldPath = thisPath; + thisPath = task.process(oldPath); + if(isNeedDelete) Files.delete(oldPath); + isNeedDelete = task.allowDelete(); LogHelper.subInfo("Task %s processed",task.getName()); } - syncBinaryFile = thisPath; + IOHelper.move(thisPath, syncBinaryFile); LogHelper.info("Build successful"); // ProGuard diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/LauncherBuildTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/LauncherBuildTask.java index 7b730952..d8d5a9ad 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/LauncherBuildTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/LauncherBuildTask.java @@ -7,4 +7,5 @@ public interface LauncherBuildTask { String getName(); int priority(); Path process(Path inputFile) throws IOException; + boolean allowDelete(); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java index 63579297..5636b6df 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -207,6 +207,12 @@ public Path process(Path cleanJar) throws IOException { } return binaryFile; } + + @Override + public boolean allowDelete() { + return true; + } + public void tryUnpack() throws IOException { LogHelper.info("Unpacking launcher native guard files and runtime"); UnpackHelper.unpackZipNoCheck("guard.zip", guardDir); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/ProGuardBuildTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/ProGuardBuildTask.java index 9831ddc4..c3f9dd7c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/ProGuardBuildTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/ProGuardBuildTask.java @@ -36,4 +36,9 @@ public Path process(Path inputFile) throws IOException { } return server.proguardConf.outputJar; } + + @Override + public boolean allowDelete() { + return true; + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/UnpackBuildTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/UnpackBuildTask.java index aaf61a6d..8b845e05 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/UnpackBuildTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/UnpackBuildTask.java @@ -27,4 +27,9 @@ public Path process(Path inputFile) throws IOException { UnpackHelper.unpack(url, result); return result; } + + @Override + public boolean allowDelete() { + return false; + } }