From db5a1884a57e05e6e24e5cd2c6ce3e246def90ea Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Sun, 5 Jan 2025 00:38:03 -0600 Subject: [PATCH] default shadeInlining to true, add missing cli args, flag serialization --- .../java/xyz/wagyourtail/jvmdg/cli/Flags.java | 73 ++++++++++++++++++- .../java/xyz/wagyourtail/jvmdg/cli/Main.java | 13 ++++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/wagyourtail/jvmdg/cli/Flags.java b/src/main/java/xyz/wagyourtail/jvmdg/cli/Flags.java index 050d3ec..1c208af 100644 --- a/src/main/java/xyz/wagyourtail/jvmdg/cli/Flags.java +++ b/src/main/java/xyz/wagyourtail/jvmdg/cli/Flags.java @@ -81,7 +81,7 @@ public class Flags { * * @since 1.2.0 */ - public boolean shadeInlining = Boolean.getBoolean(Constants.SHADE_INLINING); + public boolean shadeInlining = Boolean.getBoolean(System.getProperty(Constants.SHADE_INLINING, "true")); /** * this skips applying stubs for the specified input class version, this will still apply the * {@link xyz.wagyourtail.jvmdg.version.VersionProvider#otherTransforms(ClassNode, Set, Function, Set)} @@ -405,6 +405,77 @@ private String hash(InputStream is) { } } + public String serialize() { + List args = new ArrayList<>(); + if (classVersion != Opcodes.V1_8) { + args.add("--classVersion"); + args.add(String.valueOf(classVersion)); + } + if (quiet) args.add("--quiet"); + if (!logAnsiColors) args.add("--noColor"); + if (logLevel != Logger.Level.INFO) { + args.add("--logLevel"); + args.add(logLevel.name()); + } + for (Map.Entry entry : ignoreWarningsIn.entrySet()) { + args.add("--ignoreWarningsIn"); + String key = entry.getKey(); + switch (entry.getValue()) { + case DOUBLE: + key += "*"; + case SINGLE: + key += "*"; + case NONE: + } + args.add(key); + } + if (multiReleaseOriginal) { + args.add("--multiReleaseOriginal"); + } + for (Integer v : multiReleaseVersions) { + args.add("--multiRelease"); + args.add(String.valueOf(v)); + } + if (downgradeFromMultiReleases) { + args.add("--multiReleaseInputs"); + } + if (!shadeInlining) { + args.add("--noInlining"); + } + for (File a : api) { + args.add("--api"); + // todo: escape spaces, but, how does that work with javac plugin args? + args.add(a.getAbsolutePath()); + } + if (printDebug || !debugSkipStub.isEmpty() || !debugSkipStubs.isEmpty() || debugDumpClasses) { + args.add("debug"); + if (printDebug) { + args.add("--print"); + } + if (!debugSkipStub.isEmpty()) { + for (FullyQualifiedMemberNameAndDesc f : debugSkipStub) { + args.add("--skipStub"); + args.add(f.toString()); + } + } + if (!debugSkipStubs.isEmpty()) { + for (int i : debugSkipStubs) { + args.add("--skipStubs"); + args.add(String.valueOf(i)); + } + } + if (debugDumpClasses) { + args.add("--dumpClasses"); + } + } + StringBuilder sb = new StringBuilder(); + for (String arg : args) { + sb.append(arg).append(" "); + } + if (!args.isEmpty()) sb.deleteCharAt(sb.length() - 1); + return sb.toString(); + } + public enum WildcardType { NONE, SINGLE, diff --git a/src/main/java/xyz/wagyourtail/jvmdg/cli/Main.java b/src/main/java/xyz/wagyourtail/jvmdg/cli/Main.java index c9ccfcc..c299bf4 100644 --- a/src/main/java/xyz/wagyourtail/jvmdg/cli/Main.java +++ b/src/main/java/xyz/wagyourtail/jvmdg/cli/Main.java @@ -40,6 +40,8 @@ protected Arguments buildArgumentList() { new Arguments("--classVersion", "Target class version (ex. \"52\" for java 8)", new String[]{"-c"}, new String[]{"version"}), new Arguments("--multiReleaseOriginal", "Use the original class file for a Multi-Release jar", new String[]{"-mro"}, null), new Arguments("--multiRelease", "Use semi-downgraded files for a Multi-Release jar, versions as class version (ex. \"55\" for java 11)", new String[]{"-mr"}, new String[]{"version"}), + new Arguments("--noColor", "Disables ansi colors", new String[]{"-nc"}, null), + new Arguments("--multiReleaseInputs", "Use the Multi-Release files as inputs for downgrading when available, instead of the normal ones", new String[]{"-mri"}, null), new Arguments("debug", "Set debug flags/call debug actions", null, null).addChildren( new Arguments("--print", "[Deprecated] Enable printing debug info", new String[]{"-p"}, null), new Arguments("--skipStub", "Skip a specific class/method, of form \"Lcom/example/ClassName;\" or \"Lcom/example/ClassName;methodName;()V\"", new String[] {"-ss"}, new String[] {"stub"}), @@ -47,6 +49,7 @@ protected Arguments buildArgumentList() { new Arguments("--dumpClasses", "Dump classes to the debug folder", new String[]{"-d"}, null), new Arguments("downgradeApi", "Retrieves and downgrades the java api jar", null, new String[]{"outputPath"}) ), + new Arguments("--noInlining", "Disable shade inlining when a method is only used in one class", new String[]{"-ni"}, null), new Arguments("downgrade", "Downgrades a jar or folder", null, null).addChildren( input, classpath @@ -158,6 +161,16 @@ public void parseArgs(String[] args) throws IOException, ClassNotFoundException, } } flags.multiReleaseVersions = versions; + break; + case "--noColor": + flags.logAnsiColors = false; + break; + case "--multiReleaseInputs": + flags.downgradeFromMultiReleases = true; + break; + case "--noInlining": + flags.shadeInlining = false; + break; default: } }