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 adding single files to input #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,22 @@ public CompletableFuture<?> readClassPathAsync(final Path... inputs) {

return ret;
}

public void readClassPathFile(Path file) {
readSingleClass(false, null, file);
}

public void readClasspathFile(InputTag tag, Path file) {
readSingleClass(false, tag, file);
}

public void readInputFile(Path file) {
readSingleClass(true, null, file);
}

public void readInputFile(InputTag tag, Path file) {
readSingleClass(true, tag, file);
}

private CompletableFuture<List<ClassInstance>> read(Path[] inputs, boolean isInput, InputTag tag) {
InputTag[] tags = singleInputTags.get().get(tag);
Expand Down Expand Up @@ -426,6 +442,30 @@ private CompletableFuture<List<ClassInstance>> read(Path[] inputs, boolean isInp
assert dirty;
});
}

private void readSingleClass(boolean isInput, InputTag tag, Path file) {
try {
InputTag[] tags = singleInputTags.get().get(tag);
List<FileSystemReference> references = new ArrayList<>();
List<ClassInstance> instance = readFile(file, isInput, tags, file.getRoot(), references);
for(FileSystemReference reference : references) {
reference.close();
}

if (!dirty) {
dirty = true;
for (MrjState state : mrjStates.values()) {
state.dirty = true;
}
}

for(ClassInstance inst : instance) {
addClass(inst, readClasses, true);
}
} catch (IOException | URISyntaxException e) {
throw new RuntimeException(e);
}
}

private static void addClass(ClassInstance cls, Map<String, ClassInstance> out, boolean isVersionAware) {
// two different MRJ version will not cause warning if isVersionAware is true
Expand Down