Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow JST to be applied with the same configuration to multiple files at once #41

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions cli/src/main/java/net/neoforged/jst/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,29 @@

@CommandLine.Command(name = "jst", mixinStandardHelpOptions = true, usageHelpWidth = 100)
public class Main implements Callable<Integer> {
@CommandLine.Parameters(index = "0", paramLabel = "INPUT", description = "Path to a single Java-file, a source-archive or a folder containing the source to transform.")
Path inputPath;
@CommandLine.ArgGroup(exclusive = false, multiplicity = "1..*")
List<Task> tasks;

static class Task {
@CommandLine.Parameters(index = "0", paramLabel = "INPUT", description = "Path to a single Java-file, a source-archive or a folder containing the source to transform.")
Path inputPath;

@CommandLine.Parameters(index = "1", paramLabel = "OUTPUT", description = "Path to where the resulting source should be placed.")
Path outputPath;
@CommandLine.Parameters(index = "1", paramLabel = "OUTPUT", description = "Path to where the resulting source should be placed.")
Path outputPath;

@CommandLine.Option(names = "--in-format", description = "Specify the format of INPUT explicitly. AUTO (the default) performs auto-detection. Other options are SINGLE_FILE for Java files, ARCHIVE for source jars or zips, and FOLDER for folders containing Java code.")
PathType inputFormat = PathType.AUTO;
@CommandLine.Option(names = "--in-format", description = "Specify the format of INPUT explicitly. AUTO (the default) performs auto-detection. Other options are SINGLE_FILE for Java files, ARCHIVE for source jars or zips, and FOLDER for folders containing Java code.")
PathType inputFormat = PathType.AUTO;

@CommandLine.Option(names = "--out-format", description = "Specify the format of OUTPUT explicitly. Allows the same options as --in-format.")
PathType outputFormat = PathType.AUTO;
@CommandLine.Option(names = "--out-format", description = "Specify the format of OUTPUT explicitly. Allows the same options as --in-format.")
PathType outputFormat = PathType.AUTO;

@CommandLine.Option(names = "--ignore-prefix", description = "Do not apply transformations to paths that start with any of these prefixes.")
List<String> ignoredPrefixes = new ArrayList<>();
}

@CommandLine.Option(names = "--libraries-list", description = "Specifies a file that contains a path to an archive or directory to add to the classpath on each line.")
Path librariesList;

@CommandLine.Option(names = "--ignore-prefix", description = "Do not apply transformations to paths that start with any of these prefixes.")
List<String> ignoredPrefixes = new ArrayList<>();

@CommandLine.Option(names = "--classpath", description = "Additional classpath entries to use. Is combined with --libraries-list.", converter = ClasspathConverter.class)
List<Path> addToClasspath = new ArrayList<>();

Expand Down Expand Up @@ -67,30 +72,33 @@ public static int innerMain(String... args) {
@Override
public Integer call() throws Exception {
var logger = debug ? new Logger(System.out, System.err) : new Logger(null, System.err);
try (var source = FileSources.create(inputPath, inputFormat);
var processor = new SourceFileProcessor(logger)) {

try (var processor = new SourceFileProcessor(logger)) {
if (librariesList != null) {
processor.addLibrariesList(librariesList);
}
for (Path path : addToClasspath) {
processor.addLibrary(path);
}
for (String ignoredPrefix : ignoredPrefixes) {
processor.addIgnoredPrefix(ignoredPrefix);
}

processor.setMaxQueueDepth(maxQueueDepth);

var orderedTransformers = new ArrayList<>(enabledTransformers);

try (var sink = FileSinks.create(outputPath, outputFormat, source)) {
if (!processor.process(source, sink, orderedTransformers)) {
logger.error("Transformation failed");
return 1;

for (var task : tasks) {
try (var source = FileSources.create(task.inputPath, task.inputFormat)) {
for (String ignoredPrefix : task.ignoredPrefixes) {
processor.addIgnoredPrefix(ignoredPrefix);
}

try (var sink = FileSinks.create(task.outputPath, task.outputFormat, source)) {
if (!processor.process(source, sink, orderedTransformers)) {
logger.error("Transformation failed");
return 1;
}
}
}
}

}

return 0;
Expand Down