Attach jars and new adding libs system p.1

This commit is contained in:
zaxar163 2019-01-08 18:18:35 +04:00
parent 349bfc82fb
commit 81ef824b85
No known key found for this signature in database
GPG key ID: CEE900027AE098E0
4 changed files with 34 additions and 8 deletions

View file

@ -260,6 +260,8 @@ public static void main(String... args) throws Throwable {
public final Path dir;
public final Path launcherLibraries;
public final List<String> 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");

View file

@ -15,9 +15,9 @@
public class StarterAgent {
public static final class StarterVisitor extends SimpleFileVisitor<Path> {
private Instrumentation inst;
private final Instrumentation inst;
public StarterVisitor(Instrumentation inst) {
private StarterVisitor(Instrumentation inst) {
this.inst = inst;
}

View file

@ -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));
}

View file

@ -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<Path> {
private final List<Path> lst;
private ListFileVisitor(List<Path> 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<Path> jars;
private final List<String> exclusions;
@ -40,13 +58,16 @@ public Path process(Path inputFile) throws IOException {
IOHelper.transfer(input, output);
e = input.getNextEntry();
}
attach(output);
List<Path> 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<Path> lst) throws IOException {
for (Path p : lst) {
try (ZipInputStream input = IOHelper.newZipInput(p)) {
ZipEntry e = input.getNextEntry();
while (e != null) {