-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make fatjar allow remapping many files at once
- Loading branch information
1 parent
8872961
commit cf81c7a
Showing
2 changed files
with
70 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/cli/java/dev/lukebemish/christen/cli/ChristenMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |