diff options
| author | 2023-11-28 09:00:33 +0000 | |
|---|---|---|
| committer | 2023-11-28 09:00:33 +0000 | |
| commit | 7622b753d2a99bd8f2bbb4568fd84ca9458ffba5 (patch) | |
| tree | e3a5a6d2006787f2668e47bca34fb46beb40250c /enigma-cli/src/main/java/cuchaz/enigma/command | |
| parent | Update deps (#535) (diff) | |
| parent | Merge branch 'upstream' into mapping-io (diff) | |
| download | enigma-fork-7622b753d2a99bd8f2bbb4568fd84ca9458ffba5.tar.gz enigma-fork-7622b753d2a99bd8f2bbb4568fd84ca9458ffba5.tar.xz enigma-fork-7622b753d2a99bd8f2bbb4568fd84ca9458ffba5.zip | |
Merge pull request #463 from NebelNidas/mapping-io
Initial Mapping-IO support
Diffstat (limited to 'enigma-cli/src/main/java/cuchaz/enigma/command')
3 files changed, 53 insertions, 23 deletions
diff --git a/enigma-cli/src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java b/enigma-cli/src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java index 922d668..5e64b2c 100644 --- a/enigma-cli/src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java +++ b/enigma-cli/src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java | |||
| @@ -10,7 +10,6 @@ import cuchaz.enigma.ProgressListener; | |||
| 10 | import cuchaz.enigma.analysis.index.JarIndex; | 10 | import cuchaz.enigma.analysis.index.JarIndex; |
| 11 | import cuchaz.enigma.classprovider.ClasspathClassProvider; | 11 | import cuchaz.enigma.classprovider.ClasspathClassProvider; |
| 12 | import cuchaz.enigma.translation.mapping.EntryMapping; | 12 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 13 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | ||
| 14 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; | 13 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; |
| 15 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 14 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 16 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 15 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| @@ -38,15 +37,12 @@ public class CheckMappingsCommand extends Command { | |||
| 38 | Enigma enigma = Enigma.create(); | 37 | Enigma enigma = Enigma.create(); |
| 39 | 38 | ||
| 40 | System.out.println("Reading JAR..."); | 39 | System.out.println("Reading JAR..."); |
| 41 | |||
| 42 | EnigmaProject project = enigma.openJar(fileJarIn, new ClasspathClassProvider(), ProgressListener.none()); | 40 | EnigmaProject project = enigma.openJar(fileJarIn, new ClasspathClassProvider(), ProgressListener.none()); |
| 43 | 41 | ||
| 44 | System.out.println("Reading mappings..."); | 42 | System.out.println("Reading mappings..."); |
| 45 | |||
| 46 | MappingFormat format = chooseEnigmaFormat(fileMappings); | ||
| 47 | MappingSaveParameters saveParameters = enigma.getProfile().getMappingSaveParameters(); | 43 | MappingSaveParameters saveParameters = enigma.getProfile().getMappingSaveParameters(); |
| 48 | 44 | ||
| 49 | EntryTree<EntryMapping> mappings = format.read(fileMappings, ProgressListener.none(), saveParameters); | 45 | EntryTree<EntryMapping> mappings = readMappings(fileMappings, ProgressListener.none(), saveParameters); |
| 50 | project.setMappings(mappings); | 46 | project.setMappings(mappings); |
| 51 | 47 | ||
| 52 | JarIndex idx = project.getJarIndex(); | 48 | JarIndex idx = project.getJarIndex(); |
diff --git a/enigma-cli/src/main/java/cuchaz/enigma/command/Command.java b/enigma-cli/src/main/java/cuchaz/enigma/command/Command.java index 04d49f2..de06fa6 100644 --- a/enigma-cli/src/main/java/cuchaz/enigma/command/Command.java +++ b/enigma-cli/src/main/java/cuchaz/enigma/command/Command.java | |||
| @@ -1,11 +1,15 @@ | |||
| 1 | package cuchaz.enigma.command; | 1 | package cuchaz.enigma.command; |
| 2 | 2 | ||
| 3 | import java.io.File; | 3 | import java.io.File; |
| 4 | import java.io.IOException; | ||
| 4 | import java.nio.file.Files; | 5 | import java.nio.file.Files; |
| 5 | import java.nio.file.Path; | 6 | import java.nio.file.Path; |
| 6 | import java.nio.file.Paths; | 7 | import java.nio.file.Paths; |
| 7 | 8 | ||
| 8 | import com.google.common.io.MoreFiles; | 9 | import com.google.common.io.MoreFiles; |
| 10 | import net.fabricmc.mappingio.MappingReader; | ||
| 11 | import net.fabricmc.mappingio.tree.MemoryMappingTree; | ||
| 12 | import net.fabricmc.mappingio.tree.VisitableMappingTree; | ||
| 9 | 13 | ||
| 10 | import cuchaz.enigma.Enigma; | 14 | import cuchaz.enigma.Enigma; |
| 11 | import cuchaz.enigma.EnigmaProject; | 15 | import cuchaz.enigma.EnigmaProject; |
| @@ -13,6 +17,8 @@ import cuchaz.enigma.ProgressListener; | |||
| 13 | import cuchaz.enigma.classprovider.ClasspathClassProvider; | 17 | import cuchaz.enigma.classprovider.ClasspathClassProvider; |
| 14 | import cuchaz.enigma.translation.mapping.EntryMapping; | 18 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 15 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | 19 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; |
| 20 | import cuchaz.enigma.translation.mapping.serde.MappingIoConverter; | ||
| 21 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; | ||
| 16 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; | 22 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; |
| 17 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 23 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 18 | 24 | ||
| @@ -41,7 +47,7 @@ public abstract class Command { | |||
| 41 | System.out.println("Reading mappings..."); | 47 | System.out.println("Reading mappings..."); |
| 42 | 48 | ||
| 43 | MappingSaveParameters saveParameters = enigma.getProfile().getMappingSaveParameters(); | 49 | MappingSaveParameters saveParameters = enigma.getProfile().getMappingSaveParameters(); |
| 44 | EntryTree<EntryMapping> mappings = chooseEnigmaFormat(fileMappings).read(fileMappings, progress, saveParameters); | 50 | EntryTree<EntryMapping> mappings = readMappings(fileMappings, progress, saveParameters); |
| 45 | 51 | ||
| 46 | project.setMappings(mappings); | 52 | project.setMappings(mappings); |
| 47 | } | 53 | } |
| @@ -49,14 +55,18 @@ public abstract class Command { | |||
| 49 | return project; | 55 | return project; |
| 50 | } | 56 | } |
| 51 | 57 | ||
| 52 | protected static MappingFormat chooseEnigmaFormat(Path path) { | 58 | protected static EntryTree<EntryMapping> readMappings(Path path, ProgressListener progress, MappingSaveParameters saveParameters) throws IOException, MappingParseException { |
| 53 | if (Files.isDirectory(path)) { | 59 | // Legacy |
| 54 | return MappingFormat.ENIGMA_DIRECTORY; | 60 | if ("zip".equalsIgnoreCase(MoreFiles.getFileExtension(path))) { |
| 55 | } else if ("zip".equalsIgnoreCase(MoreFiles.getFileExtension(path))) { | 61 | return MappingFormat.ENIGMA_ZIP.read(path, progress, saveParameters, null); |
| 56 | return MappingFormat.ENIGMA_ZIP; | ||
| 57 | } else { | ||
| 58 | return MappingFormat.ENIGMA_FILE; | ||
| 59 | } | 62 | } |
| 63 | |||
| 64 | net.fabricmc.mappingio.format.MappingFormat format = MappingReader.detectFormat(path); | ||
| 65 | if (format == null) throw new IllegalArgumentException("Unknown mapping format!"); | ||
| 66 | |||
| 67 | VisitableMappingTree tree = new MemoryMappingTree(); | ||
| 68 | MappingReader.read(path, format, tree); | ||
| 69 | return MappingIoConverter.fromMappingIo(tree, progress, null); | ||
| 60 | } | 70 | } |
| 61 | 71 | ||
| 62 | protected static File getWritableFile(String path) { | 72 | protected static File getWritableFile(String path) { |
diff --git a/enigma-cli/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java b/enigma-cli/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java index 787625b..e1e216a 100644 --- a/enigma-cli/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java +++ b/enigma-cli/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java | |||
| @@ -1,17 +1,19 @@ | |||
| 1 | package cuchaz.enigma.command; | 1 | package cuchaz.enigma.command; |
| 2 | 2 | ||
| 3 | import java.io.IOException; | 3 | import java.io.IOException; |
| 4 | import java.io.UncheckedIOException; | ||
| 4 | import java.nio.file.Files; | 5 | import java.nio.file.Files; |
| 5 | import java.nio.file.Path; | 6 | import java.nio.file.Path; |
| 6 | 7 | ||
| 8 | import net.fabricmc.mappingio.MappingWriter; | ||
| 9 | import net.fabricmc.mappingio.tree.VisitableMappingTree; | ||
| 10 | |||
| 7 | import cuchaz.enigma.ProgressListener; | 11 | import cuchaz.enigma.ProgressListener; |
| 8 | import cuchaz.enigma.translation.mapping.EntryMapping; | 12 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 9 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | 13 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; |
| 14 | import cuchaz.enigma.translation.mapping.serde.MappingIoConverter; | ||
| 10 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; | 15 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; |
| 11 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; | 16 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; |
| 12 | import cuchaz.enigma.translation.mapping.serde.enigma.EnigmaMappingsReader; | ||
| 13 | import cuchaz.enigma.translation.mapping.serde.enigma.EnigmaMappingsWriter; | ||
| 14 | import cuchaz.enigma.translation.mapping.serde.tiny.TinyMappingsReader; | ||
| 15 | import cuchaz.enigma.translation.mapping.serde.tiny.TinyMappingsWriter; | 17 | import cuchaz.enigma.translation.mapping.serde.tiny.TinyMappingsWriter; |
| 16 | import cuchaz.enigma.translation.mapping.serde.tinyv2.TinyV2Writer; | 18 | import cuchaz.enigma.translation.mapping.serde.tinyv2.TinyV2Writer; |
| 17 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 19 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| @@ -22,11 +24,11 @@ public final class MappingCommandsUtil { | |||
| 22 | 24 | ||
| 23 | public static EntryTree<EntryMapping> read(String type, Path path, MappingSaveParameters saveParameters) throws MappingParseException, IOException { | 25 | public static EntryTree<EntryMapping> read(String type, Path path, MappingSaveParameters saveParameters) throws MappingParseException, IOException { |
| 24 | if (type.equals("enigma")) { | 26 | if (type.equals("enigma")) { |
| 25 | return (Files.isDirectory(path) ? EnigmaMappingsReader.DIRECTORY : EnigmaMappingsReader.ZIP).read(path, ProgressListener.none(), saveParameters); | 27 | return (Files.isDirectory(path) ? MappingFormat.ENIGMA_DIRECTORY : MappingFormat.ENIGMA_ZIP).read(path, ProgressListener.none(), saveParameters, null); |
| 26 | } | 28 | } |
| 27 | 29 | ||
| 28 | if (type.equals("tiny")) { | 30 | if (type.equals("tiny")) { |
| 29 | return TinyMappingsReader.INSTANCE.read(path, ProgressListener.none(), saveParameters); | 31 | return MappingFormat.TINY_FILE.read(path, ProgressListener.none(), saveParameters, null); |
| 30 | } | 32 | } |
| 31 | 33 | ||
| 32 | MappingFormat format = null; | 34 | MappingFormat format = null; |
| @@ -40,7 +42,7 @@ public final class MappingCommandsUtil { | |||
| 40 | } | 42 | } |
| 41 | 43 | ||
| 42 | if (format != null) { | 44 | if (format != null) { |
| 43 | return format.getReader().read(path, ProgressListener.none(), saveParameters); | 45 | return format.read(path, ProgressListener.none(), saveParameters, null); |
| 44 | } | 46 | } |
| 45 | 47 | ||
| 46 | throw new IllegalArgumentException("no reader for " + type); | 48 | throw new IllegalArgumentException("no reader for " + type); |
| @@ -48,7 +50,7 @@ public final class MappingCommandsUtil { | |||
| 48 | 50 | ||
| 49 | public static void write(EntryTree<EntryMapping> mappings, String type, Path path, MappingSaveParameters saveParameters) { | 51 | public static void write(EntryTree<EntryMapping> mappings, String type, Path path, MappingSaveParameters saveParameters) { |
| 50 | if (type.equals("enigma")) { | 52 | if (type.equals("enigma")) { |
| 51 | EnigmaMappingsWriter.DIRECTORY.write(mappings, path, ProgressListener.none(), saveParameters); | 53 | MappingFormat.ENIGMA_DIRECTORY.write(mappings, path, ProgressListener.none(), saveParameters); |
| 52 | return; | 54 | return; |
| 53 | } | 55 | } |
| 54 | 56 | ||
| @@ -59,7 +61,18 @@ public final class MappingCommandsUtil { | |||
| 59 | throw new IllegalArgumentException("specify column names as 'tinyv2:from_namespace:to_namespace'"); | 61 | throw new IllegalArgumentException("specify column names as 'tinyv2:from_namespace:to_namespace'"); |
| 60 | } | 62 | } |
| 61 | 63 | ||
| 62 | new TinyV2Writer(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters); | 64 | if (!System.getProperty("enigma.use_mappingio", "true").equals("true")) { |
| 65 | new TinyV2Writer(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters); | ||
| 66 | return; | ||
| 67 | } | ||
| 68 | |||
| 69 | try { | ||
| 70 | VisitableMappingTree tree = MappingIoConverter.toMappingIo(mappings, ProgressListener.none(), split[1], split[2]); | ||
| 71 | tree.accept(MappingWriter.create(path, net.fabricmc.mappingio.format.MappingFormat.TINY_2_FILE)); | ||
| 72 | } catch (IOException e) { | ||
| 73 | throw new UncheckedIOException(e); | ||
| 74 | } | ||
| 75 | |||
| 63 | return; | 76 | return; |
| 64 | } | 77 | } |
| 65 | 78 | ||
| @@ -70,7 +83,18 @@ public final class MappingCommandsUtil { | |||
| 70 | throw new IllegalArgumentException("specify column names as 'tiny:from_column:to_column'"); | 83 | throw new IllegalArgumentException("specify column names as 'tiny:from_column:to_column'"); |
| 71 | } | 84 | } |
| 72 | 85 | ||
| 73 | new TinyMappingsWriter(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters); | 86 | if (!System.getProperty("enigma.use_mappingio", "true").equals("true")) { |
| 87 | new TinyMappingsWriter(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters); | ||
| 88 | return; | ||
| 89 | } | ||
| 90 | |||
| 91 | try { | ||
| 92 | VisitableMappingTree tree = MappingIoConverter.toMappingIo(mappings, ProgressListener.none(), split[1], split[2]); | ||
| 93 | tree.accept(MappingWriter.create(path, net.fabricmc.mappingio.format.MappingFormat.TINY_FILE)); | ||
| 94 | } catch (IOException e) { | ||
| 95 | throw new UncheckedIOException(e); | ||
| 96 | } | ||
| 97 | |||
| 74 | return; | 98 | return; |
| 75 | } | 99 | } |
| 76 | 100 | ||
| @@ -83,7 +107,7 @@ public final class MappingCommandsUtil { | |||
| 83 | } | 107 | } |
| 84 | 108 | ||
| 85 | if (format != null) { | 109 | if (format != null) { |
| 86 | format.getWriter().write(mappings, path, ProgressListener.none(), saveParameters); | 110 | format.write(mappings, path, ProgressListener.none(), saveParameters); |
| 87 | return; | 111 | return; |
| 88 | } | 112 | } |
| 89 | 113 | ||