From bd325cbba05c2aae075bb604c0355e3eb2978ba2 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Fri, 7 Jun 2024 13:51:16 +0200 Subject: [PATCH 1/3] Add the option to add path-prefixes that should not be transformed --- .../main/java/net/neoforged/jst/cli/Main.java | 6 ++++++ .../jst/cli/SourceFileProcessor.java | 19 ++++++++++++++++++- .../parchment/GatherReplacementsVisitor.java | 5 +++-- 3 files changed, 27 insertions(+), 3 deletions(-) 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..1799fd9 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 transforms entry whose path start with this prefix.") + 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()); } } From 49ceecd719bc3afd431b528666125335f2447080 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Thu, 4 Jul 2024 15:38:57 +0200 Subject: [PATCH 2/3] Updated help --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 40f3e6c..5999f83 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,8 @@ 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 transforms entry whose path start with this prefix. --in-format= Specify the format of INPUT explicitly. AUTO (the default) performs auto-detection. Other options are SINGLE_FILE for Java files, ARCHIVE From 4a6fb2c45bee4185248938529a0a458347b470d1 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Thu, 4 Jul 2024 15:47:47 +0200 Subject: [PATCH 3/3] Updated help --- README.md | 3 ++- cli/src/main/java/net/neoforged/jst/cli/Main.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5999f83..f9bd11e 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,8 @@ Usage: jst [-hV] [--in-format=] [--libraries-list=] Additional classpath entries to use. Is combined with --libraries-list. -h, --help Show this help message and exit. --ignore-prefix= - Do not transforms entry whose path start with this 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 1799fd9..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,7 +32,7 @@ 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 transforms entry whose path start with this prefix.") + @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)