Skip to content

Commit

Permalink
Use absolute paths in origin names (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt authored Jun 19, 2024
1 parent ef6c7ed commit 8274f92
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 232 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ build.dependsOn testsJar
dependencies {
testImplementation(libs.junit.api)
testImplementation(libs.powermock)
testImplementation(libs.assert4j)
testImplementation(libs.bsl)
testImplementation(libs.sjh)
testImplementation(libs.gson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void loadFromResource(final String resourceName) throws URISyntaxExceptio

public void loadFromPath(final Path path) throws IOException {
try (Reader reader = Files.newBufferedReader(path)) {
loadAT(reader, path.getFileName().toString());
loadAT(reader, path.toAbsolutePath().toString());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package net.neoforged.accesstransformer.parser;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

public final class Transformation {
private FinalState finalState;
private Modifier modifier;
private List<String> origins = new ArrayList<>();
private final FinalState finalState;
private final Modifier modifier;
private final List<String> origins = new ArrayList<>();

private Transformation(Modifier modifier, FinalState finalState) {
this.finalState = finalState;
Expand All @@ -28,7 +29,7 @@ public Modifier modifier() {
}

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

public enum FinalState {
Expand Down
3 changes: 2 additions & 1 deletion 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 All @@ -39,4 +40,4 @@ dependencyResolutionManagement {
rootProject.name = 'AccessTransformers'
include ':cli'
include ':modlauncher'
include ':parser'
include ':parser'
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.AccessTransformerList;
import net.neoforged.accesstransformer.ml.AccessTransformerService;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.powermock.reflect.Whitebox;

Expand All @@ -18,15 +19,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 @@ -37,11 +36,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 @@ -53,13 +52,14 @@ private static void testText(final Map<String, List<AccessTransformer<?>>> acces
)
);

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 8274f92

Please sign in to comment.