From 08e548b6c62815bf4b75593cb9a499951a4f564e Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Mon, 13 Sep 2021 17:58:52 +0100 Subject: [PATCH] Expose layered mappings as an API (#490) * Expose layered mappings as an API * Add FileSpec * Cleanup and support DependencyFileSpec --- .../loom/api/LoomGradleExtensionAPI.java | 2 +- .../mappings/layered}/MappingContext.java | 14 +++- .../mappings/layered}/MappingLayer.java | 13 ++- .../mappings/layered/MappingsNamespace.java | 56 +++++++++++++ .../api/mappings/layered/spec/FileSpec.java | 79 +++++++++++++++++++ .../spec/LayeredMappingSpecBuilder.java | 50 ++++++++++++ .../mappings/layered/spec}/MappingsSpec.java | 15 +++- .../spec/ParchmentMappingsSpecBuilder.java} | 20 +++-- .../AccessWidenerJarProcessor.java | 9 ++- .../loom/configuration/mods/ModProcessor.java | 7 +- .../mappings/GradleMappingContext.java | 18 +++-- .../mappings/LayeredMappingSpec.java | 2 + ...ava => LayeredMappingSpecBuilderImpl.java} | 31 +++++--- .../mappings/LayeredMappingsDependency.java | 6 +- .../mappings/LayeredMappingsProcessor.java | 10 ++- .../mappings/MappingsProviderImpl.java | 7 +- .../IntermediaryMappingLayer.java | 10 +-- .../IntermediaryMappingsSpec.java | 4 +- .../mappings/mojmap/MojangMappingLayer.java | 33 ++++---- .../mappings/mojmap/MojangMappingsSpec.java | 4 +- .../parchment/ParchmentMappingLayer.java | 12 +-- .../parchment/ParchmentMappingsSpec.java | 9 ++- ... => ParchmentMappingsSpecBuilderImpl.java} | 18 +++-- .../mappings/utils/DependencyFileSpec.java | 69 ++++++++++++++++ .../mappings/utils/LocalFileSpec.java | 63 +++++++++++++++ .../mappings/utils/MavenFileSpec.java | 37 +++++++++ .../minecraft/MinecraftMappedProvider.java | 7 +- .../extension/LoomGradleExtensionApiImpl.java | 5 +- .../extension/MinecraftGradleExtension.java | 2 +- .../loom/task/MigrateMappingsTask.java | 11 +-- .../net/fabricmc/loom/task/RemapJarTask.java | 5 +- .../loom/task/RemapSourcesJarTask.java | 5 +- .../fabricmc/loom/util/SourceRemapper.java | 3 +- .../LayeredMappingSpecBuilderTest.groovy | 15 ++-- .../LayeredMappingsSpecification.groovy | 27 ++++--- .../ParchmentMappingLayerTest.groovy | 5 +- 36 files changed, 552 insertions(+), 131 deletions(-) rename src/main/java/net/fabricmc/loom/{configuration/providers/mappings => api/mappings/layered}/MappingContext.java (77%) rename src/main/java/net/fabricmc/loom/{configuration/providers/mappings => api/mappings/layered}/MappingLayer.java (77%) create mode 100644 src/main/java/net/fabricmc/loom/api/mappings/layered/MappingsNamespace.java create mode 100644 src/main/java/net/fabricmc/loom/api/mappings/layered/spec/FileSpec.java create mode 100644 src/main/java/net/fabricmc/loom/api/mappings/layered/spec/LayeredMappingSpecBuilder.java rename src/main/java/net/fabricmc/loom/{configuration/providers/mappings => api/mappings/layered/spec}/MappingsSpec.java (73%) rename src/main/java/net/fabricmc/loom/{configuration/providers/mappings/MappingNamespace.java => api/mappings/layered/spec/ParchmentMappingsSpecBuilder.java} (76%) rename src/main/java/net/fabricmc/loom/configuration/providers/mappings/{LayeredMappingSpecBuilder.java => LayeredMappingSpecBuilderImpl.java} (72%) rename src/main/java/net/fabricmc/loom/configuration/providers/mappings/parchment/{ParchmentMappingsSpecBuilder.java => ParchmentMappingsSpecBuilderImpl.java} (72%) create mode 100644 src/main/java/net/fabricmc/loom/configuration/providers/mappings/utils/DependencyFileSpec.java create mode 100644 src/main/java/net/fabricmc/loom/configuration/providers/mappings/utils/LocalFileSpec.java create mode 100644 src/main/java/net/fabricmc/loom/configuration/providers/mappings/utils/MavenFileSpec.java diff --git a/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java b/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java index 0acb6da..1a84efc 100644 --- a/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java +++ b/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java @@ -38,9 +38,9 @@ import org.gradle.api.publish.maven.MavenPublication; import org.jetbrains.annotations.ApiStatus; import net.fabricmc.loom.api.decompilers.LoomDecompiler; +import net.fabricmc.loom.api.mappings.layered.spec.LayeredMappingSpecBuilder; import net.fabricmc.loom.configuration.ide.RunConfigSettings; import net.fabricmc.loom.configuration.processors.JarProcessor; -import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilder; import net.fabricmc.loom.util.DeprecationHelper; /** diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingContext.java b/src/main/java/net/fabricmc/loom/api/mappings/layered/MappingContext.java similarity index 77% rename from src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingContext.java rename to src/main/java/net/fabricmc/loom/api/mappings/layered/MappingContext.java index 3fbfb65..cbc7d3a 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingContext.java +++ b/src/main/java/net/fabricmc/loom/api/mappings/layered/MappingContext.java @@ -22,16 +22,22 @@ * SOFTWARE. */ -package net.fabricmc.loom.configuration.providers.mappings; +package net.fabricmc.loom.api.mappings.layered; -import java.io.File; +import java.nio.file.Path; +import org.gradle.api.artifacts.Dependency; import org.gradle.api.logging.Logger; +import org.jetbrains.annotations.ApiStatus; import net.fabricmc.loom.configuration.providers.MinecraftProvider; +import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider; +@ApiStatus.Experimental /* Very Experimental and not cleanly separated from the impl atm */ public interface MappingContext { - File mavenFile(String mavenNotation); + Path resolveDependency(Dependency dependency); + + Path resolveMavenDependency(String mavenNotation); MappingsProvider mappingsProvider(); @@ -44,7 +50,7 @@ public interface MappingContext { /** * Creates a temporary working dir to be used to store working files. */ - File workingDirectory(String name); + Path workingDirectory(String name); Logger getLogger(); } diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingLayer.java b/src/main/java/net/fabricmc/loom/api/mappings/layered/MappingLayer.java similarity index 77% rename from src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingLayer.java rename to src/main/java/net/fabricmc/loom/api/mappings/layered/MappingLayer.java index f371789..1f28d65 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingLayer.java +++ b/src/main/java/net/fabricmc/loom/api/mappings/layered/MappingLayer.java @@ -22,21 +22,28 @@ * SOFTWARE. */ -package net.fabricmc.loom.configuration.providers.mappings; +package net.fabricmc.loom.api.mappings.layered; import java.io.IOException; import java.util.Collections; import java.util.List; +import org.jetbrains.annotations.ApiStatus; + import net.fabricmc.mappingio.MappingVisitor; +@ApiStatus.Experimental public interface MappingLayer { void visit(MappingVisitor mappingVisitor) throws IOException; - default MappingNamespace getSourceNamespace() { - return MappingNamespace.NAMED; + default MappingsNamespace getSourceNamespace() { + return MappingsNamespace.NAMED; } + /** + * Provides a list of layer classes that this mapping layer depends on. If such a layer is not present an Exception will be thrown when trying to resolve the layer. + * @return A list of MappingLayer classes to depend on. + */ default List> dependsOn() { return Collections.emptyList(); } diff --git a/src/main/java/net/fabricmc/loom/api/mappings/layered/MappingsNamespace.java b/src/main/java/net/fabricmc/loom/api/mappings/layered/MappingsNamespace.java new file mode 100644 index 0000000..ae32f7f --- /dev/null +++ b/src/main/java/net/fabricmc/loom/api/mappings/layered/MappingsNamespace.java @@ -0,0 +1,56 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2016-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.api.mappings.layered; + +import java.util.Locale; + +/** + * The standard namespaces used by loom. + */ +public enum MappingsNamespace { + /** + * Official mappings are the names that are used in the vanilla Minecraft game jars, these are usually obfuscated. + */ + OFFICIAL, + + /** + * Intermediary mappings have been generated to provide a stable set of names across minecraft versions. + * + *

Intermediary is used in a production runtime (outside a dev env) allowing mods to run across multiple versions of the game. Mods are remapped from "named" at build time. + * + * @see github.com/FabricMC/intermediary/ + */ + INTERMEDIARY, + + /** + * Named mappings are the developer friendly names used to develop mods against. + */ + NAMED; + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } +} diff --git a/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/FileSpec.java b/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/FileSpec.java new file mode 100644 index 0000000..19129e5 --- /dev/null +++ b/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/FileSpec.java @@ -0,0 +1,79 @@ +/* + * 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.api.mappings.layered.spec; + +import java.io.File; +import java.nio.file.Path; +import java.util.Objects; + +import org.gradle.api.artifacts.Dependency; +import org.gradle.api.file.RegularFileProperty; +import org.jetbrains.annotations.ApiStatus; + +import net.fabricmc.loom.api.mappings.layered.MappingContext; +import net.fabricmc.loom.configuration.providers.mappings.utils.DependencyFileSpec; +import net.fabricmc.loom.configuration.providers.mappings.utils.LocalFileSpec; +import net.fabricmc.loom.configuration.providers.mappings.utils.MavenFileSpec; + +/** + * FileSpec should be used in MappingsSpec's that take an input file. The input file can either be a local file or a gradle dep. + */ +@ApiStatus.Experimental +public interface FileSpec { + static FileSpec create(Object o) { + Objects.requireNonNull(o, "Object cannot be null"); + + if (o instanceof String s) { + return createFromMavenDependency(s); + } else if (o instanceof Dependency d) { + return createFromDependency(d); + } else if (o instanceof File f) { + return createFromFile(f); + } else if (o instanceof RegularFileProperty rfp) { + return createFromFile(rfp); + } + + throw new UnsupportedOperationException("Cannot create FileSpec from object of type:" + o.getClass().getCanonicalName()); + } + + static FileSpec createFromMavenDependency(String dependencyNotation) { + return new MavenFileSpec(dependencyNotation); + } + + static FileSpec createFromDependency(Dependency dependency) { + return new DependencyFileSpec(dependency); + } + + static FileSpec createFromFile(File file) { + return new LocalFileSpec(file); + } + + // Note resolved instantly, this is not lazy + static FileSpec createFromFile(RegularFileProperty regularFileProperty) { + return createFromFile(regularFileProperty.getAsFile().get()); + } + + Path get(MappingContext context); +} diff --git a/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/LayeredMappingSpecBuilder.java b/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/LayeredMappingSpecBuilder.java new file mode 100644 index 0000000..0518017 --- /dev/null +++ b/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/LayeredMappingSpecBuilder.java @@ -0,0 +1,50 @@ +/* + * 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.api.mappings.layered.spec; + +import org.gradle.api.Action; +import org.jetbrains.annotations.ApiStatus; + +/** + * Used to configure a layered mapping spec. + */ +@ApiStatus.Experimental +public interface LayeredMappingSpecBuilder { + /** + * Add a MappingsSpec layer. + */ + LayeredMappingSpecBuilder addLayer(MappingsSpec mappingSpec); + + /** + * Add a layer that uses the official mappings provided by Mojang. + */ + LayeredMappingSpecBuilder officialMojangMappings(); + + default LayeredMappingSpecBuilder parchment(Object object) { + return parchment(object, parchmentMappingsSpecBuilder -> parchmentMappingsSpecBuilder.setRemovePrefix(true)); + } + + LayeredMappingSpecBuilder parchment(Object object, Action action); +} diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingsSpec.java b/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/MappingsSpec.java similarity index 73% rename from src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingsSpec.java rename to src/main/java/net/fabricmc/loom/api/mappings/layered/spec/MappingsSpec.java index 8b6adce..8511614 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingsSpec.java +++ b/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/MappingsSpec.java @@ -22,8 +22,21 @@ * SOFTWARE. */ -package net.fabricmc.loom.configuration.providers.mappings; +package net.fabricmc.loom.api.mappings.layered.spec; +import org.jetbrains.annotations.ApiStatus; + +import net.fabricmc.loom.api.mappings.layered.MappingContext; +import net.fabricmc.loom.api.mappings.layered.MappingLayer; + +/** + * A MappingsSpec is an immutable set of data used to create the MappingLayer. + * + *

The hashCode is used to generate a hash of the full layered mapping spec, used to cache. + * + *

Commonly implemented as a record + */ +@ApiStatus.Experimental public interface MappingsSpec { L createLayer(MappingContext context); } diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingNamespace.java b/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/ParchmentMappingsSpecBuilder.java similarity index 76% rename from src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingNamespace.java rename to src/main/java/net/fabricmc/loom/api/mappings/layered/spec/ParchmentMappingsSpecBuilder.java index 991cdc7..ee3e07a 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingNamespace.java +++ b/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/ParchmentMappingsSpecBuilder.java @@ -1,7 +1,7 @@ /* * This file is part of fabric-loom, licensed under the MIT License (MIT). * - * Copyright (c) 2016-2021 FabricMC + * 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 @@ -22,16 +22,14 @@ * SOFTWARE. */ -package net.fabricmc.loom.configuration.providers.mappings; +package net.fabricmc.loom.api.mappings.layered.spec; -import java.util.Locale; +import org.jetbrains.annotations.ApiStatus; -public enum MappingNamespace { - OFFICIAL, - INTERMEDIARY, - NAMED; - - public String stringValue() { - return name().toLowerCase(Locale.ROOT); - } +@ApiStatus.Experimental +public interface ParchmentMappingsSpecBuilder { + /** + * When enabled the "p" prefix will be stripped from parameter names. + */ + ParchmentMappingsSpecBuilder setRemovePrefix(boolean removePrefix); } diff --git a/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerJarProcessor.java b/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerJarProcessor.java index bca3f35..6ac63ac 100644 --- a/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerJarProcessor.java +++ b/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerJarProcessor.java @@ -54,6 +54,7 @@ import net.fabricmc.accesswidener.AccessWidenerRemapper; import net.fabricmc.accesswidener.AccessWidenerVisitor; import net.fabricmc.accesswidener.AccessWidenerWriter; import net.fabricmc.loom.LoomGradleExtension; +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.loom.configuration.processors.JarProcessor; import net.fabricmc.loom.util.Checksum; import net.fabricmc.loom.util.Constants; @@ -92,7 +93,7 @@ public class AccessWidenerJarProcessor implements JarProcessor { } //Remap accessWidener if its not named, allows for AE's to be written in intermediary - if (!accessWidener.getNamespace().equals("named")) { + if (!accessWidener.getNamespace().equals(MappingsNamespace.NAMED.toString())) { try { List validNamespaces = loomGradleExtension.getMappingsProvider().getMappings().getMetadata().getNamespaces(); @@ -100,10 +101,10 @@ public class AccessWidenerJarProcessor implements JarProcessor { throw new UnsupportedOperationException(String.format("Access Widener namespace '%s' is not a valid namespace, it must be one of: '%s'", accessWidener.getNamespace(), String.join(", ", validNamespaces))); } - TinyRemapper tinyRemapper = loomGradleExtension.getMinecraftMappedProvider().getTinyRemapper("official", "named"); + TinyRemapper tinyRemapper = loomGradleExtension.getMinecraftMappedProvider().getTinyRemapper(MappingsNamespace.OFFICIAL.toString(), MappingsNamespace.NAMED.toString()); tinyRemapper.readClassPath(loomGradleExtension.getMinecraftMappedProvider().getRemapClasspath()); - AccessWidenerRemapper remapper = new AccessWidenerRemapper(accessWidener, tinyRemapper.getRemapper(), "named"); + AccessWidenerRemapper remapper = new AccessWidenerRemapper(accessWidener, tinyRemapper.getRemapper(), MappingsNamespace.NAMED.toString()); accessWidener = remapper.remap(); tinyRemapper.finish(); @@ -160,7 +161,7 @@ public class AccessWidenerJarProcessor implements JarProcessor { } public byte[] getRemappedAccessWidener(Remapper asmRemapper) throws IOException { - AccessWidenerRemapper remapper = new AccessWidenerRemapper(accessWidener, asmRemapper, "intermediary"); + AccessWidenerRemapper remapper = new AccessWidenerRemapper(accessWidener, asmRemapper, MappingsNamespace.INTERMEDIARY.toString()); AccessWidener remapped = remapper.remap(); AccessWidenerWriter accessWidenerWriter = new AccessWidenerWriter(remapped); diff --git a/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java b/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java index 808c857..7cdc667 100644 --- a/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java +++ b/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java @@ -54,6 +54,7 @@ import net.fabricmc.accesswidener.AccessWidenerRemapper; import net.fabricmc.accesswidener.AccessWidenerWriter; import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradlePlugin; +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.loom.configuration.RemappedConfigurationEntry; import net.fabricmc.loom.configuration.processors.dependency.ModDependencyInfo; import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl; @@ -113,7 +114,7 @@ public class ModProcessor { AccessWidenerReader accessWidenerReader = new AccessWidenerReader(accessWidener); accessWidenerReader.read(bufferedReader); - AccessWidenerRemapper accessWidenerRemapper = new AccessWidenerRemapper(accessWidener, remapper, "named"); + AccessWidenerRemapper accessWidenerRemapper = new AccessWidenerRemapper(accessWidener, remapper, MappingsNamespace.NAMED.toString()); AccessWidener remapped = accessWidenerRemapper.remap(); AccessWidenerWriter accessWidenerWriter = new AccessWidenerWriter(remapped); @@ -128,8 +129,8 @@ public class ModProcessor { private static void remapJars(Project project, List processList) throws IOException { LoomGradleExtension extension = LoomGradleExtension.get(project); - String fromM = "intermediary"; - String toM = "named"; + String fromM = MappingsNamespace.INTERMEDIARY.toString(); + String toM = MappingsNamespace.NAMED.toString(); MinecraftMappedProvider mappedProvider = extension.getMinecraftMappedProvider(); MappingsProviderImpl mappingsProvider = extension.getMappingsProvider(); diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/GradleMappingContext.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/GradleMappingContext.java index e62e9e9..0d780f1 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/GradleMappingContext.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/GradleMappingContext.java @@ -25,12 +25,15 @@ package net.fabricmc.loom.configuration.providers.mappings; import java.io.File; +import java.nio.file.Path; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.Dependency; import org.gradle.api.logging.Logger; import net.fabricmc.loom.LoomGradleExtension; +import net.fabricmc.loom.api.mappings.layered.MappingContext; import net.fabricmc.loom.configuration.providers.MinecraftProvider; public class GradleMappingContext implements MappingContext { @@ -45,9 +48,14 @@ public class GradleMappingContext implements MappingContext { } @Override - public File mavenFile(String mavenNotation) { - Configuration configuration = project.getConfigurations().detachedConfiguration(project.getDependencies().create(mavenNotation)); - return configuration.getSingleFile(); + public Path resolveDependency(Dependency dependency) { + Configuration configuration = project.getConfigurations().detachedConfiguration(dependency); + return configuration.getSingleFile().toPath(); + } + + @Override + public Path resolveMavenDependency(String mavenNotation) { + return resolveDependency(project.getDependencies().create(mavenNotation)); } @Override @@ -61,8 +69,8 @@ public class GradleMappingContext implements MappingContext { } @Override - public File workingDirectory(String name) { - return new File(minecraftProvider().dir("layered/working_dir/" + workingDirName), name); + public Path workingDirectory(String name) { + return new File(minecraftProvider().dir("layered/working_dir/" + workingDirName), name).toPath(); } @Override diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpec.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpec.java index 2e47af3..cb09d71 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpec.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpec.java @@ -26,6 +26,8 @@ package net.fabricmc.loom.configuration.providers.mappings; import java.util.List; +import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec; + public record LayeredMappingSpec(List> layers) { public String getVersion() { // TODO something better? diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpecBuilder.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpecBuilderImpl.java similarity index 72% rename from src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpecBuilder.java rename to src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpecBuilderImpl.java index f61b882..4f47cfb 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpecBuilder.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpecBuilderImpl.java @@ -30,28 +30,33 @@ import java.util.List; import org.gradle.api.Action; +import net.fabricmc.loom.api.mappings.layered.spec.FileSpec; +import net.fabricmc.loom.api.mappings.layered.spec.LayeredMappingSpecBuilder; +import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec; +import net.fabricmc.loom.api.mappings.layered.spec.ParchmentMappingsSpecBuilder; import net.fabricmc.loom.configuration.providers.mappings.intermediary.IntermediaryMappingsSpec; import net.fabricmc.loom.configuration.providers.mappings.mojmap.MojangMappingsSpec; -import net.fabricmc.loom.configuration.providers.mappings.parchment.ParchmentMappingsSpecBuilder; +import net.fabricmc.loom.configuration.providers.mappings.parchment.ParchmentMappingsSpecBuilderImpl; -public class LayeredMappingSpecBuilder { +public class LayeredMappingSpecBuilderImpl implements LayeredMappingSpecBuilder { private final List> layers = new LinkedList<>(); + @Override + public LayeredMappingSpecBuilder addLayer(MappingsSpec mappingSpec) { + layers.add(mappingSpec); + return this; + } + + @Override public LayeredMappingSpecBuilder officialMojangMappings() { - layers.add(new MojangMappingsSpec()); - return this; + return addLayer(new MojangMappingsSpec()); } - public LayeredMappingSpecBuilder parchment(String mavenNotation) { - parchment(mavenNotation, parchmentMappingsSpecBuilder -> parchmentMappingsSpecBuilder.setRemovePrefix(true)); - return this; - } - - public LayeredMappingSpecBuilder parchment(String mavenNotation, Action action) { - ParchmentMappingsSpecBuilder builder = ParchmentMappingsSpecBuilder.builder(mavenNotation); + @Override + public LayeredMappingSpecBuilder parchment(Object object, Action action) { + ParchmentMappingsSpecBuilderImpl builder = ParchmentMappingsSpecBuilderImpl.builder(FileSpec.create(object)); action.execute(builder); - layers.add(builder.build()); - return this; + return addLayer(builder.build()); } public LayeredMappingSpec build() { diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingsDependency.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingsDependency.java index 878a37e..e15f623 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingsDependency.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingsDependency.java @@ -43,6 +43,8 @@ import org.zeroturnaround.zip.ZipEntrySource; import org.zeroturnaround.zip.ZipUtil; import net.fabricmc.loom.LoomGradlePlugin; +import net.fabricmc.loom.api.mappings.layered.MappingContext; +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.mappingio.adapter.MappingDstNsReorder; import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch; import net.fabricmc.mappingio.format.Tiny2Writer; @@ -75,8 +77,8 @@ public class LayeredMappingsDependency implements SelfResolvingDependency { try (Writer writer = new StringWriter()) { Tiny2Writer tiny2Writer = new Tiny2Writer(writer, false); - MappingDstNsReorder nsReorder = new MappingDstNsReorder(tiny2Writer, Collections.singletonList(MappingNamespace.NAMED.stringValue())); - MappingSourceNsSwitch nsSwitch = new MappingSourceNsSwitch(nsReorder, MappingNamespace.INTERMEDIARY.stringValue(), true); + MappingDstNsReorder nsReorder = new MappingDstNsReorder(tiny2Writer, Collections.singletonList(MappingsNamespace.NAMED.toString())); + MappingSourceNsSwitch nsSwitch = new MappingSourceNsSwitch(nsReorder, MappingsNamespace.INTERMEDIARY.toString(), true); mappings.accept(nsSwitch); Files.deleteIfExists(mappingsFile); diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingsProcessor.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingsProcessor.java index a3fa529..b14902c 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingsProcessor.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingsProcessor.java @@ -28,6 +28,10 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import net.fabricmc.loom.api.mappings.layered.MappingContext; +import net.fabricmc.loom.api.mappings.layered.MappingLayer; +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; +import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec; import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch; import net.fabricmc.mappingio.tree.MemoryMappingTree; @@ -55,7 +59,7 @@ public class LayeredMappingsProcessor { visitedLayers.add(layer.getClass()); // We have to rebuild a new tree to work on when a layer doesnt merge into layered - boolean rebuild = layer.getSourceNamespace() != MappingNamespace.NAMED; + boolean rebuild = layer.getSourceNamespace() != MappingsNamespace.NAMED; MemoryMappingTree workingTree; if (rebuild) { @@ -63,7 +67,7 @@ public class LayeredMappingsProcessor { // This can be null on the first layer if (mappingTree.getSrcNamespace() != null) { - var sourceNsSwitch = new MappingSourceNsSwitch(tempTree, layer.getSourceNamespace().stringValue()); + var sourceNsSwitch = new MappingSourceNsSwitch(tempTree, layer.getSourceNamespace().toString()); mappingTree.accept(sourceNsSwitch); } @@ -80,7 +84,7 @@ public class LayeredMappingsProcessor { if (rebuild) { mappingTree = new MemoryMappingTree(); - workingTree.accept(new MappingSourceNsSwitch(mappingTree, MappingNamespace.NAMED.stringValue())); + workingTree.accept(new MappingSourceNsSwitch(mappingTree, MappingsNamespace.NAMED.toString())); } } diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingsProviderImpl.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingsProviderImpl.java index 4554b8d..0456ada 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingsProviderImpl.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingsProviderImpl.java @@ -48,6 +48,7 @@ import org.zeroturnaround.zip.ZipUtil; import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradlePlugin; +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.loom.configuration.DependencyProvider; import net.fabricmc.loom.configuration.accesswidener.AccessWidenerJarProcessor; import net.fabricmc.loom.configuration.processors.JarProcessorManager; @@ -276,7 +277,7 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings project.getLogger().info(":merging mappings"); MemoryMappingTree tree = new MemoryMappingTree(); - MappingSourceNsSwitch sourceNsSwitch = new MappingSourceNsSwitch(tree, MappingNamespace.OFFICIAL.stringValue()); + MappingSourceNsSwitch sourceNsSwitch = new MappingSourceNsSwitch(tree, MappingsNamespace.OFFICIAL.toString()); readIntermediaryTree().accept(sourceNsSwitch); try (BufferedReader reader = Files.newBufferedReader(from, StandardCharsets.UTF_8)) { @@ -292,7 +293,7 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings private MemoryMappingTree readIntermediaryTree() throws IOException { MemoryMappingTree tree = new MemoryMappingTree(); - MappingNsCompleter nsCompleter = new MappingNsCompleter(tree, Collections.singletonMap(MappingNamespace.NAMED.stringValue(), MappingNamespace.INTERMEDIARY.stringValue()), true); + MappingNsCompleter nsCompleter = new MappingNsCompleter(tree, Collections.singletonMap(MappingsNamespace.NAMED.toString(), MappingsNamespace.INTERMEDIARY.toString()), true); try (BufferedReader reader = Files.newBufferedReader(getIntermediaryTiny(), StandardCharsets.UTF_8)) { Tiny2Reader.read(reader, nsCompleter); @@ -316,7 +317,7 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings runCommand(command, intermediaryMappings.toAbsolutePath().toString(), yarnMappings.toAbsolutePath().toString(), newMergedMappings.toAbsolutePath().toString(), - "intermediary", "official"); + MappingsNamespace.INTERMEDIARY.toString(), MappingsNamespace.OFFICIAL.toString()); } catch (Exception e) { throw new RuntimeException("Could not merge mappings from " + intermediaryMappings.toString() + " with mappings from " + yarnMappings, e); diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/intermediary/IntermediaryMappingLayer.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/intermediary/IntermediaryMappingLayer.java index 0ca6414..a6c06ba 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/intermediary/IntermediaryMappingLayer.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/intermediary/IntermediaryMappingLayer.java @@ -31,22 +31,22 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Collections; -import net.fabricmc.loom.configuration.providers.mappings.MappingLayer; -import net.fabricmc.loom.configuration.providers.mappings.MappingNamespace; +import net.fabricmc.loom.api.mappings.layered.MappingLayer; +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.mappingio.MappingVisitor; import net.fabricmc.mappingio.adapter.MappingNsCompleter; import net.fabricmc.mappingio.format.Tiny2Reader; public record IntermediaryMappingLayer(File tinyFile) implements MappingLayer { @Override - public MappingNamespace getSourceNamespace() { - return MappingNamespace.OFFICIAL; + public MappingsNamespace getSourceNamespace() { + return MappingsNamespace.OFFICIAL; } @Override public void visit(MappingVisitor mappingVisitor) throws IOException { // Populate named with intermediary and add Add a "named" namespace - MappingNsCompleter nsCompleter = new MappingNsCompleter(mappingVisitor, Collections.singletonMap(MappingNamespace.NAMED.stringValue(), MappingNamespace.INTERMEDIARY.stringValue()), true); + MappingNsCompleter nsCompleter = new MappingNsCompleter(mappingVisitor, Collections.singletonMap(MappingsNamespace.NAMED.toString(), MappingsNamespace.INTERMEDIARY.toString()), true); try (BufferedReader reader = Files.newBufferedReader(tinyFile().toPath(), StandardCharsets.UTF_8)) { Tiny2Reader.read(reader, nsCompleter); diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/intermediary/IntermediaryMappingsSpec.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/intermediary/IntermediaryMappingsSpec.java index 866ad9d..194b303 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/intermediary/IntermediaryMappingsSpec.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/intermediary/IntermediaryMappingsSpec.java @@ -24,8 +24,8 @@ package net.fabricmc.loom.configuration.providers.mappings.intermediary; -import net.fabricmc.loom.configuration.providers.mappings.MappingContext; -import net.fabricmc.loom.configuration.providers.mappings.MappingsSpec; +import net.fabricmc.loom.api.mappings.layered.MappingContext; +import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec; public record IntermediaryMappingsSpec() implements MappingsSpec { @Override diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/mojmap/MojangMappingLayer.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/mojmap/MojangMappingLayer.java index 03d0c01..dacfbaf 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/mojmap/MojangMappingLayer.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/mojmap/MojangMappingLayer.java @@ -25,7 +25,6 @@ package net.fabricmc.loom.configuration.providers.mappings.mojmap; import java.io.BufferedReader; -import java.io.File; import java.io.IOException; import java.net.URL; import java.nio.charset.StandardCharsets; @@ -35,8 +34,8 @@ import java.util.List; import org.gradle.api.logging.Logger; -import net.fabricmc.loom.configuration.providers.mappings.MappingLayer; -import net.fabricmc.loom.configuration.providers.mappings.MappingNamespace; +import net.fabricmc.loom.api.mappings.layered.MappingLayer; +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.loom.configuration.providers.minecraft.MinecraftVersionMeta; import net.fabricmc.loom.configuration.providers.mappings.intermediary.IntermediaryMappingLayer; import net.fabricmc.loom.util.HashedDownloadUtil; @@ -46,30 +45,30 @@ import net.fabricmc.mappingio.format.ProGuardReader; public record MojangMappingLayer(MinecraftVersionMeta.Download clientDownload, MinecraftVersionMeta.Download serverDownload, - File workingDir, + Path workingDir, Logger logger) implements MappingLayer { @Override public void visit(MappingVisitor mappingVisitor) throws IOException { - var clientMappings = new File(workingDir(), "client.txt"); - var serverMappings = new File(workingDir(), "server.txt"); + Path clientMappings = workingDir().resolve("client.txt"); + Path serverMappings = workingDir().resolve("server.txt"); download(clientMappings, serverMappings); - printMappingsLicense(clientMappings.toPath()); + printMappingsLicense(clientMappings); // Make official the source namespace - MappingSourceNsSwitch nsSwitch = new MappingSourceNsSwitch(mappingVisitor, MappingNamespace.OFFICIAL.stringValue()); + MappingSourceNsSwitch nsSwitch = new MappingSourceNsSwitch(mappingVisitor, MappingsNamespace.OFFICIAL.toString()); - try (BufferedReader clientBufferedReader = Files.newBufferedReader(clientMappings.toPath(), StandardCharsets.UTF_8); - BufferedReader serverBufferedReader = Files.newBufferedReader(serverMappings.toPath(), StandardCharsets.UTF_8)) { - ProGuardReader.read(clientBufferedReader, MappingNamespace.NAMED.stringValue(), MappingNamespace.OFFICIAL.stringValue(), nsSwitch); - ProGuardReader.read(serverBufferedReader, MappingNamespace.NAMED.stringValue(), MappingNamespace.OFFICIAL.stringValue(), nsSwitch); + try (BufferedReader clientBufferedReader = Files.newBufferedReader(clientMappings, StandardCharsets.UTF_8); + BufferedReader serverBufferedReader = Files.newBufferedReader(serverMappings, StandardCharsets.UTF_8)) { + ProGuardReader.read(clientBufferedReader, MappingsNamespace.NAMED.toString(), MappingsNamespace.OFFICIAL.toString(), nsSwitch); + ProGuardReader.read(serverBufferedReader, MappingsNamespace.NAMED.toString(), MappingsNamespace.OFFICIAL.toString(), nsSwitch); } } - private void download(File clientMappings, File serverMappings) throws IOException { - HashedDownloadUtil.downloadIfInvalid(new URL(clientDownload().url()), clientMappings, clientDownload().sha1(), logger(), false); - HashedDownloadUtil.downloadIfInvalid(new URL(serverDownload().url()), serverMappings, serverDownload().sha1(), logger(), false); + private void download(Path clientMappings, Path serverMappings) throws IOException { + HashedDownloadUtil.downloadIfInvalid(new URL(clientDownload().url()), clientMappings.toFile(), clientDownload().sha1(), logger(), false); + HashedDownloadUtil.downloadIfInvalid(new URL(serverDownload().url()), serverMappings.toFile(), serverDownload().sha1(), logger(), false); } private void printMappingsLicense(Path clientMappings) { @@ -91,8 +90,8 @@ public record MojangMappingLayer(MinecraftVersionMeta.Download clientDownload, } @Override - public MappingNamespace getSourceNamespace() { - return MappingNamespace.OFFICIAL; + public MappingsNamespace getSourceNamespace() { + return MappingsNamespace.OFFICIAL; } @Override diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/mojmap/MojangMappingsSpec.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/mojmap/MojangMappingsSpec.java index 61bec47..59d14f4 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/mojmap/MojangMappingsSpec.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/mojmap/MojangMappingsSpec.java @@ -24,8 +24,8 @@ package net.fabricmc.loom.configuration.providers.mappings.mojmap; -import net.fabricmc.loom.configuration.providers.mappings.MappingContext; -import net.fabricmc.loom.configuration.providers.mappings.MappingsSpec; +import net.fabricmc.loom.api.mappings.layered.MappingContext; +import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec; import net.fabricmc.loom.configuration.providers.minecraft.MinecraftVersionMeta; public record MojangMappingsSpec() implements MappingsSpec { diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/parchment/ParchmentMappingLayer.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/parchment/ParchmentMappingLayer.java index 448a33a..f6b602e 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/parchment/ParchmentMappingLayer.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/parchment/ParchmentMappingLayer.java @@ -24,19 +24,19 @@ package net.fabricmc.loom.configuration.providers.mappings.parchment; -import java.io.File; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.file.Path; import java.util.Objects; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import net.fabricmc.loom.LoomGradlePlugin; -import net.fabricmc.loom.configuration.providers.mappings.MappingLayer; -import net.fabricmc.loom.configuration.providers.mappings.MappingNamespace; +import net.fabricmc.loom.api.mappings.layered.MappingLayer; +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.mappingio.MappingVisitor; -public record ParchmentMappingLayer(File parchmentFile, boolean removePrefix) implements MappingLayer { +public record ParchmentMappingLayer(Path parchmentFile, boolean removePrefix) implements MappingLayer { private static final String PARCHMENT_DATA_FILE_NAME = "parchment.json"; @Override @@ -47,11 +47,11 @@ public record ParchmentMappingLayer(File parchmentFile, boolean removePrefix) im mappingVisitor = new ParchmentPrefixStripingMappingVisitor(mappingVisitor); } - parchmentData.visit(mappingVisitor, MappingNamespace.NAMED.stringValue()); + parchmentData.visit(mappingVisitor, MappingsNamespace.NAMED.toString()); } private ParchmentTreeV1 getParchmentData() throws IOException { - try (var zipFile = new ZipFile(parchmentFile())) { + try (var zipFile = new ZipFile(parchmentFile().toFile())) { ZipEntry zipFileEntry = zipFile.getEntry(PARCHMENT_DATA_FILE_NAME); Objects.requireNonNull(zipFileEntry, "Could not find %s in parchment data file".formatted(PARCHMENT_DATA_FILE_NAME)); diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/parchment/ParchmentMappingsSpec.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/parchment/ParchmentMappingsSpec.java index 2b3f48b..5af9503 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/parchment/ParchmentMappingsSpec.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/parchment/ParchmentMappingsSpec.java @@ -24,12 +24,13 @@ package net.fabricmc.loom.configuration.providers.mappings.parchment; -import net.fabricmc.loom.configuration.providers.mappings.MappingContext; -import net.fabricmc.loom.configuration.providers.mappings.MappingsSpec; +import net.fabricmc.loom.api.mappings.layered.spec.FileSpec; +import net.fabricmc.loom.api.mappings.layered.MappingContext; +import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec; -public record ParchmentMappingsSpec(String mavenNotation, boolean removePrefix) implements MappingsSpec { +public record ParchmentMappingsSpec(FileSpec fileSpec, boolean removePrefix) implements MappingsSpec { @Override public ParchmentMappingLayer createLayer(MappingContext context) { - return new ParchmentMappingLayer(context.mavenFile(mavenNotation()), removePrefix()); + return new ParchmentMappingLayer(fileSpec.get(context), removePrefix()); } } diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/parchment/ParchmentMappingsSpecBuilder.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/parchment/ParchmentMappingsSpecBuilderImpl.java similarity index 72% rename from src/main/java/net/fabricmc/loom/configuration/providers/mappings/parchment/ParchmentMappingsSpecBuilder.java rename to src/main/java/net/fabricmc/loom/configuration/providers/mappings/parchment/ParchmentMappingsSpecBuilderImpl.java index 1fff319..4830cad 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/parchment/ParchmentMappingsSpecBuilder.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/parchment/ParchmentMappingsSpecBuilderImpl.java @@ -24,25 +24,29 @@ package net.fabricmc.loom.configuration.providers.mappings.parchment; -public class ParchmentMappingsSpecBuilder { - private final String mavenNotation; +import net.fabricmc.loom.api.mappings.layered.spec.FileSpec; +import net.fabricmc.loom.api.mappings.layered.spec.ParchmentMappingsSpecBuilder; + +public class ParchmentMappingsSpecBuilderImpl implements ParchmentMappingsSpecBuilder { + private final FileSpec fileSpec; private boolean removePrefix; - private ParchmentMappingsSpecBuilder(String mavenNotation) { - this.mavenNotation = mavenNotation; + private ParchmentMappingsSpecBuilderImpl(FileSpec fileSpec) { + this.fileSpec = fileSpec; } - public static ParchmentMappingsSpecBuilder builder(String depNotation) { - return new ParchmentMappingsSpecBuilder(depNotation); + public static ParchmentMappingsSpecBuilderImpl builder(FileSpec fileSpec) { + return new ParchmentMappingsSpecBuilderImpl(fileSpec); } + @Override public ParchmentMappingsSpecBuilder setRemovePrefix(boolean removePrefix) { this.removePrefix = removePrefix; return this; } public ParchmentMappingsSpec build() { - return new ParchmentMappingsSpec(mavenNotation, removePrefix); + return new ParchmentMappingsSpec(fileSpec, removePrefix); } } diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/utils/DependencyFileSpec.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/utils/DependencyFileSpec.java new file mode 100644 index 0000000..99c9d7d --- /dev/null +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/utils/DependencyFileSpec.java @@ -0,0 +1,69 @@ +/* + * 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.configuration.providers.mappings.utils; + +import java.io.File; +import java.nio.file.Path; +import java.util.Objects; +import java.util.Set; + +import org.gradle.api.artifacts.Dependency; +import org.gradle.api.artifacts.SelfResolvingDependency; + +import net.fabricmc.loom.api.mappings.layered.MappingContext; +import net.fabricmc.loom.api.mappings.layered.spec.FileSpec; + +public record DependencyFileSpec(Dependency dependency) implements FileSpec { + @Override + public Path get(MappingContext context) { + if (dependency instanceof SelfResolvingDependency selfResolvingDependency) { + Set files = selfResolvingDependency.resolve(); + + if (files.size() == 0) { + throw new RuntimeException("SelfResolvingDependency (%s) resolved no files".formatted(selfResolvingDependency.toString())); + } else if (files.size() > 1) { + throw new RuntimeException("SelfResolvingDependency (%s) resolved too many files (%d) only 1 is expected".formatted(selfResolvingDependency.toString(), files.size())); + } + + return files.iterator().next().toPath(); + } + + return context.resolveDependency(dependency); + } + + @Override + public int hashCode() { + return Objects.hash(dependency.getGroup(), dependency.getName(), dependency.getVersion()); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof DependencyFileSpec other) { + return other.dependency().contentEquals(this.dependency()); + } + + return false; + } +} diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/utils/LocalFileSpec.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/utils/LocalFileSpec.java new file mode 100644 index 0000000..d870d69 --- /dev/null +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/utils/LocalFileSpec.java @@ -0,0 +1,63 @@ +/* + * 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.configuration.providers.mappings.utils; + +import java.io.File; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.Objects; + +import net.fabricmc.loom.api.mappings.layered.spec.FileSpec; +import net.fabricmc.loom.api.mappings.layered.MappingContext; +import net.fabricmc.loom.util.Checksum; + +public class LocalFileSpec implements FileSpec { + private final File file; + private final int hash; + + public LocalFileSpec(File file) { + this.file = file; + this.hash = calculateHashCode(); + } + + private int calculateHashCode() { + if (!file.exists()) { + throw new RuntimeException("Could not find %s, it must be present at spec creation time to calculate mappings hash".formatted(file.getAbsolutePath())); + } + + // Use the file hash as part of the spec, this means if the input file changes the mappings will be re-generated. + return Objects.hash(Arrays.hashCode(Checksum.sha256(file)), file.getAbsolutePath()); + } + + @Override + public Path get(MappingContext context) { + return file.toPath(); + } + + @Override + public int hashCode() { + return hash; + } +} diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/utils/MavenFileSpec.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/utils/MavenFileSpec.java new file mode 100644 index 0000000..f833fe1 --- /dev/null +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/utils/MavenFileSpec.java @@ -0,0 +1,37 @@ +/* + * 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.configuration.providers.mappings.utils; + +import java.nio.file.Path; + +import net.fabricmc.loom.api.mappings.layered.spec.FileSpec; +import net.fabricmc.loom.api.mappings.layered.MappingContext; + +public record MavenFileSpec(String dependencyNotation) implements FileSpec { + @Override + public Path get(MappingContext context) { + return context.resolveMavenDependency(dependencyNotation); + } +} diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftMappedProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftMappedProvider.java index b95f819..7535e1a 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftMappedProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftMappedProvider.java @@ -35,6 +35,7 @@ import java.util.function.Consumer; import com.google.common.collect.ImmutableMap; import org.gradle.api.Project; +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.loom.configuration.DependencyProvider; import net.fabricmc.loom.configuration.providers.MinecraftProviderImpl; import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl; @@ -99,7 +100,7 @@ public class MinecraftMappedProvider extends DependencyProvider { } private void mapMinecraftJar() throws IOException { - String fromM = "official"; + String fromM = MappingsNamespace.OFFICIAL.toString(); MappingsProviderImpl mappingsProvider = getExtension().getMappingsProvider(); @@ -107,8 +108,8 @@ public class MinecraftMappedProvider extends DependencyProvider { Path outputMapped = minecraftMappedJar.toPath(); Path outputIntermediary = minecraftIntermediaryJar.toPath(); - for (String toM : Arrays.asList("named", "intermediary")) { - Path output = "named".equals(toM) ? outputMapped : outputIntermediary; + for (String toM : Arrays.asList(MappingsNamespace.NAMED.toString(), MappingsNamespace.INTERMEDIARY.toString())) { + Path output = MappingsNamespace.NAMED.toString().equals(toM) ? outputMapped : outputIntermediary; getProject().getLogger().lifecycle(":remapping minecraft (TinyRemapper, " + fromM + " -> " + toM + ")"); diff --git a/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java b/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java index b1c4b12..93e8852 100644 --- a/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java +++ b/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java @@ -37,12 +37,13 @@ import org.gradle.api.publish.maven.MavenPublication; import net.fabricmc.loom.api.LoomGradleExtensionAPI; import net.fabricmc.loom.api.MixinExtensionAPI; import net.fabricmc.loom.api.decompilers.LoomDecompiler; +import net.fabricmc.loom.api.mappings.layered.spec.LayeredMappingSpecBuilder; import net.fabricmc.loom.configuration.ide.RunConfigSettings; import net.fabricmc.loom.configuration.mods.ModVersionParser; import net.fabricmc.loom.configuration.processors.JarProcessor; import net.fabricmc.loom.configuration.providers.mappings.GradleMappingContext; import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpec; -import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilder; +import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilderImpl; import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingsDependency; import net.fabricmc.loom.util.DeprecationHelper; @@ -113,7 +114,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA @Override public Dependency layered(Action action) { - LayeredMappingSpecBuilder builder = new LayeredMappingSpecBuilder(); + LayeredMappingSpecBuilderImpl builder = new LayeredMappingSpecBuilderImpl(); action.execute(builder); LayeredMappingSpec builtSpec = builder.build(); return new LayeredMappingsDependency(new GradleMappingContext(getProject(), builtSpec.getVersion().replace("+", "_").replace(".", "_")), builtSpec, builtSpec.getVersion()); diff --git a/src/main/java/net/fabricmc/loom/extension/MinecraftGradleExtension.java b/src/main/java/net/fabricmc/loom/extension/MinecraftGradleExtension.java index c4ea3d3..5b02a7d 100644 --- a/src/main/java/net/fabricmc/loom/extension/MinecraftGradleExtension.java +++ b/src/main/java/net/fabricmc/loom/extension/MinecraftGradleExtension.java @@ -36,9 +36,9 @@ import org.gradle.api.publish.maven.MavenPublication; import net.fabricmc.loom.api.LoomGradleExtensionAPI; import net.fabricmc.loom.api.MixinExtensionAPI; import net.fabricmc.loom.api.decompilers.LoomDecompiler; +import net.fabricmc.loom.api.mappings.layered.spec.LayeredMappingSpecBuilder; import net.fabricmc.loom.configuration.ide.RunConfigSettings; import net.fabricmc.loom.configuration.processors.JarProcessor; -import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilder; import net.fabricmc.loom.util.DeprecationHelper; public class MinecraftGradleExtension implements LoomGradleExtensionAPI { diff --git a/src/main/java/net/fabricmc/loom/task/MigrateMappingsTask.java b/src/main/java/net/fabricmc/loom/task/MigrateMappingsTask.java index 508dfee..2afc276 100644 --- a/src/main/java/net/fabricmc/loom/task/MigrateMappingsTask.java +++ b/src/main/java/net/fabricmc/loom/task/MigrateMappingsTask.java @@ -49,10 +49,11 @@ import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.options.Option; import net.fabricmc.loom.LoomGradleExtension; +import net.fabricmc.loom.api.mappings.layered.spec.LayeredMappingSpecBuilder; +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; +import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingsDependency; import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl; import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvider; -import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilder; -import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingsDependency; import net.fabricmc.loom.util.SourceRemapper; import net.fabricmc.lorenztiny.TinyMappingsJoiner; import net.fabricmc.mapping.tree.TinyMappingFactory; @@ -166,9 +167,9 @@ public class MigrateMappingsTask extends AbstractLoomTask { project.getLogger().info(":joining mappings"); MappingSet mappingSet = new TinyMappingsJoiner( - currentMappings, "named", - targetMappings, "named", - "intermediary" + currentMappings, MappingsNamespace.NAMED.toString(), + targetMappings, MappingsNamespace.NAMED.toString(), + MappingsNamespace.INTERMEDIARY.toString() ).read(); project.getLogger().lifecycle(":remapping"); diff --git a/src/main/java/net/fabricmc/loom/task/RemapJarTask.java b/src/main/java/net/fabricmc/loom/task/RemapJarTask.java index 2bab9f5..bd83c79 100644 --- a/src/main/java/net/fabricmc/loom/task/RemapJarTask.java +++ b/src/main/java/net/fabricmc/loom/task/RemapJarTask.java @@ -57,6 +57,7 @@ import org.zeroturnaround.zip.transform.StreamZipEntryTransformer; import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry; import net.fabricmc.loom.LoomGradleExtension; +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.loom.build.JarRemapper; import net.fabricmc.loom.build.MixinRefmapHelper; import net.fabricmc.loom.build.nesting.JarNester; @@ -130,8 +131,8 @@ public class RemapJarTask extends Jar { MappingsProviderImpl mappingsProvider = extension.getMappingsProvider(); - String fromM = "named"; - String toM = "intermediary"; + String fromM = MappingsNamespace.NAMED.toString(); + String toM = MappingsNamespace.INTERMEDIARY.toString(); if (isMainRemapTask) { jarRemapper.addToClasspath(getRemapClasspath()); diff --git a/src/main/java/net/fabricmc/loom/task/RemapSourcesJarTask.java b/src/main/java/net/fabricmc/loom/task/RemapSourcesJarTask.java index 858c7ec..26fd6a3 100644 --- a/src/main/java/net/fabricmc/loom/task/RemapSourcesJarTask.java +++ b/src/main/java/net/fabricmc/loom/task/RemapSourcesJarTask.java @@ -32,12 +32,13 @@ import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.TaskAction; +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.loom.util.SourceRemapper; public class RemapSourcesJarTask extends AbstractLoomTask { private final RegularFileProperty input = getProject().getObjects().fileProperty(); private final RegularFileProperty output = getProject().getObjects().fileProperty().convention(input); - private final Property targetNamespace = getProject().getObjects().property(String.class).convention("intermediary"); + private final Property targetNamespace = getProject().getObjects().property(String.class).convention(MappingsNamespace.INTERMEDIARY.toString()); private SourceRemapper sourceRemapper = null; private final Property preserveFileTimestamps = getProject().getObjects().property(Boolean.class).convention(true); private final Property reproducibleFileOrder = getProject().getObjects().property(Boolean.class).convention(false); @@ -49,7 +50,7 @@ public class RemapSourcesJarTask extends AbstractLoomTask { public void remap() throws Exception { if (sourceRemapper == null) { String direction = targetNamespace.get(); - SourceRemapper.remapSources(getProject(), input.get().getAsFile(), output.get().getAsFile(), direction.equals("named"), reproducibleFileOrder.get(), preserveFileTimestamps.get()); + SourceRemapper.remapSources(getProject(), input.get().getAsFile(), output.get().getAsFile(), direction.equals(MappingsNamespace.NAMED.toString()), reproducibleFileOrder.get(), preserveFileTimestamps.get()); } else { sourceRemapper.scheduleRemapSources(input.get().getAsFile(), output.get().getAsFile(), reproducibleFileOrder.get(), preserveFileTimestamps.get()); } diff --git a/src/main/java/net/fabricmc/loom/util/SourceRemapper.java b/src/main/java/net/fabricmc/loom/util/SourceRemapper.java index 66c74dc..8f7bf89 100644 --- a/src/main/java/net/fabricmc/loom/util/SourceRemapper.java +++ b/src/main/java/net/fabricmc/loom/util/SourceRemapper.java @@ -40,6 +40,7 @@ import org.gradle.api.Project; import org.zeroturnaround.zip.ZipUtil; import net.fabricmc.loom.LoomGradleExtension; +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.loom.configuration.RemappedConfigurationEntry; import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl; import net.fabricmc.loom.util.gradle.ProgressLogger; @@ -166,7 +167,7 @@ public class SourceRemapper { try { TinyTree m = mappingsProvider.getMappings(); project.getLogger().info(":loading " + (toNamed ? "intermediary -> named" : "named -> intermediary") + " source mappings"); - return new TinyMappingsReader(m, toNamed ? "intermediary" : "named", toNamed ? "named" : "intermediary").read(); + return new TinyMappingsReader(m, toNamed ? MappingsNamespace.INTERMEDIARY.toString() : MappingsNamespace.NAMED.toString(), toNamed ? MappingsNamespace.NAMED.toString() : MappingsNamespace.INTERMEDIARY.toString()).read(); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/LayeredMappingSpecBuilderTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/LayeredMappingSpecBuilderTest.groovy index 53a5b3e..743ddc5 100644 --- a/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/LayeredMappingSpecBuilderTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/LayeredMappingSpecBuilderTest.groovy @@ -24,8 +24,9 @@ package net.fabricmc.loom.test.unit.layeredmappings +import net.fabricmc.loom.configuration.providers.mappings.utils.MavenFileSpec import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpec -import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilder +import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilderImpl import net.fabricmc.loom.configuration.providers.mappings.intermediary.IntermediaryMappingsSpec import net.fabricmc.loom.configuration.providers.mappings.mojmap.MojangMappingsSpec import net.fabricmc.loom.configuration.providers.mappings.parchment.ParchmentMappingsSpec @@ -61,7 +62,7 @@ class LayeredMappingSpecBuilderTest extends Specification { layers[0].class == IntermediaryMappingsSpec layers[1].class == MojangMappingsSpec layers[2].class == ParchmentMappingsSpec - parchment.mavenNotation() == "I like cake" + (parchment.fileSpec() as MavenFileSpec).dependencyNotation() == "I like cake" parchment.removePrefix() == true } @@ -81,7 +82,7 @@ class LayeredMappingSpecBuilderTest extends Specification { layers[0].class == IntermediaryMappingsSpec layers[1].class == MojangMappingsSpec layers[2].class == ParchmentMappingsSpec - parchment.mavenNotation() == "I like cake" + (parchment.fileSpec() as MavenFileSpec).dependencyNotation() == "I like cake" parchment.removePrefix() == false } @@ -101,17 +102,17 @@ class LayeredMappingSpecBuilderTest extends Specification { layers[0].class == IntermediaryMappingsSpec layers[1].class == MojangMappingsSpec layers[2].class == ParchmentMappingsSpec - parchment.mavenNotation() == "I really like cake" + (parchment.fileSpec() as MavenFileSpec).dependencyNotation() == "I really like cake" parchment.removePrefix() == false } // Gradle does this big of magic behind the scenes - LayeredMappingSpec layered(@DelegatesTo(LayeredMappingSpecBuilder) Closure cl) { + LayeredMappingSpec layered(@DelegatesTo(LayeredMappingSpecBuilderImpl) Closure cl) { return layeredAction(ConfigureUtil.configureUsing(cl)) } - LayeredMappingSpec layeredAction(Action action) { - LayeredMappingSpecBuilder builder = new LayeredMappingSpecBuilder() + LayeredMappingSpec layeredAction(Action action) { + LayeredMappingSpecBuilderImpl builder = new LayeredMappingSpecBuilderImpl() action.execute(builder) return builder.build() } diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/LayeredMappingsSpecification.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/LayeredMappingsSpecification.groovy index 1042912..1fba03d 100644 --- a/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/LayeredMappingsSpecification.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/LayeredMappingsSpecification.groovy @@ -28,18 +28,20 @@ import groovy.transform.CompileStatic import net.fabricmc.loom.configuration.providers.MinecraftProvider import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpec import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingsProcessor -import net.fabricmc.loom.configuration.providers.mappings.MappingContext -import net.fabricmc.loom.configuration.providers.mappings.MappingLayer -import net.fabricmc.loom.configuration.providers.mappings.MappingNamespace +import net.fabricmc.loom.api.mappings.layered.MappingContext +import net.fabricmc.loom.api.mappings.layered.MappingLayer +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider -import net.fabricmc.loom.configuration.providers.mappings.MappingsSpec +import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec import net.fabricmc.mappingio.adapter.MappingDstNsReorder import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch import net.fabricmc.mappingio.format.Tiny2Writer import net.fabricmc.mappingio.tree.MemoryMappingTree +import org.gradle.api.artifacts.Dependency import org.gradle.api.logging.Logger import spock.lang.Specification +import java.nio.file.Path import java.util.zip.ZipFile abstract class LayeredMappingsSpecification extends Specification implements LayeredMappingsTestConstants { @@ -94,8 +96,8 @@ abstract class LayeredMappingsSpecification extends Specification implements Lay MemoryMappingTree reorder(MemoryMappingTree mappingTree) { def reorderedMappings = new MemoryMappingTree() - def nsReorder = new MappingDstNsReorder(reorderedMappings, Collections.singletonList(MappingNamespace.NAMED.stringValue())) - def nsSwitch = new MappingSourceNsSwitch(nsReorder, MappingNamespace.INTERMEDIARY.stringValue(), true) + def nsReorder = new MappingDstNsReorder(reorderedMappings, Collections.singletonList(MappingsNamespace.NAMED.toString())) + def nsSwitch = new MappingSourceNsSwitch(nsReorder, MappingsNamespace.INTERMEDIARY.toString(), true) mappingTree.accept(nsSwitch) return reorderedMappings } @@ -103,9 +105,14 @@ abstract class LayeredMappingsSpecification extends Specification implements Lay @CompileStatic class TestMappingContext implements MappingContext { @Override - File mavenFile(String mavenNotation) { + Path resolveDependency(Dependency dependency) { + throw new UnsupportedOperationException("TODO") + } + + @Override + Path resolveMavenDependency(String mavenNotation) { assert mavenFiles.containsKey(mavenNotation) - return mavenFiles.get(mavenNotation) + return mavenFiles.get(mavenNotation).toPath() } @Override @@ -119,8 +126,8 @@ abstract class LayeredMappingsSpecification extends Specification implements Lay } @Override - File workingDirectory(String name) { - return new File(tempDir, name) + Path workingDirectory(String name) { + return new File(tempDir, name).toPath() } @Override diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/ParchmentMappingLayerTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/ParchmentMappingLayerTest.groovy index ac9592c..73e2a25 100644 --- a/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/ParchmentMappingLayerTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/ParchmentMappingLayerTest.groovy @@ -24,6 +24,7 @@ package net.fabricmc.loom.test.unit.layeredmappings +import net.fabricmc.loom.api.mappings.layered.spec.FileSpec import net.fabricmc.loom.configuration.providers.mappings.intermediary.IntermediaryMappingsSpec import net.fabricmc.loom.configuration.providers.mappings.mojmap.MojangMappingsSpec import net.fabricmc.loom.configuration.providers.mappings.parchment.ParchmentMappingsSpec @@ -38,7 +39,7 @@ class ParchmentMappingLayerTest extends LayeredMappingsSpecification { def mappings = getLayeredMappings( new IntermediaryMappingsSpec(), new MojangMappingsSpec(), - new ParchmentMappingsSpec(PARCHMENT_NOTATION, false) + new ParchmentMappingsSpec(FileSpec.create(PARCHMENT_NOTATION), false) ) def tiny = getTiny(mappings) def reorderedMappings = reorder(mappings) @@ -61,7 +62,7 @@ class ParchmentMappingLayerTest extends LayeredMappingsSpecification { def mappings = getLayeredMappings( new IntermediaryMappingsSpec(), new MojangMappingsSpec(), - new ParchmentMappingsSpec(PARCHMENT_NOTATION, true) + new ParchmentMappingsSpec(FileSpec.create(PARCHMENT_NOTATION), true) ) def tiny = getTiny(mappings) def reorderedMappings = reorder(mappings)