[FIX] Автовыбор опций ProGuard для Java9

This commit is contained in:
Zaxar163 2019-11-28 17:29:36 +01:00
parent 37e3991a9a
commit 90d2123f76
No known key found for this signature in database
GPG key ID: 1FE4F2E1F053831B
3 changed files with 24 additions and 4 deletions

View file

@ -15,6 +15,17 @@
import static org.objectweb.asm.Opcodes.*; import static org.objectweb.asm.Opcodes.*;
public final class NodeUtils { public final class NodeUtils {
public static final boolean JAVA9;
static {
boolean java9 = false;
try {
Class.forName("java.lang.StackWalker");
java9 = true;
} catch (final Throwable e) {
}
JAVA9 = java9;
}
private NodeUtils() { private NodeUtils() {
} }

View file

@ -1,6 +1,7 @@
package pro.gravit.launchserver.binary; package pro.gravit.launchserver.binary;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.asm.NodeUtils;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.SecurityHelper;
@ -13,11 +14,21 @@
import java.nio.file.Path; import java.nio.file.Path;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
public class ProguardConf { public class ProguardConf {
private static final String chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ"; private static final String chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ";
public static final String[] JAVA9_OPTS = new String[] {
"-libraryjars '<java.home>/jmods/'"
};
public static final String[] JAVA8_OPTS = new String[] {
"-libraryjars '<java.home>/lib/rt.jar'",
"-libraryjars '<java.home>/lib/jce.jar'",
"-libraryjars '<java.home>/lib/ext/nashorn.jar'",
"-libraryjars '<java.home>/lib/ext/jfxrt.jar'"
};
private static String generateString(SecureRandom rand, String lowString, String upString, int il) { private static String generateString(SecureRandom rand, String lowString, String upString, int il) {
StringBuilder sb = new StringBuilder(Math.max(il, lowString.length())); StringBuilder sb = new StringBuilder(Math.max(il, lowString.length()));
for (int i = 0; i < lowString.length(); ++i) { for (int i = 0; i < lowString.length(); ++i) {
@ -50,9 +61,11 @@ public String[] buildConfig(Path inputJar, Path outputJar) {
confStrs.add("-obfuscationdictionary \'" + words.toFile().getName() + "\'"); confStrs.add("-obfuscationdictionary \'" + words.toFile().getName() + "\'");
confStrs.add("-injar \'" + inputJar.toAbsolutePath() + "\'"); confStrs.add("-injar \'" + inputJar.toAbsolutePath() + "\'");
confStrs.add("-outjar \'" + outputJar.toAbsolutePath() + "\'"); confStrs.add("-outjar \'" + outputJar.toAbsolutePath() + "\'");
Collections.addAll(confStrs, NodeUtils.JAVA9 ? JAVA9_OPTS : JAVA8_OPTS);
srv.launcherBinary.coreLibs.stream() srv.launcherBinary.coreLibs.stream()
.map(e -> "-libraryjars \'" + e.toAbsolutePath().toString() + "\'") .map(e -> "-libraryjars \'" + e.toAbsolutePath().toString() + "\'")
.forEach(confStrs::add); .forEach(confStrs::add);
srv.launcherBinary.addonLibs.stream() srv.launcherBinary.addonLibs.stream()
.map(e -> "-libraryjars \'" + e.toAbsolutePath().toString() + "\'") .map(e -> "-libraryjars \'" + e.toAbsolutePath().toString() + "\'")
.forEach(confStrs::add); .forEach(confStrs::add);

View file

@ -1,7 +1,3 @@
-libraryjars '<java.home>/lib/rt.jar'
-libraryjars '<java.home>/lib/jce.jar'
-libraryjars '<java.home>/lib/ext/nashorn.jar'
-libraryjars '<java.home>/lib/ext/jfxrt.jar'
-keepattributes SourceFile,LineNumberTable -keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute Source -renamesourcefileattribute Source