diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 76b7e832..f219de5e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -260,6 +260,8 @@ public static void main(String... args) throws Throwable { public final Path dir; + public final Path launcherLibraries; + public final List args; public final Path configFile; @@ -327,7 +329,8 @@ public static void main(String... args) throws Throwable { public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecException { this.dir = dir; - Files.createDirectories(dir); + launcherLibraries = dir.resolve("launcher-libraries"); + if (!Files.isDirectory(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 30db3252..9806bbc4 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java @@ -15,9 +15,9 @@ public class StarterAgent { public static final class StarterVisitor extends SimpleFileVisitor { - private Instrumentation inst; + private final Instrumentation inst; - public StarterVisitor(Instrumentation inst) { + private StarterVisitor(Instrumentation inst) { this.inst = 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 05f594c3..7c19e410 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java @@ -8,6 +8,7 @@ import ru.gravit.launcher.Launcher; import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.binary.tasks.AttachJarsTask; import ru.gravit.launchserver.binary.tasks.LauncherBuildTask; import ru.gravit.launchserver.binary.tasks.MainBuildTask; import ru.gravit.launchserver.binary.tasks.ProGuardBuildTask; @@ -40,6 +41,7 @@ public void init() { tasks.add(new UnpackBuildTask(server)); tasks.add(new MainBuildTask(server)); if(server.config.enabledProGuard) tasks.add(new ProGuardBuildTask(server)); + tasks.add(new AttachJarsTask(server)); if(server.config.stripLineNumbers) tasks.add(new StripLineNumbersTask(server)); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/api/AttachJarsTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AttachJarsTask.java similarity index 62% rename from LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/api/AttachJarsTask.java rename to LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AttachJarsTask.java index ab653eb4..f7eea802 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/api/AttachJarsTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AttachJarsTask.java @@ -1,19 +1,37 @@ -package ru.gravit.launchserver.binary.tasks.api; +package ru.gravit.launchserver.binary.tasks; import java.io.IOException; +import java.lang.instrument.Instrumentation; +import java.nio.file.FileVisitResult; 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.jar.JarFile; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.binary.tasks.LauncherBuildTask; import ru.gravit.utils.helper.IOHelper; public class AttachJarsTask implements LauncherBuildTask { + 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); + } + } + private final LaunchServer srv; private final List jars; private final List exclusions; @@ -40,13 +58,16 @@ public Path process(Path inputFile) throws IOException { IOHelper.transfer(input, output); e = input.getNextEntry(); } - attach(output); + List coreAttach = new ArrayList<>(); + IOHelper.walk(srv.launcherLibraries, new ListFileVisitor(coreAttach), true); + attach(output, coreAttach); + attach(output, jars); } return outputFile; } - private void attach(ZipOutputStream output) throws IOException { - for (Path p : jars) { + private void attach(ZipOutputStream output, List lst) throws IOException { + for (Path p : lst) { try (ZipInputStream input = IOHelper.newZipInput(p)) { ZipEntry e = input.getNextEntry(); while (e != null) {