From 6d51a2bd3315f292d5b80fadf27925bc4d7650ec Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Thu, 13 Mar 2025 14:27:14 +0200 Subject: [PATCH] Replace SrgNamedWriter with MIO --- .../mappings/MappingConfiguration.java | 11 ++++- .../loom/util/srg/SrgNamedWriter.java | 47 ------------------- 2 files changed, 9 insertions(+), 49 deletions(-) delete mode 100644 src/main/java/net/fabricmc/loom/util/srg/SrgNamedWriter.java diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingConfiguration.java index a78d6f0f..71061576 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingConfiguration.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingConfiguration.java @@ -73,8 +73,11 @@ import net.fabricmc.loom.util.service.ScopedServiceFactory; import net.fabricmc.loom.util.service.ServiceFactory; import net.fabricmc.loom.util.srg.ForgeMappingsMerger; import net.fabricmc.loom.util.srg.MCPReader; -import net.fabricmc.loom.util.srg.SrgNamedWriter; import net.fabricmc.mappingio.MappingReader; +import net.fabricmc.mappingio.MappingVisitor; +import net.fabricmc.mappingio.MappingWriter; +import net.fabricmc.mappingio.adapter.MappingDstNsReorder; +import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch; import net.fabricmc.mappingio.format.MappingFormat; import net.fabricmc.mappingio.format.tiny.Tiny2FileWriter; import net.fabricmc.stitch.Command; @@ -269,7 +272,11 @@ public class MappingConfiguration { if (Files.notExists(srgToNamedSrg) || extension.refreshDeps()) { try (var serviceFactory = new ScopedServiceFactory()) { TinyMappingsService mappingsService = getMappingsService(project, serviceFactory, MappingOption.WITH_SRG); - SrgNamedWriter.writeTo(project.getLogger(), srgToNamedSrg, mappingsService.getMappingTree(), "srg", "named"); + + try (MappingWriter writer = MappingWriter.create(srgToNamedSrg, MappingFormat.SRG_FILE)) { + MappingVisitor visitor = new MappingSourceNsSwitch(new MappingDstNsReorder(writer, "named"), "srg"); + mappingsService.getMappingTree().accept(visitor); + } } } } diff --git a/src/main/java/net/fabricmc/loom/util/srg/SrgNamedWriter.java b/src/main/java/net/fabricmc/loom/util/srg/SrgNamedWriter.java deleted file mode 100644 index 456b8b1b..00000000 --- a/src/main/java/net/fabricmc/loom/util/srg/SrgNamedWriter.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is part of fabric-loom, licensed under the MIT License (MIT). - * - * Copyright (c) 2021 FabricMC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.fabricmc.loom.util.srg; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -import org.cadixdev.lorenz.io.srg.SrgWriter; -import org.gradle.api.logging.Logger; - -import net.fabricmc.lorenztiny.TinyMappingsReader; -import net.fabricmc.mappingio.tree.MappingTree; - -public class SrgNamedWriter { - public static void writeTo(Logger logger, Path srgFile, MappingTree mappings, String from, String to) throws IOException { - Files.deleteIfExists(srgFile); - - try (SrgWriter writer = new SrgWriter(Files.newBufferedWriter(srgFile))) { - try (TinyMappingsReader reader = new TinyMappingsReader(mappings, from, to)) { - writer.write(reader.read()); - } - } - } -}