mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE] Удаление устаревшего TaskUtil
This commit is contained in:
parent
5446142e6a
commit
085924c831
5 changed files with 10 additions and 59 deletions
|
@ -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) {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
|
||||
List<LauncherBuildTask> 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<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
|
||||
List<LauncherBuildTask> 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<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
|
||||
addCounted(tasks, -1, pred, taskAdd);
|
||||
}
|
||||
|
||||
public static void add(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
|
||||
addCounted(tasks, 0, pred, taskAdd);
|
||||
}
|
||||
|
||||
public static void addAfter(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
|
||||
addCounted(tasks, 1, pred, taskAdd);
|
||||
}
|
||||
|
||||
public static void replacePre(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
|
||||
replaceCounted(tasks, -1, pred, taskRep);
|
||||
}
|
||||
|
||||
public static void replace(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
|
||||
replaceCounted(tasks, 0, pred, taskRep);
|
||||
}
|
||||
|
||||
public static void replaceAfter(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
|
||||
replaceCounted(tasks, 1, pred, taskRep);
|
||||
}
|
||||
|
||||
public static <T extends LauncherBuildTask> List<T> getTaskByClass(List<LauncherBuildTask> tasks, Class<T> taskClass) {
|
||||
return tasks.stream().filter(taskClass::isInstance).map(taskClass::cast).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private TaskUtil() {
|
||||
}
|
||||
}
|
|
@ -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<Path>
|
||||
|
@ -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<SignJarTask> 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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<SignJarTask> 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());
|
||||
|
|
Loading…
Reference in a new issue