From cf81c7a0b7919928214cc72508e8185bc236e508 Mon Sep 17 00:00:00 2001 From: Luke Bemish Date: Sat, 28 Sep 2024 16:06:43 -0500 Subject: [PATCH] Make fatjar allow remapping many files at once --- build.gradle | 21 +++++-- .../lukebemish/christen/cli/ChristenMain.java | 55 +++++++++++++++++++ 2 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 src/cli/java/dev/lukebemish/christen/cli/ChristenMain.java diff --git a/build.gradle b/build.gradle index 666dfda..c2f7653 100644 --- a/build.gradle +++ b/build.gradle @@ -83,18 +83,26 @@ managedVersioning { apply() } +sourceSets { + cli {} +} + dependencies { + cliImplementation 'net.neoforged.jst:jst-cli:1.0.63' + cliImplementation 'net.neoforged.jst:jst-api:1.0.63' + cliCompileOnly sourceSets.main.output + + cliCompileOnly cLibs.bundles.compileonly + cliAnnotationProcessor cLibs.bundles.annotationprocessor + implementation 'net.neoforged.jst:jst-cli:1.0.63' implementation 'net.neoforged.jst:jst-api:1.0.63' implementation 'net.neoforged:srgutils:1.0.9' implementation 'org.ow2.asm:asm:9.7' implementation 'org.slf4j:slf4j-simple:2.0.13' - compileOnly 'org.jetbrains:annotations:24.1.0' - compileOnly 'org.jspecify:jspecify:1.0.0' - compileOnly 'com.google.auto.service:auto-service:1.1.1' - - annotationProcessor 'com.google.auto.service:auto-service:1.1.1' + compileOnly cLibs.bundles.compileonly + annotationProcessor cLibs.bundles.annotationprocessor testImplementation platform('org.junit:junit-bom:5.10.3') testImplementation 'org.junit.jupiter:junit-jupiter' @@ -112,10 +120,11 @@ configurations { } shadowJar { + from sourceSets.cli.output configurations = [project.configurations.include] mergeServiceFiles() manifest { - attributes 'Main-Class': 'net.neoforged.jst.cli.Main' + attributes 'Main-Class': 'dev.lukebemish.christen.cli.ChristenMain' } } diff --git a/src/cli/java/dev/lukebemish/christen/cli/ChristenMain.java b/src/cli/java/dev/lukebemish/christen/cli/ChristenMain.java new file mode 100644 index 0000000..5c774ca --- /dev/null +++ b/src/cli/java/dev/lukebemish/christen/cli/ChristenMain.java @@ -0,0 +1,55 @@ +package dev.lukebemish.christen.cli; + +import dev.lukebemish.christen.ChristenTransformer; +import net.neoforged.jst.api.SourceTransformer; +import net.neoforged.jst.cli.Main; +import picocli.CommandLine; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.util.HashSet; +import java.util.List; +import java.util.concurrent.Callable; + +public class ChristenMain implements Callable { + @CommandLine.ArgGroup(exclusive = false, multiplicity = "1") + ChristenTransformer plugin; + + @CommandLine.ArgGroup(exclusive = false, multiplicity = "1..*") + List
subcommands; + + private static final MethodHandle ENABLED_TRANSFORMERS; + + static { + try { + ENABLED_TRANSFORMERS = MethodHandles.lookup().findGetter(Main.class, "enabledTransformers", HashSet.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public static void main(String[] args) { + var commandLine = new CommandLine(new ChristenMain()); + commandLine.setCaseInsensitiveEnumValuesAllowed(true); + System.exit(commandLine.execute(args)); + } + + @SuppressWarnings("unchecked") + @Override + public Integer call() throws Exception { + for (var main : subcommands) { + HashSet enabledTransformers; + try { + enabledTransformers = (HashSet) ENABLED_TRANSFORMERS.invoke(main); + } catch (Throwable e) { + throw new RuntimeException(e); + } + enabledTransformers.add(plugin); + var result = main.call(); + if (!result.equals(0)) { + return result; + } + } + return 0; + } +}