[FEATURE] FxRuntimeOptimizerModule

This commit is contained in:
Gravita 2024-03-03 13:39:28 +07:00
parent ead4689bcf
commit f484f045ca
4 changed files with 29 additions and 10 deletions

View File

@ -46,11 +46,14 @@ public class BuildContext {
public final HashSet<String> fileList;
public final HashSet<String> clientModules;
public final HashSet<String> legacyClientModules;
private Path runtimeDir;
private boolean deleteRuntimeDir;
public BuildContext(ZipOutputStream output, List<JarFile> readerClassPath, MainBuildTask task) {
public BuildContext(ZipOutputStream output, List<JarFile> readerClassPath, MainBuildTask task, Path runtimeDir) {
this.output = output;
this.readerClassPath = readerClassPath;
this.task = task;
this.runtimeDir = runtimeDir;
fileList = new HashSet<>(1024);
clientModules = new HashSet<>();
legacyClientModules = new HashSet<>();
@ -103,6 +106,14 @@ public class BuildContext {
pushJarFile(jarfile.toUri().toURL(), filter, needTransform);
}
public Path getRuntimeDir() {
return runtimeDir;
}
public void setRuntimeDir(Path runtimeDir) {
this.runtimeDir = runtimeDir;
}
public void pushJarFile(URL jarfile, Predicate<ZipEntry> filter, Predicate<String> needTransform) throws IOException {
try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(jarfile))) {
ZipEntry e = input.getNextEntry();
@ -129,6 +140,16 @@ public class BuildContext {
e = input.getNextEntry();
}
}
}
public boolean isDeleteRuntimeDir() {
return deleteRuntimeDir;
}
public void setDeleteRuntimeDir(boolean deleteRuntimeDir) {
this.deleteRuntimeDir = deleteRuntimeDir;
}
private final static class RuntimeDirVisitor extends SimpleFileVisitor<Path> {

View File

@ -53,7 +53,7 @@ public class MainBuildTask implements LauncherBuildTask {
public Path process(Path inputJar) throws IOException {
Path outputJar = server.launcherBinary.nextPath(this);
try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(outputJar))) {
BuildContext context = new BuildContext(output, reader.getCp(), this);
BuildContext context = new BuildContext(output, reader.getCp(), this, server.launcherBinary.runtimeDir);
initProps();
preBuildHook.hook(context);
properties.put("launcher.legacymodules", context.legacyClientModules.stream().map(e -> Type.getObjectType(e.replace('.', '/'))).collect(Collectors.toList()));
@ -69,9 +69,12 @@ public class MainBuildTask implements LauncherBuildTask {
Map<String, byte[]> runtime = new HashMap<>(256);
// Write launcher guard dir
if (server.config.launcher.encryptRuntime) {
context.pushEncryptedDir(server.launcherBinary.runtimeDir, Launcher.RUNTIME_DIR, server.runtime.runtimeEncryptKey, runtime, false);
context.pushEncryptedDir(context.getRuntimeDir(), Launcher.RUNTIME_DIR, server.runtime.runtimeEncryptKey, runtime, false);
} else {
context.pushDir(server.launcherBinary.runtimeDir, Launcher.RUNTIME_DIR, runtime, false);
context.pushDir(context.getRuntimeDir(), Launcher.RUNTIME_DIR, runtime, false);
}
if(context.isDeleteRuntimeDir()) {
IOHelper.deleteDir(context.getRuntimeDir(), true);
}
LauncherConfig launcherConfig = new LauncherConfig(server.config.netty.address, server.keyAgreementManager.ecdsaPublicKey, server.keyAgreementManager.rsaPublicKey, runtime, server.config.projectName);

View File

@ -1,4 +1,3 @@
apply plugin: 'org.openjfx.javafxplugin'
apply plugin: 'com.github.johnrengelman.shadow'
String mainClassName = "pro.gravit.launcher.start.ClientLauncherWrapper"
@ -9,10 +8,6 @@ repositories {
url "https://repo.spring.io/plugins-release/"
}
}
javafx {
version = "12"
modules = ['javafx.controls', 'javafx.fxml']
}
sourceCompatibility = '17'
targetCompatibility = '17'

View File

@ -2,7 +2,7 @@ plugins {
id 'com.github.johnrengelman.shadow' version '7.1.2' apply false
id 'maven-publish'
id 'signing'
id 'org.openjfx.javafxplugin' version '0.0.10' apply false
id 'org.openjfx.javafxplugin' version '0.1.0' apply false
}
group = 'pro.gravit.launcher'
version = '5.6.0-SNAPSHOT'