Skip to content

Commit a7eaf8d

Browse files
committed
Add hidden prefixes
JSTs ignored prefixes are still pushed into the output file sink, which is not needed when the input and output sources are the same. The commit adds a stronger version of ignored prefixes, "hidden" prefixes, which are not processed or pushed to the output sink.
1 parent 4efb936 commit a7eaf8d

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

cli/src/main/java/net/neoforged/jst/cli/Main.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public class Main implements Callable<Integer> {
3535
@CommandLine.Option(names = "--ignore-prefix", description = "Do not apply transformations to paths that start with any of these prefixes.")
3636
List<String> ignoredPrefixes = new ArrayList<>();
3737

38+
@CommandLine.Option(names = "--hidden-prefix", description = "Do not process or emit paths that start with any of these prefixes.")
39+
List<String> hiddenPrefixes = new ArrayList<>();
40+
3841
@CommandLine.Option(names = "--classpath", description = "Additional classpath entries to use. Is combined with --libraries-list.", converter = ClasspathConverter.class)
3942
List<Path> addToClasspath = new ArrayList<>();
4043

@@ -79,6 +82,10 @@ public Integer call() throws Exception {
7982
for (String ignoredPrefix : ignoredPrefixes) {
8083
processor.addIgnoredPrefix(ignoredPrefix);
8184
}
85+
for (String hiddenPrefix : hiddenPrefixes) {
86+
processor.addIgnoredPrefix(hiddenPrefix);
87+
processor.addHiddenPrefix(hiddenPrefix);
88+
}
8289

8390
processor.setMaxQueueDepth(maxQueueDepth);
8491

cli/src/main/java/net/neoforged/jst/cli/SourceFileProcessor.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class SourceFileProcessor implements AutoCloseable {
3434
private final Logger logger;
3535

3636
private final List<String> ignoredPrefixes = new ArrayList<>();
37+
private final List<String> hiddenPrefixes = new ArrayList<>();
3738

3839
public SourceFileProcessor(Logger logger) throws IOException {
3940
this.logger = logger;
@@ -114,13 +115,21 @@ private boolean processEntry(FileEntry entry, VirtualFile sourceRoot, List<Sourc
114115
lastModified = FileTime.from(Instant.now());
115116
}
116117
}
117-
sink.putFile(entry.relativePath(), lastModified, content);
118+
if (isHidden(entry.relativePath())) sink.putFile(entry.relativePath(), lastModified, content);
118119
}
119120
return true;
120121
}
121122

122123
private boolean isIgnored(String relativePath) {
123-
for (String ignoredPrefix : ignoredPrefixes) {
124+
return isRelativePathIn(relativePath, this.ignoredPrefixes);
125+
}
126+
127+
private boolean isHidden(String relativePath) {
128+
return isRelativePathIn(relativePath, this.hiddenPrefixes);
129+
}
130+
131+
private boolean isRelativePathIn(String relativePath, List<String> prefixes) {
132+
for (String ignoredPrefix : prefixes) {
124133
if (relativePath.startsWith(ignoredPrefix)) {
125134
return true;
126135
}
@@ -187,6 +196,12 @@ public void addIgnoredPrefix(String ignoredPrefix) {
187196
this.ignoredPrefixes.add(ignoredPrefix);
188197
}
189198

199+
public void addHiddenPrefix(String hiddenPrefix) {
200+
System.out.println("Not reading entries starting with " + hiddenPrefix);
201+
this.ignoredPrefixes.add(hiddenPrefix);
202+
this.hiddenPrefixes.add(hiddenPrefix);
203+
}
204+
190205
@Override
191206
public void close() throws IOException {
192207
ijEnv.close();

0 commit comments

Comments
 (0)