Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Read the configuration path from a system property
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 committed Nov 21, 2023
1 parent b25263a commit ee92143
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import net.fabricmc.nameproposal.registry.Codecs;

public record NameProposalConfig(FieldNameProvider fieldNameProvider, int version) {
public static final String FILE_NAME = "name_proposal.json";
public static final String SYSTEM_PROPERTY_KEY = "name_proposal_config";

public static final Codec<NameProposalConfig> CODEC = Codecs.validate(RecordCodecBuilder.create(instance -> {
return instance.group(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -79,7 +80,7 @@ public Optional<String> proposeName(Entry<?> obfEntry, EntryRemapper remapper) {

private static NameFinder createNameFinder() {
Registry.init();
File file = new File("./" + NameProposalConfig.FILE_NAME);
File file = new File(System.getProperty(NameProposalConfig.SYSTEM_PROPERTY_KEY));

try (var reader = new FileReader(file)) {
var tree = JsonParser.parseReader(reader);
Expand All @@ -89,7 +90,7 @@ private static NameFinder createNameFinder() {

return new NameFinder(config);
} catch (IOException e) {
throw new RuntimeException("Failed to load name proposal config", e);
throw new UncheckedIOException("Failed to load name proposal config", e);
}
}
}
2 changes: 1 addition & 1 deletion src/test/java/net/fabricmc/nameproposal/FieldTestMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class FieldTestMain {

@Test
public void parseConfig() throws Throwable {
var url = FieldTestMain.class.getClassLoader().getResource(NameProposalConfig.FILE_NAME);
var url = FieldTestMain.class.getClassLoader().getResource("name_proposal.json");

try (var reader = new FileReader(new File(url.toURI()))) {
var tree = JsonParser.parseReader(reader);
Expand Down

0 comments on commit ee92143

Please sign in to comment.