From 085924c8315eda8a5beec8e62a413ea40ae57e20 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 27 Oct 2019 23:58:44 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=83=D1=81=D1=82=D0=B0=D1=80=D0=B5=D0=B2?= =?UTF-8?q?=D1=88=D0=B5=D0=B3=D0=BE=20TaskUtil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/tasks/MainBuildTask.java | 2 +- .../binary/tasks/SignJarTask.java | 2 +- .../launchserver/binary/tasks/TaskUtil.java | 51 ------------------- .../command/service/SignDirCommand.java | 7 +-- .../command/service/SignJarCommand.java | 7 +-- 5 files changed, 10 insertions(+), 59 deletions(-) delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/TaskUtil.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index c483fae6..83946c33 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -146,7 +146,7 @@ public Path process(Path inputJar) throws IOException { }).collect(Collectors.toList()); if(!server.config.sign.enabled) { - CertificateAutogenTask task = TaskUtil.getTaskByClass(server.launcherBinary.tasks, CertificateAutogenTask.class).get(0); + CertificateAutogenTask task = server.launcherBinary.getTaskByClass(CertificateAutogenTask.class).get(); try { certificates.add(task.certificate.getEncoded()); } catch (CertificateEncodingException e) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java index 32e42e66..44eadd98 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java @@ -91,7 +91,7 @@ private void stdSign(LaunchServerConfig.JarSignerConf config, Path inputFile, Pa } private void autoSign(Path inputFile, Path signedFile) throws IOException { try (SignerJar output = new SignerJar(new ZipOutputStream(IOHelper.newOutput(signedFile)), () -> { - CertificateAutogenTask task = TaskUtil.getTaskByClass(srv.launcherBinary.tasks, CertificateAutogenTask.class).get(0); + CertificateAutogenTask task = srv.launcherBinary.getTaskByClass(CertificateAutogenTask.class).get(); return task.signedDataGenerator; }, "AUTOGEN.SF", "AUTOGEN.EC"); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/TaskUtil.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/TaskUtil.java deleted file mode 100644 index 9449952e..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/TaskUtil.java +++ /dev/null @@ -1,51 +0,0 @@ -package pro.gravit.launchserver.binary.tasks; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -public final class TaskUtil { - public static void addCounted(List tasks, int count, Predicate pred, LauncherBuildTask taskAdd) { - List indexes = new ArrayList<>(); - tasks.stream().filter(pred).forEach(indexes::add); - indexes.forEach(e -> tasks.add(tasks.indexOf(e) + count, taskAdd)); - } - - public static void replaceCounted(List tasks, int count, Predicate pred, LauncherBuildTask taskRep) { - List indexes = new ArrayList<>(); - tasks.stream().filter(pred).forEach(indexes::add); - indexes.forEach(e -> tasks.set(tasks.indexOf(e) + count, taskRep)); - } - - public static void addPre(List tasks, Predicate pred, LauncherBuildTask taskAdd) { - addCounted(tasks, -1, pred, taskAdd); - } - - public static void add(List tasks, Predicate pred, LauncherBuildTask taskAdd) { - addCounted(tasks, 0, pred, taskAdd); - } - - public static void addAfter(List tasks, Predicate pred, LauncherBuildTask taskAdd) { - addCounted(tasks, 1, pred, taskAdd); - } - - public static void replacePre(List tasks, Predicate pred, LauncherBuildTask taskRep) { - replaceCounted(tasks, -1, pred, taskRep); - } - - public static void replace(List tasks, Predicate pred, LauncherBuildTask taskRep) { - replaceCounted(tasks, 0, pred, taskRep); - } - - public static void replaceAfter(List tasks, Predicate pred, LauncherBuildTask taskRep) { - replaceCounted(tasks, 1, pred, taskRep); - } - - public static List getTaskByClass(List tasks, Class taskClass) { - return tasks.stream().filter(taskClass::isInstance).map(taskClass::cast).collect(Collectors.toList()); - } - - private TaskUtil() { - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java index 84abd7cf..3cea5b76 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java @@ -2,7 +2,6 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.binary.tasks.SignJarTask; -import pro.gravit.launchserver.binary.tasks.TaskUtil; import pro.gravit.launchserver.command.Command; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; @@ -10,6 +9,7 @@ import java.io.IOException; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; +import java.util.Optional; public class SignDirCommand extends Command { private class SignJarVisitor extends SimpleFileVisitor @@ -52,8 +52,9 @@ public void invoke(String... args) throws Exception { Path targetDir = Paths.get(args[0]); if(!IOHelper.isDir(targetDir)) throw new IllegalArgumentException(String.format("%s not directory", targetDir.toString())); - SignJarTask task = (SignJarTask) TaskUtil.getTaskByClass(server.launcherBinary.tasks, SignJarTask.class); - IOHelper.walk(targetDir, new SignJarVisitor(task), true); + Optional task = server.launcherBinary.getTaskByClass(SignJarTask.class); + if(!task.isPresent()) throw new IllegalStateException("SignJarTask not found"); + IOHelper.walk(targetDir, new SignJarVisitor(task.get()), true); LogHelper.info("Success signed"); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java index 62162f60..ce71f751 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java @@ -2,13 +2,13 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.binary.tasks.SignJarTask; -import pro.gravit.launchserver.binary.tasks.TaskUtil; import pro.gravit.launchserver.command.Command; import pro.gravit.utils.helper.LogHelper; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Optional; public class SignJarCommand extends Command { public SignJarCommand(LaunchServer server) { @@ -35,8 +35,9 @@ public void invoke(String... args) throws Exception { else tmpSign = server.dir.resolve("build").resolve(target.toFile().getName()); LogHelper.info("Signing jar %s to %s", target.toString(), tmpSign.toString()); - SignJarTask task = (SignJarTask) TaskUtil.getTaskByClass(server.launcherBinary.tasks, SignJarTask.class); - task.sign(server.config.sign, target, tmpSign); + Optional task = server.launcherBinary.getTaskByClass(SignJarTask.class); + if(!task.isPresent()) throw new IllegalStateException("SignJarTask not found"); + task.get().sign(server.config.sign, target, tmpSign); if(args.length <= 1) { LogHelper.info("Move temp jar %s to %s", tmpSign.toString(), target.toString());