Skip to content

Commit

Permalink
Add hidden prefixes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lynxplay committed Dec 18, 2024
1 parent 7b55b32 commit af7ec81
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions cli/src/main/java/net/neoforged/jst/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class Main implements Callable<Integer> {
@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 = "--hidden-prefix", description = "Do not process or emit paths that start with any of these prefixes.")
List<String> hiddenPrefixes = 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 @@ -79,6 +82,10 @@ public Integer call() throws Exception {
for (String ignoredPrefix : ignoredPrefixes) {
processor.addIgnoredPrefix(ignoredPrefix);
}
for (String hiddenPrefix : hiddenPrefixes) {
processor.addIgnoredPrefix(hiddenPrefix);
processor.addHiddenPrefix(hiddenPrefix);
}

processor.setMaxQueueDepth(maxQueueDepth);

Expand Down
19 changes: 17 additions & 2 deletions cli/src/main/java/net/neoforged/jst/cli/SourceFileProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class SourceFileProcessor implements AutoCloseable {
private final Logger logger;

private final List<String> ignoredPrefixes = new ArrayList<>();
private final List<String> hiddenPrefixes = new ArrayList<>();

public SourceFileProcessor(Logger logger) throws IOException {
this.logger = logger;
Expand Down Expand Up @@ -114,13 +115,21 @@ private boolean processEntry(FileEntry entry, VirtualFile sourceRoot, List<Sourc
lastModified = FileTime.from(Instant.now());
}
}
sink.putFile(entry.relativePath(), lastModified, content);
if (!isHidden(entry.relativePath())) sink.putFile(entry.relativePath(), lastModified, content);
}
return true;
}

private boolean isIgnored(String relativePath) {
for (String ignoredPrefix : ignoredPrefixes) {
return isRelativePathIn(relativePath, this.ignoredPrefixes);
}

private boolean isHidden(String relativePath) {
return isRelativePathIn(relativePath, this.hiddenPrefixes);
}

private boolean isRelativePathIn(String relativePath, List<String> prefixes) {
for (String ignoredPrefix : prefixes) {
if (relativePath.startsWith(ignoredPrefix)) {
return true;
}
Expand Down Expand Up @@ -187,6 +196,12 @@ public void addIgnoredPrefix(String ignoredPrefix) {
this.ignoredPrefixes.add(ignoredPrefix);
}

public void addHiddenPrefix(String hiddenPrefix) {
System.out.println("Not reading entries starting with " + hiddenPrefix);
this.ignoredPrefixes.add(hiddenPrefix);
this.hiddenPrefixes.add(hiddenPrefix);
}

@Override
public void close() throws IOException {
ijEnv.close();
Expand Down

0 comments on commit af7ec81

Please sign in to comment.