diff --git a/README.md b/README.md index 40f3e6c..f9bd11e 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ It can be invoked as a standalone executable Jar-File. Java 17 is required. ``` Usage: jst [-hV] [--in-format=] [--libraries-list=] [--max-queue-depth=] [--out-format=] - [--classpath=]... [--enable-parchment - --parchment-mappings= [--[no-]parchment-javadoc] + [--classpath=]... [--ignore-prefix=]... + [--enable-parchment --parchment-mappings= [--[no-]parchment-javadoc] [--parchment-conflict-prefix=]] [--enable-accesstransformers --access-transformer= [--access-transformer=]... [--access-transformer-validation=]] INPUT OUTPUT @@ -40,6 +40,9 @@ Usage: jst [-hV] [--in-format=] [--libraries-list=] --classpath= Additional classpath entries to use. Is combined with --libraries-list. -h, --help Show this help message and exit. + --ignore-prefix= + Do not apply transformations to paths that start with any of these + prefixes. --in-format= Specify the format of INPUT explicitly. AUTO (the default) performs auto-detection. Other options are SINGLE_FILE for Java files, ARCHIVE diff --git a/cli/src/main/java/net/neoforged/jst/cli/Main.java b/cli/src/main/java/net/neoforged/jst/cli/Main.java index 3a41047..613d2e1 100644 --- a/cli/src/main/java/net/neoforged/jst/cli/Main.java +++ b/cli/src/main/java/net/neoforged/jst/cli/Main.java @@ -32,6 +32,9 @@ public class Main implements Callable { @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 ignoredPrefixes = new ArrayList<>(); + @CommandLine.Option(names = "--classpath", description = "Additional classpath entries to use. Is combined with --libraries-list.", converter = ClasspathConverter.class) List addToClasspath = new ArrayList<>(); @@ -73,6 +76,9 @@ public Integer call() throws Exception { for (Path path : addToClasspath) { processor.addLibrary(path); } + for (String ignoredPrefix : ignoredPrefixes) { + processor.addIgnoredPrefix(ignoredPrefix); + } processor.setMaxQueueDepth(maxQueueDepth); diff --git a/cli/src/main/java/net/neoforged/jst/cli/SourceFileProcessor.java b/cli/src/main/java/net/neoforged/jst/cli/SourceFileProcessor.java index b3c97c3..c97b113 100644 --- a/cli/src/main/java/net/neoforged/jst/cli/SourceFileProcessor.java +++ b/cli/src/main/java/net/neoforged/jst/cli/SourceFileProcessor.java @@ -18,6 +18,7 @@ import java.nio.file.Path; import java.nio.file.attribute.FileTime; import java.time.Instant; +import java.util.ArrayList; import java.util.List; /** @@ -29,6 +30,8 @@ class SourceFileProcessor implements AutoCloseable { private int maxQueueDepth = 50; private final Logger logger; + private final List ignoredPrefixes = new ArrayList<>(); + public SourceFileProcessor(Logger logger) throws IOException { this.logger = logger; ijEnv = new IntelliJEnvironmentImpl(logger); @@ -90,7 +93,7 @@ private void processEntry(FileEntry entry, VirtualFile sourceRoot, List transformers, byte[] originalContentBytes) { // Instead of parsing the content we actually read from the file, we read the virtual file that is // visible to IntelliJ from adding the source jar. The reasoning is that IntelliJ will cache this internally @@ -145,6 +157,11 @@ public void addLibrary(Path library) { ClasspathSetup.addLibrary(logger, library, ijEnv); } + public void addIgnoredPrefix(String ignoredPrefix) { + System.out.println("Not transforming entries starting with " + ignoredPrefix); + this.ignoredPrefixes.add(ignoredPrefix); + } + @Override public void close() throws IOException { ijEnv.close(); diff --git a/parchment/src/main/java/net/neoforged/jst/parchment/GatherReplacementsVisitor.java b/parchment/src/main/java/net/neoforged/jst/parchment/GatherReplacementsVisitor.java index 45631e4..e5aa9ca 100644 --- a/parchment/src/main/java/net/neoforged/jst/parchment/GatherReplacementsVisitor.java +++ b/parchment/src/main/java/net/neoforged/jst/parchment/GatherReplacementsVisitor.java @@ -61,8 +61,9 @@ public void visitElement(@NotNull PsiElement element) { if (foundClass == null) { throw new IllegalStateException("Failed to find how class " + psiClass.getQualifiedName() + " was loaded while processing it"); } else if (foundClass != psiClass) { - throw new IllegalStateException("Class " + psiClass + " was loaded from two different sources: " + - psiClass.getContainingFile() + " and " + foundClass.getContainingFile()); + throw new IllegalStateException("Class " + psiClass.getQualifiedName() + " was loaded from two different sources: " + + psiClass.getContainingFile().getVirtualFile().getPath() + " and " + + foundClass.getContainingFile().getVirtualFile().getPath()); } }