From cfcd0010a728ee4409538d94cc09db3bbfa7940d Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sun, 7 Jan 2024 20:18:15 +0700 Subject: [PATCH 1/3] [FIX] Support arch i586 in release file --- .../src/main/java/pro/gravit/utils/helper/JVMHelper.java | 2 +- .../src/main/java/pro/gravit/utils/helper/JavaHelper.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java index e691aacb..bc029287 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java @@ -46,7 +46,7 @@ private JVMHelper() { public static ARCH getArch(String arch) { if (arch.equals("amd64") || arch.equals("x86-64") || arch.equals("x86_64")) return ARCH.X86_64; - if (arch.equals("i386") || arch.equals("i686") || arch.equals("x86")) return ARCH.X86; + if (arch.equals("i386") || arch.equals("i586") || arch.equals("i686") || arch.equals("x86")) return ARCH.X86; if (arch.startsWith("armv8") || arch.startsWith("aarch64")) return ARCH.ARM64; if (arch.startsWith("arm") || arch.startsWith("aarch32")) return ARCH.ARM32; throw new InternalError(String.format("Unsupported arch '%s'", arch)); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java index a4d1f58f..96c54a79 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java @@ -265,7 +265,6 @@ public static JavaVersion getByPath(Path jvmDir) { arch = JVMHelper.getArch(archProperty); } } catch (Throwable ignored) { - arch = null; } String modulesProperty = getProperty(properties, "MODULES"); if(modulesProperty != null) { From 48946d6e7407b7b0d0bee1a9258122aabcf3f797 Mon Sep 17 00:00:00 2001 From: dima_dencep Date: Fri, 12 Jan 2024 16:02:02 +0700 Subject: [PATCH 2/3] [FIX] proguard (#694) --- .../components/ProGuardComponent.java | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/ProGuardComponent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/ProGuardComponent.java index 520a80f4..f30ab0b4 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/ProGuardComponent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/ProGuardComponent.java @@ -9,21 +9,23 @@ import pro.gravit.utils.command.SubCommand; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; +import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.UnpackHelper; -import proguard.Configuration; -import proguard.ConfigurationParser; -import proguard.ProGuard; import java.io.*; +import java.nio.file.FileVisitOption; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.security.SecureRandom; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; @@ -191,7 +193,6 @@ public String getName() { public Path process(Path inputFile) throws IOException { Path outputJar = server.launcherBinary.nextLowerPath(this); if (component.enabled) { - Configuration proguard_cfg = new Configuration(); if (!checkJMods(IOHelper.JVM_DIR.resolve("jmods"))) { throw new RuntimeException("Java path: %s is not JDK! Please install JDK".formatted(IOHelper.JVM_DIR)); } @@ -204,12 +205,34 @@ public Path process(Path inputFile) throws IOException { } else { throw new RuntimeException("JavaFX jmods not found. May be install OpenJFX?"); } - ConfigurationParser parser = new ConfigurationParser(proguardConf.buildConfig(inputFile, outputJar, jfxPath == null ? new Path[0] : new Path[]{jfxPath}), - proguardConf.proguard.toFile(), System.getProperties()); try { - parser.parse(proguard_cfg); - ProGuard proGuard = new ProGuard(proguard_cfg); - proGuard.execute(); + List args = new ArrayList<>(); + args.add(IOHelper.resolveJavaBin(IOHelper.JVM_DIR).toAbsolutePath().toString()); + args.add("-cp"); + try(Stream files = Files.walk(Path.of("libraries"), FileVisitOption.FOLLOW_LINKS)) { + args.add(files + .filter(e -> e.getFileName().toString().endsWith(".jar")) + .map(path -> path.toAbsolutePath().toString()) + .collect(Collectors.joining(File.pathSeparator)) + ); + } + args.add("proguard.ProGuard"); + proguardConf.buildConfig(args, inputFile, outputJar, jfxPath == null ? new Path[0] : new Path[]{jfxPath}); + + Process process = new ProcessBuilder() + .command(args) + .inheritIO() + .directory(proguardConf.proguard.toFile()) + .start(); + + try { + process.waitFor(); + } catch (InterruptedException ignored) { + + } + if (process.exitValue() != 0) { + throw new RuntimeException("ProGuard process return %d".formatted(process.exitValue())); + } } catch (Exception e) { logger.error(e); } @@ -256,8 +279,7 @@ private static String generateString(SecureRandom rand, String lowString, String return sb.toString(); } - public String[] buildConfig(Path inputJar, Path outputJar, Path[] jfxPath) { - List confStrs = new ArrayList<>(); + public void buildConfig(List confStrs, Path inputJar, Path outputJar, Path[] jfxPath) { prepare(false); if (component.mappings) confStrs.add("-printmapping '" + mappings.toFile().getName() + "'"); @@ -279,7 +301,6 @@ public String[] buildConfig(Path inputJar, Path outputJar, Path[] jfxPath) { .forEach(confStrs::add); confStrs.add("-classobfuscationdictionary '" + words.toFile().getName() + "'"); confStrs.add("@".concat(config.toFile().getName())); - return confStrs.toArray(new String[0]); } private void genConfig(boolean force) throws IOException { From ab884c8d23b8ac1f7ca8905596f7c732e4e1fb8a Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Thu, 18 Jan 2024 00:13:36 +0700 Subject: [PATCH 3/3] [FEATURE] Add ProGuard jvmArgs --- .../gravit/launchserver/components/ProGuardComponent.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/ProGuardComponent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/ProGuardComponent.java index f30ab0b4..ee92b7e0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/ProGuardComponent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/ProGuardComponent.java @@ -34,6 +34,7 @@ public class ProGuardComponent extends Component implements AutoCloseable, Recon private static final Logger logger = LogManager.getLogger(); public String modeAfter = "MainBuild"; public String dir = "proguard"; + public List jvmArgs = new ArrayList<>(); public boolean enabled = true; public boolean mappings = true; public transient ProguardConf proguardConf; @@ -41,6 +42,10 @@ public class ProGuardComponent extends Component implements AutoCloseable, Recon private transient ProGuardBuildTask buildTask; private transient ProGuardMultiReleaseFixer fixerTask; + public ProGuardComponent() { + this.jvmArgs.add("-Xmx512M"); + } + public static boolean checkFXJMods(Path path) { if (!IOHelper.exists(path.resolve("javafx.base.jmod"))) return false; @@ -208,6 +213,7 @@ public Path process(Path inputFile) throws IOException { try { List args = new ArrayList<>(); args.add(IOHelper.resolveJavaBin(IOHelper.JVM_DIR).toAbsolutePath().toString()); + args.addAll(component.jvmArgs); args.add("-cp"); try(Stream files = Files.walk(Path.of("libraries"), FileVisitOption.FOLLOW_LINKS)) { args.add(files