From c2ce8897a5ebe3b74d3995d4ccc4c0c277e44247 Mon Sep 17 00:00:00 2001 From: NebelNidas Date: Tue, 27 Aug 2024 16:22:02 +0200 Subject: Update to Mapping-IO 0.6 (#547) * Update to Mapping-IO 0.6 * Make `legacy` suffix translatable * Only respect `use_mappingio=false` when Enigma has an alternative reader/writer--- .../translation/mapping/serde/MappingFormat.java | 56 ++++++++++------------ 1 file changed, 24 insertions(+), 32 deletions(-) (limited to 'enigma/src/main/java') diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java index c9707b9..bb70c04 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java @@ -34,18 +34,20 @@ import cuchaz.enigma.translation.mapping.tree.EntryTree; import cuchaz.enigma.utils.I18n; public enum MappingFormat { - ENIGMA_FILE(EnigmaMappingsWriter.FILE, EnigmaMappingsReader.FILE, FileType.MAPPING, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_FILE, true), - ENIGMA_DIRECTORY(EnigmaMappingsWriter.DIRECTORY, EnigmaMappingsReader.DIRECTORY, FileType.DIRECTORY, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_DIR, true), - ENIGMA_ZIP(EnigmaMappingsWriter.ZIP, EnigmaMappingsReader.ZIP, FileType.ZIP, null, false), - TINY_V2(new TinyV2Writer("intermediary", "named"), new TinyV2Reader(), FileType.TINY, net.fabricmc.mappingio.format.MappingFormat.TINY_2_FILE, true), - TINY_FILE(TinyMappingsWriter.INSTANCE, TinyMappingsReader.INSTANCE, FileType.TINY, net.fabricmc.mappingio.format.MappingFormat.TINY_FILE, true), - SRG_FILE(SrgMappingsWriter.INSTANCE, null, FileType.SRG, net.fabricmc.mappingio.format.MappingFormat.SRG_FILE, true), - XSRG_FILE(null, null, FileType.XSRG, net.fabricmc.mappingio.format.MappingFormat.XSRG_FILE, true), - CSRG_FILE(null, null, FileType.CSRG, net.fabricmc.mappingio.format.MappingFormat.CSRG_FILE, false), - TSRG_FILE(null, null, FileType.TSRG, net.fabricmc.mappingio.format.MappingFormat.TSRG_FILE, false), - TSRG_2_FILE(null, null, FileType.TSRG, net.fabricmc.mappingio.format.MappingFormat.TSRG_2_FILE, false), - PROGUARD(null, ProguardMappingsReader.INSTANCE, FileType.TXT, net.fabricmc.mappingio.format.MappingFormat.PROGUARD_FILE, true), - RECAF(RecafMappingsWriter.INSTANCE, RecafMappingsReader.INSTANCE, FileType.TXT, null, false); + ENIGMA_FILE(EnigmaMappingsWriter.FILE, EnigmaMappingsReader.FILE, FileType.MAPPING, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_FILE), + ENIGMA_DIRECTORY(EnigmaMappingsWriter.DIRECTORY, EnigmaMappingsReader.DIRECTORY, FileType.DIRECTORY, net.fabricmc.mappingio.format.MappingFormat.ENIGMA_DIR), + ENIGMA_ZIP(EnigmaMappingsWriter.ZIP, EnigmaMappingsReader.ZIP, FileType.ZIP, null), + TINY_V2(new TinyV2Writer("intermediary", "named"), new TinyV2Reader(), FileType.TINY, net.fabricmc.mappingio.format.MappingFormat.TINY_2_FILE), + TINY_FILE(TinyMappingsWriter.INSTANCE, TinyMappingsReader.INSTANCE, FileType.TINY, net.fabricmc.mappingio.format.MappingFormat.TINY_FILE), + SRG_FILE(SrgMappingsWriter.INSTANCE, null, FileType.SRG, net.fabricmc.mappingio.format.MappingFormat.SRG_FILE), + XSRG_FILE(null, null, FileType.XSRG, net.fabricmc.mappingio.format.MappingFormat.XSRG_FILE), + JAM_FILE(null, null, FileType.JAM, net.fabricmc.mappingio.format.MappingFormat.JAM_FILE), + CSRG_FILE(null, null, FileType.CSRG, net.fabricmc.mappingio.format.MappingFormat.CSRG_FILE), + TSRG_FILE(null, null, FileType.TSRG, net.fabricmc.mappingio.format.MappingFormat.TSRG_FILE), + TSRG_2_FILE(null, null, FileType.TSRG, net.fabricmc.mappingio.format.MappingFormat.TSRG_2_FILE), + PROGUARD(null, ProguardMappingsReader.INSTANCE, FileType.TXT, net.fabricmc.mappingio.format.MappingFormat.PROGUARD_FILE), + RECAF(RecafMappingsWriter.INSTANCE, RecafMappingsReader.INSTANCE, FileType.TXT, net.fabricmc.mappingio.format.MappingFormat.RECAF_SIMPLE_FILE), + JOBF_FILE(null, null, FileType.JOBF, net.fabricmc.mappingio.format.MappingFormat.JOBF_FILE); private final MappingsWriter writer; private final MappingsReader reader; @@ -54,12 +56,12 @@ public enum MappingFormat { private final boolean hasMappingIoWriter; private boolean usedMappingIoWriterLast; - MappingFormat(MappingsWriter writer, MappingsReader reader, FileType fileType, net.fabricmc.mappingio.format.MappingFormat mappingIoCounterpart, boolean hasMappingIoWriter) { + MappingFormat(MappingsWriter writer, MappingsReader reader, FileType fileType, net.fabricmc.mappingio.format.MappingFormat mappingIoCounterpart) { this.writer = writer; this.reader = reader; this.fileType = fileType; this.mappingIoCounterpart = mappingIoCounterpart; - this.hasMappingIoWriter = hasMappingIoWriter; + this.hasMappingIoWriter = mappingIoCounterpart == null ? false : mappingIoCounterpart.hasWriter; } public void write(EntryTree mappings, Path path, ProgressListener progressListener, MappingSaveParameters saveParameters) { @@ -67,11 +69,7 @@ public enum MappingFormat { } public void write(EntryTree mappings, MappingDelta delta, Path path, ProgressListener progressListener, MappingSaveParameters saveParameters) { - if (!hasMappingIoWriter || !useMappingIo()) { - if (writer == null) { - throw new IllegalStateException(name() + " does not support writing"); - } - + if (!hasMappingIoWriter || (!useMappingIo() && writer != null)) { writer.write(mappings, usedMappingIoWriterLast ? MappingDelta.added(mappings) : delta, path, progressListener, saveParameters); usedMappingIoWriterLast = false; return; @@ -105,11 +103,7 @@ public enum MappingFormat { } public EntryTree read(Path path, ProgressListener progressListener, MappingSaveParameters saveParameters, JarIndex index) throws IOException, MappingParseException { - if (!useMappingIo()) { - if (reader == null) { - throw new IllegalStateException(name() + " does not support reading"); - } - + if (mappingIoCounterpart == null || (!useMappingIo() && reader != null)) { return reader.read(path, progressListener, saveParameters); } @@ -178,22 +172,18 @@ public enum MappingFormat { return writer != null || hasMappingIoWriter; } - @ApiStatus.Internal private boolean useMappingIo() { - if (mappingIoCounterpart == null) return false; return System.getProperty("enigma.use_mappingio", "true").equals("true"); } public static List getReadableFormats() { - return Arrays.asList(values()) - .stream() + return Arrays.stream(values()) .filter(MappingFormat::isReadable) .toList(); } public static List getWritableFormats() { - return Arrays.asList(values()) - .stream() + return Arrays.stream(values()) .filter(MappingFormat::isWritable) .toList(); } @@ -209,14 +199,16 @@ public enum MappingFormat { @ApiStatus.Internal public record FileType(List extensions) { public static final FileType DIRECTORY = new FileType(); + public static final FileType ZIP = new FileType(".zip"); public static final FileType MAPPING = new FileType(".mapping", ".mappings"); + public static final FileType TINY = new FileType(".tiny"); public static final FileType SRG = new FileType(".srg"); public static final FileType XSRG = new FileType(".xsrg"); + public static final FileType JAM = new FileType(".jam"); public static final FileType CSRG = new FileType(".csrg"); public static final FileType TSRG = new FileType(".tsrg"); - public static final FileType TINY = new FileType(".tiny"); public static final FileType TXT = new FileType(".txt"); - public static final FileType ZIP = new FileType(".zip"); + public static final FileType JOBF = new FileType(".jobf"); public FileType(String... extensions) { this(List.of(extensions)); -- cgit v1.2.3