Skip to content

Commit

Permalink
Use absolute paths in origin names (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
XFactHD authored Sep 25, 2024
1 parent beb8927 commit bb0f9f1
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 228 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ configurations {
dependencies {
testImplementation(libs.junit.api)
testImplementation(libs.powermock)
testImplementation(libs.assert4j)
testImplementation(libs.bsl)
testImplementation(libs.sjh)
testImplementation(libs.gson)
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencyResolutionManagement {
library('slf4j', 'org.slf4j:slf4j-api:2.0.9')
library('jopt', 'net.sf.jopt-simple:jopt-simple:6.0-alpha-3')
library('jopt5', 'net.sf.jopt-simple:jopt-simple:5.0.4')
library('assert4j', 'org.assertj:assertj-core:3.25.1')

library('log4j-api', 'org.apache.logging.log4j', 'log4j-api').versionRef(log4j)
library('log4j-core', 'org.apache.logging.log4j', 'log4j-core').versionRef(log4j)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -48,7 +49,7 @@ public boolean isValid() {
}

public List<String> getOrigins() {
return origins;
return Collections.unmodifiableList(origins);
}

public <T> void applyModifier(final T node, final Class<T> type, final Set<String> privateChanged) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void loadFromPath(final Path path) throws IOException {
StandardCharsets.UTF_8,
4096, // CharStreams.DEFAULT_BUFFER_SIZE
CodingErrorAction.REPLACE,
path.getFileName().toString(),
path.toAbsolutePath().toString(),
size));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.neoforged.accesstransformer.AccessTransformer;
import net.neoforged.accesstransformer.ml.AccessTransformerService;
import net.neoforged.accesstransformer.parser.AccessTransformerList;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.powermock.reflect.Whitebox;

Expand All @@ -22,15 +23,13 @@
import java.util.TreeMap;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AccessTransformerLoadTest {
@Test
public void testLoadForgeAT() throws IOException, URISyntaxException {
final AccessTransformerList atLoader = new AccessTransformerList();
atLoader.loadFromResource("forge_at.cfg");
final Map<String, List<AccessTransformer>> accessTransformers = atLoader.getAccessTransformers();
testText(accessTransformers);
testText(accessTransformers, Paths.get(ClassLoader.getSystemClassLoader().getResource("forge_at.cfg").toURI()));
}

@Test
Expand All @@ -41,11 +40,11 @@ public void testLoadATFromJar() throws IOException, URISyntaxException {
mls.engine.loadATFromPath(atPath);
final AccessTransformerList list = Whitebox.getInternalState(mls.engine, "masterList");
final Map<String, List<AccessTransformer>> accessTransformers = list.getAccessTransformers();
testText(accessTransformers);
testText(accessTransformers, atPath);
}
}

private static void testText(final Map<String, List<AccessTransformer>> accessTransformers) throws URISyntaxException, IOException {
private static void testText(final Map<String, List<AccessTransformer>> accessTransformers, Path source) throws URISyntaxException, IOException {
accessTransformers.forEach((k,v) -> System.out.printf("Got %d ATs for %s:\n\t%s\n", v.size(), k, v.stream().map(Object::toString).collect(Collectors.joining("\n\t"))));

final TreeMap<String, List<String>> testOutput = accessTransformers.entrySet().stream().collect(
Expand All @@ -57,13 +56,14 @@ private static void testText(final Map<String, List<AccessTransformer>> accessTr
)
);

final String text = new String(Files.readAllBytes(Paths.get(ClassLoader.getSystemClassLoader().getResource("forge_at.cfg.json").toURI())), StandardCharsets.UTF_8);
final String text = Files.readString(Paths.get(ClassLoader.getSystemClassLoader().getResource("forge_at.cfg.json").toURI()), StandardCharsets.UTF_8);
final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
final TreeMap<String, List<String>> expectation = GSON.fromJson(text, new TypeToken<TreeMap<String, List<String>>>() {}.getType());
expectation.values().forEach(value -> value.replaceAll(str -> str.replace("{cfgfile}", source.toAbsolutePath().toString())));

final String output = GSON.toJson(testOutput);
final String expect = GSON.toJson(expectation);

assertEquals(expect, output);
Assertions.assertThat(output).isEqualToNormalizingNewlines(expect);
}
}
Loading

0 comments on commit bb0f9f1

Please sign in to comment.