diff --git a/parchment/build.gradle b/parchment/build.gradle index 9f82cb3..e9ed8d7 100644 --- a/parchment/build.gradle +++ b/parchment/build.gradle @@ -5,5 +5,5 @@ plugins { dependencies { implementation project(":api") implementation 'org.parchmentmc.feather:io-gson:1.1.0' - implementation 'net.fabricmc:mapping-io:0.5.1' + implementation 'net.neoforged:srgutils:1.0.0' } diff --git a/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/NameAndDocSourceLoader.java b/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/NameAndDocSourceLoader.java index 0b0df80..fd74038 100644 --- a/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/NameAndDocSourceLoader.java +++ b/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/NameAndDocSourceLoader.java @@ -1,10 +1,8 @@ package net.neoforged.jst.parchment.namesanddocs; -import net.fabricmc.mappingio.MappingReader; -import net.fabricmc.mappingio.format.MappingFormat; -import net.fabricmc.mappingio.tree.MemoryMappingTree; -import net.neoforged.jst.parchment.namesanddocs.mappingio.TreeData; +import net.neoforged.jst.parchment.namesanddocs.srgutils.MappingFileDatabase; import net.neoforged.jst.parchment.namesanddocs.parchment.ParchmentDatabase; +import net.neoforged.srgutils.INamedMappingFile; import org.jetbrains.annotations.Nullable; import java.io.IOException; @@ -26,12 +24,7 @@ public static NamesAndDocsDatabase load(Path path, @Nullable NameAndDocsFormat f return switch (format) { case PARCHMENT_ZIP -> ParchmentDatabase.loadZip(path); case PARCHMENT_JSON -> ParchmentDatabase.loadJson(path); - case TSRG2 -> { - var tree = new MemoryMappingTree(true); - MappingReader.read(path, MappingFormat.TSRG_2_FILE, tree); - - yield new TreeData(tree); - } + case TSRG2 -> MappingFileDatabase.load(path); }; } @@ -48,5 +41,3 @@ private static NameAndDocsFormat guessFormat(Path path) { } } - - diff --git a/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/mappingio/TreeData.java b/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/mappingio/TreeData.java deleted file mode 100644 index 2e9f7ec..0000000 --- a/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/mappingio/TreeData.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.neoforged.jst.parchment.namesanddocs.mappingio; - -import net.fabricmc.mappingio.tree.MemoryMappingTree; -import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsDatabase; -import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsForClass; - -public class TreeData implements NamesAndDocsDatabase { - private final MemoryMappingTree tree; - - public TreeData(MemoryMappingTree tree) { - this.tree = tree; - } - - @Override - public NamesAndDocsForClass getClass(String className) { - var classData = tree.getClass(className, 0); - return classData != null ? new TreeClassData(classData) : null; - } -} diff --git a/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/mappingio/TreeClassData.java b/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/srgutils/MappingFileClassData.java similarity index 63% rename from parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/mappingio/TreeClassData.java rename to parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/srgutils/MappingFileClassData.java index 8741343..0511095 100644 --- a/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/mappingio/TreeClassData.java +++ b/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/srgutils/MappingFileClassData.java @@ -1,16 +1,16 @@ -package net.neoforged.jst.parchment.namesanddocs.mappingio; +package net.neoforged.jst.parchment.namesanddocs.srgutils; -import net.fabricmc.mappingio.tree.MappingTree; import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsForClass; import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsForField; import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsForMethod; +import net.neoforged.srgutils.IMappingFile; import java.util.List; -class TreeClassData implements NamesAndDocsForClass { - private final MappingTree.ClassMapping classData; +class MappingFileClassData implements NamesAndDocsForClass { + private final IMappingFile.IClass classData; - public TreeClassData(MappingTree.ClassMapping classData) { + public MappingFileClassData(IMappingFile.IClass classData) { this.classData = classData; } @@ -27,7 +27,7 @@ public NamesAndDocsForField getField(String name) { @Override public NamesAndDocsForMethod getMethod(String name, String methodSignature) { - var methodData = classData.getMethod(name, methodSignature, 0); - return methodData != null ? new TreeMethodData(methodData) : null; + var methodData = classData.getMethod(name, methodSignature); + return methodData != null ? new MappingFileMethodData(methodData) : null; } } diff --git a/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/srgutils/MappingFileDatabase.java b/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/srgutils/MappingFileDatabase.java new file mode 100644 index 0000000..f3003c0 --- /dev/null +++ b/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/srgutils/MappingFileDatabase.java @@ -0,0 +1,28 @@ +package net.neoforged.jst.parchment.namesanddocs.srgutils; + +import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsDatabase; +import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsForClass; +import net.neoforged.srgutils.IMappingFile; +import net.neoforged.srgutils.INamedMappingFile; + +import java.io.IOException; +import java.nio.file.Path; + +public class MappingFileDatabase implements NamesAndDocsDatabase { + private final IMappingFile tree; + + public MappingFileDatabase(INamedMappingFile tree) { + this.tree = tree.getMap("right", "right"); + } + + public static MappingFileDatabase load(Path path) throws IOException { + var mappingFile = INamedMappingFile.load(path.toFile()); + return new MappingFileDatabase(mappingFile); + } + + @Override + public NamesAndDocsForClass getClass(String className) { + var classData = tree.getClass(className); + return classData != null ? new MappingFileClassData(classData) : null; + } +} diff --git a/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/mappingio/TreeMethodData.java b/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/srgutils/MappingFileMethodData.java similarity index 61% rename from parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/mappingio/TreeMethodData.java rename to parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/srgutils/MappingFileMethodData.java index 55da46a..3147bc3 100644 --- a/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/mappingio/TreeMethodData.java +++ b/parchment/src/main/java/net/neoforged/jst/parchment/namesanddocs/srgutils/MappingFileMethodData.java @@ -1,16 +1,16 @@ -package net.neoforged.jst.parchment.namesanddocs.mappingio; +package net.neoforged.jst.parchment.namesanddocs.srgutils; -import net.fabricmc.mappingio.tree.MappingTree; import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsForMethod; import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsForParameter; +import net.neoforged.srgutils.IMappingFile; import org.jetbrains.annotations.Nullable; import java.util.List; -public class TreeMethodData implements NamesAndDocsForMethod { - private final MappingTree.MethodMapping methodData; +public class MappingFileMethodData implements NamesAndDocsForMethod { + private final IMappingFile.IMethod methodData; - public TreeMethodData(MappingTree.MethodMapping methodData) { + public MappingFileMethodData(IMappingFile.IMethod methodData) { this.methodData = methodData; } @@ -21,14 +21,14 @@ public List getJavadoc() { @Override public NamesAndDocsForParameter getParameter(int index) { - var paramData = methodData.getArg(0, index, null); - if (paramData == null || paramData.getName(0) == null) { + var paramData = methodData.getParameter(index); + if (paramData == null || paramData.getMapped() == null) { return null; } return new NamesAndDocsForParameter() { @Override public @Nullable String getName() { - return paramData.getName(0); + return paramData.getOriginal(); } @Override diff --git a/settings.gradle b/settings.gradle index 26abd54..ac9f6c8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -24,6 +24,9 @@ dependencyResolutionManagement { maven { url "https://maven.parchmentmc.org/" } + maven { + url "https://maven.neoforged.net/releases/" + } } } diff --git a/tests/data/tsrg_file/expected/pkg/TestClass.java b/tests/data/tsrg_file/expected/pkg/TestClass.java new file mode 100644 index 0000000..b29d9a6 --- /dev/null +++ b/tests/data/tsrg_file/expected/pkg/TestClass.java @@ -0,0 +1,8 @@ +package pkg; + +import java.util.*; + +public class TestClass { + public void m(String p_254545_, List p_254546_) { + } +} diff --git a/tests/data/tsrg_file/merged.tsrg b/tests/data/tsrg_file/merged.tsrg new file mode 100644 index 0000000..5aa6285 --- /dev/null +++ b/tests/data/tsrg_file/merged.tsrg @@ -0,0 +1,5 @@ +tsrg2 left right +obfuscated_c pkg/TestClass + obfuscated_m (Ljava/lang/String;Ljava/util/List;)V m + 1 o p_254545_ + 2 o p_254546_ diff --git a/tests/data/tsrg_file/source/pkg/TestClass.java b/tests/data/tsrg_file/source/pkg/TestClass.java new file mode 100644 index 0000000..778fcdc --- /dev/null +++ b/tests/data/tsrg_file/source/pkg/TestClass.java @@ -0,0 +1,8 @@ +package pkg; + +import java.util.*; + +public class TestClass { + public void m(String a1, List a2) { + } +} diff --git a/tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java b/tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java index e32ea52..3c2250f 100644 --- a/tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java +++ b/tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java @@ -186,27 +186,32 @@ void archiveOutput() throws Exception { @Test void testInnerAndLocalClasses() throws Exception { - runTest("nested"); + runTest("nested", "parchment.json"); } @Test void testExternalReferences() throws Exception { - runTest("external_refs"); + runTest("external_refs", "parchment.json"); } @Test void testParamIndices() throws Exception { - runTest("param_indices"); + runTest("param_indices", "parchment.json"); } @Test void testJavadoc() throws Exception { - runTest("javadoc"); + runTest("javadoc", "parchment.json"); } - protected final void runTest(String testDirName) throws Exception { + @Test + void testTsrgMappings() throws Exception { + runTest("tsrg_file", "merged.tsrg"); + } + + protected final void runTest(String testDirName, String mappingsFilename) throws Exception { var testDir = testDataRoot.resolve(testDirName); - var parchmentFile = testDir.resolve("parchment.json"); + var mappingsFile = testDir.resolve(mappingsFilename); var sourceDir = testDir.resolve("source"); var expectedDir = testDir.resolve("expected"); @@ -227,7 +232,7 @@ protected final void runTest(String testDirName) throws Exception { librariesFile.toString(), "--enable-parchment", "--parchment-mappings", - parchmentFile.toString(), + mappingsFile.toString(), inputFile.toString(), outputFile.toString() );