mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-05 07:52:01 +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());
|
}).collect(Collectors.toList());
|
||||||
if(!server.config.sign.enabled)
|
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 {
|
try {
|
||||||
certificates.add(task.certificate.getEncoded());
|
certificates.add(task.certificate.getEncoded());
|
||||||
} catch (CertificateEncodingException e) {
|
} 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 {
|
private void autoSign(Path inputFile, Path signedFile) throws IOException {
|
||||||
try (SignerJar output = new SignerJar(new ZipOutputStream(IOHelper.newOutput(signedFile)), () -> {
|
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;
|
return task.signedDataGenerator;
|
||||||
},
|
},
|
||||||
"AUTOGEN.SF", "AUTOGEN.EC");
|
"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.LaunchServer;
|
||||||
import pro.gravit.launchserver.binary.tasks.SignJarTask;
|
import pro.gravit.launchserver.binary.tasks.SignJarTask;
|
||||||
import pro.gravit.launchserver.binary.tasks.TaskUtil;
|
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
@ -10,6 +9,7 @@
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class SignDirCommand extends Command {
|
public class SignDirCommand extends Command {
|
||||||
private class SignJarVisitor extends SimpleFileVisitor<Path>
|
private class SignJarVisitor extends SimpleFileVisitor<Path>
|
||||||
|
@ -52,8 +52,9 @@ public void invoke(String... args) throws Exception {
|
||||||
Path targetDir = Paths.get(args[0]);
|
Path targetDir = Paths.get(args[0]);
|
||||||
if(!IOHelper.isDir(targetDir))
|
if(!IOHelper.isDir(targetDir))
|
||||||
throw new IllegalArgumentException(String.format("%s not directory", targetDir.toString()));
|
throw new IllegalArgumentException(String.format("%s not directory", targetDir.toString()));
|
||||||
SignJarTask task = (SignJarTask) TaskUtil.getTaskByClass(server.launcherBinary.tasks, SignJarTask.class);
|
Optional<SignJarTask> task = server.launcherBinary.getTaskByClass(SignJarTask.class);
|
||||||
IOHelper.walk(targetDir, new SignJarVisitor(task), true);
|
if(!task.isPresent()) throw new IllegalStateException("SignJarTask not found");
|
||||||
|
IOHelper.walk(targetDir, new SignJarVisitor(task.get()), true);
|
||||||
LogHelper.info("Success signed");
|
LogHelper.info("Success signed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.binary.tasks.SignJarTask;
|
import pro.gravit.launchserver.binary.tasks.SignJarTask;
|
||||||
import pro.gravit.launchserver.binary.tasks.TaskUtil;
|
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class SignJarCommand extends Command {
|
public class SignJarCommand extends Command {
|
||||||
public SignJarCommand(LaunchServer server) {
|
public SignJarCommand(LaunchServer server) {
|
||||||
|
@ -35,8 +35,9 @@ public void invoke(String... args) throws Exception {
|
||||||
else
|
else
|
||||||
tmpSign = server.dir.resolve("build").resolve(target.toFile().getName());
|
tmpSign = server.dir.resolve("build").resolve(target.toFile().getName());
|
||||||
LogHelper.info("Signing jar %s to %s", target.toString(), tmpSign.toString());
|
LogHelper.info("Signing jar %s to %s", target.toString(), tmpSign.toString());
|
||||||
SignJarTask task = (SignJarTask) TaskUtil.getTaskByClass(server.launcherBinary.tasks, SignJarTask.class);
|
Optional<SignJarTask> task = server.launcherBinary.getTaskByClass(SignJarTask.class);
|
||||||
task.sign(server.config.sign, target, tmpSign);
|
if(!task.isPresent()) throw new IllegalStateException("SignJarTask not found");
|
||||||
|
task.get().sign(server.config.sign, target, tmpSign);
|
||||||
if(args.length <= 1)
|
if(args.length <= 1)
|
||||||
{
|
{
|
||||||
LogHelper.info("Move temp jar %s to %s", tmpSign.toString(), target.toString());
|
LogHelper.info("Move temp jar %s to %s", tmpSign.toString(), target.toString());
|
||||||
|
|
Loading…
Reference in a new issue