Skip to content

Commit

Permalink
update mapping-io
Browse files Browse the repository at this point in the history
  • Loading branch information
ramidzkh committed Nov 22, 2023
1 parent 9a6206b commit 61e097f
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 118 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ repositories {
}

dependencies {
implementation("net.fabricmc:mapping-io:0.3.0")
implementation("net.fabricmc:mapping-io:0.5.0")
implementation(files(RepackagedJavacProvider.createJavacJar(buildDir)))

implementation("org.ow2.asm:asm-util:9.6")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.0")
}

java {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "java"
id("java")
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/astrarre/sfu/impl/DescVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Void visitTypeVariable(TypeVariable t, Void unused) {

@Override
public Void visitWildcard(WildcardType t, Void unused) {
var type = t.getExtendsBound();
TypeMirror type = t.getExtendsBound();
if (type != null) {
this.visit(type);
} else {
Expand Down
69 changes: 0 additions & 69 deletions src/main/java/io/github/astrarre/sfu/impl/JavaFileParser.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void addTypeRange(Tree tree) { // todo find "roots" (eg. array element types, ea
return;
JCTree internal = (JCTree) tree;
// todo test for full qualification
var e = new TypeRange(internal.getStartPosition(), internal.getEndPosition(this.root.endPositions),
TypeRange e = new TypeRange(internal.getStartPosition(), internal.getEndPosition(this.root.endPositions),
this.util.getDesc(tree), false);
this.types.add(e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/astrarre/sfu/impl/Remapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Remapper(StringBuilder builder,
public void apply() {
for (RangeCollectingVisitor.MemberRange member : this.members) {
String name = member.name();
var mapping = member.isMethod()
MappingTreeView.MemberMappingView mapping = member.isMethod()
? this.view.getMethod(member.owner(), name, member.desc(), this.srcNamespace)
: this.view.getField(member.owner(), name, member.desc(), this.srcNamespace);

Expand Down
27 changes: 14 additions & 13 deletions src/main/java/io/github/astrarre/sfu/impl/SFUImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.StreamSupport;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.NestingKind;
import javax.tools.*;
Expand Down Expand Up @@ -92,27 +93,27 @@ public void process() throws IOException {
diagnostics,
List.of("-proc:none"),
null,
inputs.entrySet().stream().map(path -> {
Iterator<? extends JavaFileObject> iterable = fileManager
.getJavaFileObjectsFromPaths(List.of(path.getKey())).iterator();
JavaFileObject object = iterable.next();
assert !iterable.hasNext();
return new WJavaFileObject(object, path.getValue());
}).toList());
inputs.entrySet().stream()
.flatMap(path -> StreamSupport
.stream(fileManager.getJavaFileObjectsFromPaths(List.of(path.getKey())).spliterator(),
false)
.map(it -> new WrappedJavaFileObject(it, path.getValue())))
.toList());
ClientCodeWrapper wrapper = ClientCodeWrapper.instance(task.getContext());
Trees trees = Trees.instance(task);

Iterable<? extends CompilationUnitTree> codeResult = task.parse();
Iterable<? extends CompilationUnitTree> units = task.parse();
task.analyze();

for (CompilationUnitTree codeTree : codeResult) {
var collector = new RangeCollectingVisitor(trees);
for (CompilationUnitTree codeTree : units) {
RangeCollectingVisitor collector = new RangeCollectingVisitor(trees);
codeTree.accept(collector, null);

WJavaFileObject sourceFile;
WrappedJavaFileObject sourceFile;

try {
sourceFile = (WJavaFileObject) (JavaFileObject) UNWRAP.invokeExact(wrapper, codeTree.getSourceFile());
sourceFile = (WrappedJavaFileObject) (JavaFileObject) UNWRAP.invokeExact(wrapper,
codeTree.getSourceFile());
} catch (Throwable e) {
throw new RuntimeException(e);
}
Expand All @@ -126,7 +127,7 @@ public void process() throws IOException {
}
}

record WJavaFileObject(JavaFileObject object, Path output) implements JavaFileObject {
record WrappedJavaFileObject(JavaFileObject object, Path output) implements JavaFileObject {
@Override
public Kind getKind() {
return object.getKind();
Expand Down
63 changes: 35 additions & 28 deletions src/test/java/io/github/astrarre/sfu/test/RemappingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,53 @@
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import net.fabricmc.mappingio.format.Tiny2Reader;
import net.fabricmc.mappingio.MappingReader;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.tree.MemoryMappingTree;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

public class RemappingTests {

@Test
public void remap() throws IOException {
Path root = Path.of("src/test/resources");
Path originals = root.resolve("original");
Path remapped = root.resolve("remapped");
Path mappings = root.resolve("mappings");
Path tempRoot = Files.createTempDirectory("mercury-test");
Path tempRoot = Files.createTempDirectory("mercury-test");
Path root = Path.of("src/test/resources");
Path originals = root.resolve("original");
Path remapped = root.resolve("remapped");
Path mappings = root.resolve("mappings");

for (Path original : Files.list(originals).toList()) {
Path name = originals.relativize(original);
Path output = tempRoot.resolve(name);
Path test = remapped.resolve(name);
public RemappingTests() throws IOException {
}

MemoryMappingTree tree = new MemoryMappingTree();
@ParameterizedTest(name = ParameterizedTest.ARGUMENTS_PLACEHOLDER)
@ValueSource(strings = {
"fields",
"verbatim",
})
public void remap(String testCase) throws IOException {
Path original = originals.resolve(testCase);
Path output = tempRoot.resolve(testCase);
Path test = remapped.resolve(testCase);

try (Reader reader = Files.newBufferedReader(mappings.resolve(name + ".tiny"))) {
Tiny2Reader.read(reader, tree);
}
MemoryMappingTree tree = new MemoryMappingTree();

SourceFixerUpper sfu = SourceFixerUpper.create()
.mappings(tree, tree.getNamespaceId("a"), tree.getNamespaceId("b"));
try (Reader reader = Files.newBufferedReader(mappings.resolve(testCase + ".tiny"))) {
MappingReader.read(reader, MappingFormat.TINY_2_FILE, tree);
}

Files.walk(original).forEach(path -> {
if (Files.isRegularFile(path)) {
sfu.input(path, output.resolve(original.relativize(path)));
}
});
SourceFixerUpper sfu = SourceFixerUpper.create()
.mappings(tree, tree.getNamespaceId("a"), tree.getNamespaceId("b"));

sfu.process();
Files.walk(original).forEach(path -> {
if (Files.isRegularFile(path)) {
sfu.input(path, output.resolve(original.relativize(path)));
}
});

verifyDirsAreEqual(output, test, false);
verifyDirsAreEqual(test, output, true);
}
sfu.process();

verifyDirsAreEqual(output, test, false);
verifyDirsAreEqual(test, output, true);
}

private static void verifyDirsAreEqual(Path one, Path other, boolean flip) throws IOException {
Expand Down

0 comments on commit 61e097f

Please sign in to comment.