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; + } }