mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
Merge pull request #696 from microwin7/dev
[FIX][FEATURE] Merge commits from nojava8support ref. Proguard, with jvmArgs
This commit is contained in:
commit
1e3676778e
1 changed files with 39 additions and 12 deletions
|
@ -9,21 +9,23 @@
|
||||||
import pro.gravit.utils.command.SubCommand;
|
import pro.gravit.utils.command.SubCommand;
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
import pro.gravit.utils.helper.JVMHelper;
|
import pro.gravit.utils.helper.JVMHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
import pro.gravit.utils.helper.UnpackHelper;
|
import pro.gravit.utils.helper.UnpackHelper;
|
||||||
import proguard.Configuration;
|
|
||||||
import proguard.ConfigurationParser;
|
|
||||||
import proguard.ProGuard;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.file.FileVisitOption;
|
||||||
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.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
@ -32,6 +34,7 @@ public class ProGuardComponent extends Component implements AutoCloseable, Recon
|
||||||
private static final Logger logger = LogManager.getLogger();
|
private static final Logger logger = LogManager.getLogger();
|
||||||
public String modeAfter = "MainBuild";
|
public String modeAfter = "MainBuild";
|
||||||
public String dir = "proguard";
|
public String dir = "proguard";
|
||||||
|
public List<String> jvmArgs = new ArrayList<>();
|
||||||
public boolean enabled = true;
|
public boolean enabled = true;
|
||||||
public boolean mappings = true;
|
public boolean mappings = true;
|
||||||
public transient ProguardConf proguardConf;
|
public transient ProguardConf proguardConf;
|
||||||
|
@ -39,6 +42,10 @@ public class ProGuardComponent extends Component implements AutoCloseable, Recon
|
||||||
private transient ProGuardBuildTask buildTask;
|
private transient ProGuardBuildTask buildTask;
|
||||||
private transient ProGuardMultiReleaseFixer fixerTask;
|
private transient ProGuardMultiReleaseFixer fixerTask;
|
||||||
|
|
||||||
|
public ProGuardComponent() {
|
||||||
|
this.jvmArgs.add("-Xmx512M");
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean checkFXJMods(Path path) {
|
public static boolean checkFXJMods(Path path) {
|
||||||
if (!IOHelper.exists(path.resolve("javafx.base.jmod")))
|
if (!IOHelper.exists(path.resolve("javafx.base.jmod")))
|
||||||
return false;
|
return false;
|
||||||
|
@ -191,7 +198,6 @@ public String getName() {
|
||||||
public Path process(Path inputFile) throws IOException {
|
public Path process(Path inputFile) throws IOException {
|
||||||
Path outputJar = server.launcherBinary.nextLowerPath(this);
|
Path outputJar = server.launcherBinary.nextLowerPath(this);
|
||||||
if (component.enabled) {
|
if (component.enabled) {
|
||||||
Configuration proguard_cfg = new Configuration();
|
|
||||||
if (!checkJMods(IOHelper.JVM_DIR.resolve("jmods"))) {
|
if (!checkJMods(IOHelper.JVM_DIR.resolve("jmods"))) {
|
||||||
throw new RuntimeException("Java path: %s is not JDK! Please install JDK".formatted(IOHelper.JVM_DIR));
|
throw new RuntimeException("Java path: %s is not JDK! Please install JDK".formatted(IOHelper.JVM_DIR));
|
||||||
}
|
}
|
||||||
|
@ -204,12 +210,35 @@ public Path process(Path inputFile) throws IOException {
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("JavaFX jmods not found. May be install OpenJFX?");
|
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 {
|
try {
|
||||||
parser.parse(proguard_cfg);
|
List<String> args = new ArrayList<>();
|
||||||
ProGuard proGuard = new ProGuard(proguard_cfg);
|
args.add(IOHelper.resolveJavaBin(IOHelper.JVM_DIR).toAbsolutePath().toString());
|
||||||
proGuard.execute();
|
args.addAll(component.jvmArgs);
|
||||||
|
args.add("-cp");
|
||||||
|
try(Stream<Path> 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) {
|
} catch (Exception e) {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
|
@ -256,8 +285,7 @@ private static String generateString(SecureRandom rand, String lowString, String
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] buildConfig(Path inputJar, Path outputJar, Path[] jfxPath) {
|
public void buildConfig(List<String> confStrs, Path inputJar, Path outputJar, Path[] jfxPath) {
|
||||||
List<String> confStrs = new ArrayList<>();
|
|
||||||
prepare(false);
|
prepare(false);
|
||||||
if (component.mappings)
|
if (component.mappings)
|
||||||
confStrs.add("-printmapping '" + mappings.toFile().getName() + "'");
|
confStrs.add("-printmapping '" + mappings.toFile().getName() + "'");
|
||||||
|
@ -279,7 +307,6 @@ public String[] buildConfig(Path inputJar, Path outputJar, Path[] jfxPath) {
|
||||||
.forEach(confStrs::add);
|
.forEach(confStrs::add);
|
||||||
confStrs.add("-classobfuscationdictionary '" + words.toFile().getName() + "'");
|
confStrs.add("-classobfuscationdictionary '" + words.toFile().getName() + "'");
|
||||||
confStrs.add("@".concat(config.toFile().getName()));
|
confStrs.add("@".concat(config.toFile().getName()));
|
||||||
return confStrs.toArray(new String[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void genConfig(boolean force) throws IOException {
|
private void genConfig(boolean force) throws IOException {
|
||||||
|
|
Loading…
Reference in a new issue