Skip to content

Commit

Permalink
Make fatjar allow remapping many files at once
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish committed Sep 28, 2024
1 parent 8872961 commit cf81c7a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 6 deletions.
21 changes: 15 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
}
}

Expand Down
55 changes: 55 additions & 0 deletions src/cli/java/dev/lukebemish/christen/cli/ChristenMain.java
Original file line number Diff line number Diff line change
@@ -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<Integer> {
@CommandLine.ArgGroup(exclusive = false, multiplicity = "1")
ChristenTransformer plugin;

@CommandLine.ArgGroup(exclusive = false, multiplicity = "1..*")
List<Main> 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<SourceTransformer> enabledTransformers;
try {
enabledTransformers = (HashSet<SourceTransformer>) 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;
}
}

0 comments on commit cf81c7a

Please sign in to comment.