diff options
Diffstat (limited to 'enigma-cli/src/main/java')
3 files changed, 43 insertions, 24 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..ef7cfaa 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); |
| 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); | ||
| 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..c452d8c 100644 --- a/enigma-cli/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java +++ b/enigma-cli/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java | |||
| @@ -4,14 +4,15 @@ import java.io.IOException; | |||
| 4 | import java.nio.file.Files; | 4 | import java.nio.file.Files; |
| 5 | import java.nio.file.Path; | 5 | import java.nio.file.Path; |
| 6 | 6 | ||
| 7 | import net.fabricmc.mappingio.MappingWriter; | ||
| 8 | import net.fabricmc.mappingio.tree.VisitableMappingTree; | ||
| 9 | |||
| 7 | import cuchaz.enigma.ProgressListener; | 10 | import cuchaz.enigma.ProgressListener; |
| 8 | import cuchaz.enigma.translation.mapping.EntryMapping; | 11 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 9 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | 12 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; |
| 13 | import cuchaz.enigma.translation.mapping.serde.MappingIoConverter; | ||
| 10 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; | 14 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; |
| 11 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; | 15 | 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; | 16 | import cuchaz.enigma.translation.mapping.serde.tiny.TinyMappingsWriter; |
| 16 | import cuchaz.enigma.translation.mapping.serde.tinyv2.TinyV2Writer; | 17 | import cuchaz.enigma.translation.mapping.serde.tinyv2.TinyV2Writer; |
| 17 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 18 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| @@ -22,11 +23,11 @@ public final class MappingCommandsUtil { | |||
| 22 | 23 | ||
| 23 | public static EntryTree<EntryMapping> read(String type, Path path, MappingSaveParameters saveParameters) throws MappingParseException, IOException { | 24 | public static EntryTree<EntryMapping> read(String type, Path path, MappingSaveParameters saveParameters) throws MappingParseException, IOException { |
| 24 | if (type.equals("enigma")) { | 25 | if (type.equals("enigma")) { |
| 25 | return (Files.isDirectory(path) ? EnigmaMappingsReader.DIRECTORY : EnigmaMappingsReader.ZIP).read(path, ProgressListener.none(), saveParameters); | 26 | return (Files.isDirectory(path) ? MappingFormat.ENIGMA_DIRECTORY : MappingFormat.ENIGMA_ZIP).read(path, ProgressListener.none(), saveParameters); |
| 26 | } | 27 | } |
| 27 | 28 | ||
| 28 | if (type.equals("tiny")) { | 29 | if (type.equals("tiny")) { |
| 29 | return TinyMappingsReader.INSTANCE.read(path, ProgressListener.none(), saveParameters); | 30 | return MappingFormat.TINY_FILE.read(path, ProgressListener.none(), saveParameters); |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | MappingFormat format = null; | 33 | MappingFormat format = null; |
| @@ -40,15 +41,15 @@ public final class MappingCommandsUtil { | |||
| 40 | } | 41 | } |
| 41 | 42 | ||
| 42 | if (format != null) { | 43 | if (format != null) { |
| 43 | return format.getReader().read(path, ProgressListener.none(), saveParameters); | 44 | return format.read(path, ProgressListener.none(), saveParameters); |
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | throw new IllegalArgumentException("no reader for " + type); | 47 | throw new IllegalArgumentException("no reader for " + type); |
| 47 | } | 48 | } |
| 48 | 49 | ||
| 49 | public static void write(EntryTree<EntryMapping> mappings, String type, Path path, MappingSaveParameters saveParameters) { | 50 | public static void write(EntryTree<EntryMapping> mappings, String type, Path path, MappingSaveParameters saveParameters) throws IOException { |
| 50 | if (type.equals("enigma")) { | 51 | if (type.equals("enigma")) { |
| 51 | EnigmaMappingsWriter.DIRECTORY.write(mappings, path, ProgressListener.none(), saveParameters); | 52 | MappingFormat.ENIGMA_DIRECTORY.write(mappings, path, ProgressListener.none(), saveParameters); |
| 52 | return; | 53 | return; |
| 53 | } | 54 | } |
| 54 | 55 | ||
| @@ -59,7 +60,13 @@ public final class MappingCommandsUtil { | |||
| 59 | throw new IllegalArgumentException("specify column names as 'tinyv2:from_namespace:to_namespace'"); | 60 | throw new IllegalArgumentException("specify column names as 'tinyv2:from_namespace:to_namespace'"); |
| 60 | } | 61 | } |
| 61 | 62 | ||
| 62 | new TinyV2Writer(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters); | 63 | if (!System.getProperty("enigma.use_mappingio", "true").equals("true")) { |
| 64 | new TinyV2Writer(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters); | ||
| 65 | return; | ||
| 66 | } | ||
| 67 | |||
| 68 | VisitableMappingTree tree = MappingIoConverter.toMappingIo(mappings, ProgressListener.none(), split[1], split[2]); | ||
| 69 | tree.accept(MappingWriter.create(path, net.fabricmc.mappingio.format.MappingFormat.TINY_2_FILE)); | ||
| 63 | return; | 70 | return; |
| 64 | } | 71 | } |
| 65 | 72 | ||
| @@ -70,7 +77,13 @@ public final class MappingCommandsUtil { | |||
| 70 | throw new IllegalArgumentException("specify column names as 'tiny:from_column:to_column'"); | 77 | throw new IllegalArgumentException("specify column names as 'tiny:from_column:to_column'"); |
| 71 | } | 78 | } |
| 72 | 79 | ||
| 73 | new TinyMappingsWriter(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters); | 80 | if (!System.getProperty("enigma.use_mappingio", "true").equals("true")) { |
| 81 | new TinyMappingsWriter(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters); | ||
| 82 | return; | ||
| 83 | } | ||
| 84 | |||
| 85 | VisitableMappingTree tree = MappingIoConverter.toMappingIo(mappings, ProgressListener.none(), split[1], split[2]); | ||
| 86 | tree.accept(MappingWriter.create(path, net.fabricmc.mappingio.format.MappingFormat.TINY_FILE)); | ||
| 74 | return; | 87 | return; |
| 75 | } | 88 | } |
| 76 | 89 | ||
| @@ -83,7 +96,7 @@ public final class MappingCommandsUtil { | |||
| 83 | } | 96 | } |
| 84 | 97 | ||
| 85 | if (format != null) { | 98 | if (format != null) { |
| 86 | format.getWriter().write(mappings, path, ProgressListener.none(), saveParameters); | 99 | format.write(mappings, path, ProgressListener.none(), saveParameters); |
| 87 | return; | 100 | return; |
| 88 | } | 101 | } |
| 89 | 102 | ||