diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java index 1f7a9cc9..732c3e40 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java @@ -11,7 +11,10 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.file.Path; +import java.util.List; +import java.util.function.Predicate; import java.util.jar.JarFile; +import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; @@ -31,13 +34,33 @@ public String getName() { @Override public Path process(Path inputFile) throws IOException { Path out = server.launcherBinary.nextPath("post-fixed"); - try (ClassMetadataReader reader = new ClassMetadataReader()) { + try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(out))) { + apply(inputFile, inputFile, output, server, (e) -> false); + } + return out; + } + + public static void apply(Path inputFile, Path addFile, ZipOutputStream output, LaunchServer srv, Predicate excluder) throws IOException { + try (ClassMetadataReader reader = new ClassMetadataReader()) { reader.getCp().add(new JarFile(inputFile.toFile())); - try (ZipInputStream input = IOHelper.newZipInput(inputFile); - ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(out))) { + List libs = srv.launcherBinary.coreLibs.stream().map(e -> { + try { + return new JarFile(e.toFile()); + } catch (IOException e1) { + throw new RuntimeException(e1); + } + }).collect(Collectors.toList()); + libs.addAll(srv.launcherBinary.addonLibs.stream().map(e -> { + try { + return new JarFile(e.toFile()); + } catch (IOException e1) { + throw new RuntimeException(e1); + } + }).collect(Collectors.toList())); + try (ZipInputStream input = IOHelper.newZipInput(addFile)) { ZipEntry e = input.getNextEntry(); while (e != null) { - if (e.isDirectory()) { + if (e.isDirectory() || excluder.test(e)) { e = input.getNextEntry(); continue; } @@ -49,14 +72,13 @@ public Path process(Path inputFile) throws IOException { IOHelper.transfer(input, outputStream); bytes = outputStream.toByteArray(); } - output.write(classFix(bytes, reader, server.config.stripLineNumbers)); + output.write(classFix(bytes, reader, srv.config.stripLineNumbers)); } else IOHelper.transfer(input, output); e = input.getNextEntry(); } } } - return out; } private static byte[] classFix(byte[] bytes, ClassMetadataReader reader, boolean stripNumbers) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AttachJarsTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AttachJarsTask.java index 1c10ee28..90b69574 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AttachJarsTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AttachJarsTask.java @@ -44,26 +44,16 @@ public Path process(Path inputFile) throws IOException { IOHelper.transfer(input, output); e = input.getNextEntry(); } - attach(output, srv.launcherBinary.coreLibs); - attach(output, jars); + attach(output, inputFile, srv.launcherBinary.coreLibs); + attach(output, inputFile, jars); } return outputFile; } - private void attach(ZipOutputStream output, List lst) throws IOException { + private void attach(ZipOutputStream output, Path inputFile, List lst) throws IOException { for (Path p : lst) { LogHelper.debug("Attaching: " + p); - try (ZipInputStream input = IOHelper.newZipInput(p)) { - ZipEntry e = input.getNextEntry(); - while (e != null) { - String filename = e.getName(); - if (exclusions.stream().noneMatch(filename::startsWith) && !e.isDirectory()) { - output.putNextEntry(IOHelper.newZipEntry(e)); - IOHelper.transfer(input, output); - } - e = input.getNextEntry(); - } - } + AdditionalFixesApplyTask.apply(inputFile, p, output, srv, (e) -> exclusions.stream().anyMatch(e.getName()::startsWith)); } } 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 e7e9de06..06d60a01 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,7 +207,7 @@ public Path process(Path inputJar) throws IOException { jaConfigurator.compile(); output.write(jaConfigurator.getBytecode()); } catch (CannotCompileException | NotFoundException e) { - LogHelper.error(e); + throw new IOException(e); } reader.close(); return outputJar;