From 61fa4d9fb6e80969b7a736e0ae796d5cdd8679da Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Wed, 21 Jul 2021 22:29:23 +0100 Subject: [PATCH] Fix MojangMappingsSpec having the same hash version for each mc version. I dont think this would be a real cause for concern as the jar would have had the mc version in it anyway. --- .../fabricmc/loom/LoomGradleExtension.java | 4 +-- .../mappings/LayeredMappingSpecBuilder.java | 8 ++++- .../mappings/mojmap/MojangMappingsSpec.java | 2 +- .../extension/LoomGradleExtensionApiImpl.java | 12 +++++-- .../extension/LoomGradleExtensionImpl.java | 6 ++++ .../LayeredMappingSpecBuilderTest.groovy | 36 ++++++++++++++++--- .../MojangMappingLayerTest.groovy | 2 +- 7 files changed, 57 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java index 2705898..e03fda1 100644 --- a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java +++ b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java @@ -75,9 +75,7 @@ public interface LoomGradleExtension extends LoomGradleExtensionAPI { JarProcessorManager getJarProcessorManager(); - default MinecraftProviderImpl getMinecraftProvider() { - return getDependencyManager().getProvider(MinecraftProviderImpl.class); - } + MinecraftProviderImpl getMinecraftProvider(); default MappingsProviderImpl getMappingsProvider() { return getDependencyManager().getProvider(MappingsProviderImpl.class); diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpecBuilder.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpecBuilder.java index eae2066..1348be5 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpecBuilder.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpecBuilder.java @@ -30,15 +30,21 @@ import java.util.List; import org.gradle.api.Action; +import net.fabricmc.loom.configuration.providers.MinecraftProvider; 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; public class LayeredMappingSpecBuilder { private final List> layers = new LinkedList<>(); + private final MinecraftProvider minecraftProvider; + + public LayeredMappingSpecBuilder(MinecraftProvider minecraftProvider) { + this.minecraftProvider = minecraftProvider; + } public LayeredMappingSpecBuilder officialMojangMappings() { - layers.add(new MojangMappingsSpec()); + layers.add(new MojangMappingsSpec(minecraftProvider.minecraftVersion())); return this; } 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..21c6624 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 @@ -28,7 +28,7 @@ import net.fabricmc.loom.configuration.providers.mappings.MappingContext; import net.fabricmc.loom.configuration.providers.mappings.MappingsSpec; import net.fabricmc.loom.configuration.providers.minecraft.MinecraftVersionMeta; -public record MojangMappingsSpec() implements MappingsSpec { +public record MojangMappingsSpec(String minecraftVersion) implements MappingsSpec { // Keys in dependency manifest private static final String MANIFEST_CLIENT_MAPPINGS = "client_mappings"; private static final String MANIFEST_SERVER_MAPPINGS = "server_mappings"; diff --git a/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java b/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java index 3d9ca87..c865b18 100644 --- a/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java +++ b/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java @@ -36,11 +36,12 @@ import org.gradle.api.artifacts.Dependency; import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.plugins.BasePluginConvention; +import net.fabricmc.loom.api.LoomGradleExtensionAPI; import net.fabricmc.loom.api.MixinApExtensionAPI; import net.fabricmc.loom.api.decompilers.LoomDecompiler; -import net.fabricmc.loom.api.LoomGradleExtensionAPI; import net.fabricmc.loom.configuration.ide.RunConfigSettings; import net.fabricmc.loom.configuration.processors.JarProcessor; +import net.fabricmc.loom.configuration.providers.MinecraftProvider; import net.fabricmc.loom.configuration.providers.mappings.GradleMappingContext; import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpec; import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilder; @@ -113,7 +114,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA @Override public Dependency layered(Action action) { - LayeredMappingSpecBuilder builder = new LayeredMappingSpecBuilder(); + LayeredMappingSpecBuilder builder = new LayeredMappingSpecBuilder(getMinecraftProvider()); action.execute(builder); LayeredMappingSpec builtSpec = builder.build(); return new LayeredMappingsDependency(new GradleMappingContext(getProject(), "layers_" + builtSpec.getVersion().replace("+", "_").replace(".", "_")), builtSpec, builtSpec.getVersion()); @@ -182,6 +183,8 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA protected abstract MixinApExtension getMixinApExtension(); + protected abstract MinecraftProvider getMinecraftProvider(); + // This is here to ensure that LoomGradleExtensionApiImpl compiles without any unimplemented methods private final class EnsureCompile extends LoomGradleExtensionApiImpl { private EnsureCompile() { @@ -203,5 +206,10 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA protected MixinApExtension getMixinApExtension() { throw new RuntimeException("Yeah... something is really wrong"); } + + @Override + protected MinecraftProvider getMinecraftProvider() { + throw new RuntimeException("Yeah... something is really wrong"); + } } } diff --git a/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionImpl.java b/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionImpl.java index 436f9b6..d78052b 100644 --- a/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionImpl.java +++ b/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionImpl.java @@ -44,6 +44,7 @@ import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.configuration.InstallerData; import net.fabricmc.loom.configuration.LoomDependencyManager; import net.fabricmc.loom.configuration.processors.JarProcessorManager; +import net.fabricmc.loom.configuration.providers.MinecraftProviderImpl; public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implements LoomGradleExtension { private final Project project; @@ -110,6 +111,11 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen return Objects.requireNonNull(jarProcessorManager, "Cannot get JarProcessorManager before it has been setup"); } + @Override + public MinecraftProviderImpl getMinecraftProvider() { + return getDependencyManager().getProvider(MinecraftProviderImpl.class); + } + @Override public MappingSet getOrCreateSrcMappingCache(int id, Supplier factory) { return srcMappingCache[id] != null ? srcMappingCache[id] : (srcMappingCache[id] = factory.get()); 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..f808069 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,6 +24,7 @@ package net.fabricmc.loom.test.unit.layeredmappings +import net.fabricmc.loom.configuration.providers.MinecraftProvider import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpec import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilder import net.fabricmc.loom.configuration.providers.mappings.intermediary.IntermediaryMappingsSpec @@ -34,20 +35,41 @@ import org.gradle.util.ConfigureUtil import spock.lang.Specification class LayeredMappingSpecBuilderTest extends Specification { + MinecraftProvider mockMinecraftProvider = Mock(MinecraftProvider) + def "simple mojmap" () { + setup: + mockMinecraftProvider.minecraftVersion() >> "1.17" when: def spec = layered() { officialMojangMappings() } def layers = spec.layers() then: - spec.version == "layered+hash.961" + spec.version == "layered+hash.1506500" + layers.size() == 2 + layers[0].class == IntermediaryMappingsSpec + layers[1].class == MojangMappingsSpec + } + + def "simple mojmap alternative version" () { + setup: + mockMinecraftProvider.minecraftVersion() >> "1.17.1" + when: + def spec = layered() { + officialMojangMappings() + } + def layers = spec.layers() + then: + spec.version == "layered+hash.1446825415" layers.size() == 2 layers[0].class == IntermediaryMappingsSpec layers[1].class == MojangMappingsSpec } def "simple mojmap with parchment" () { + setup: + mockMinecraftProvider.minecraftVersion() >> "1.17" when: def spec = layered() { officialMojangMappings() @@ -56,7 +78,7 @@ class LayeredMappingSpecBuilderTest extends Specification { def layers = spec.layers() def parchment = layers[2] as ParchmentMappingsSpec then: - spec.version == "layered+hash.863714404" + spec.version == "layered+hash.910386113" layers.size() == 3 layers[0].class == IntermediaryMappingsSpec layers[1].class == MojangMappingsSpec @@ -66,6 +88,8 @@ class LayeredMappingSpecBuilderTest extends Specification { } def "simple mojmap with parchment keep prefix" () { + setup: + mockMinecraftProvider.minecraftVersion() >> "1.17" when: def spec = layered() { officialMojangMappings() @@ -76,7 +100,7 @@ class LayeredMappingSpecBuilderTest extends Specification { def layers = spec.layers() def parchment = layers[2] as ParchmentMappingsSpec then: - spec.version == "layered+hash.863714410" + spec.version == "layered+hash.910386119" layers.size() == 3 layers[0].class == IntermediaryMappingsSpec layers[1].class == MojangMappingsSpec @@ -86,6 +110,8 @@ class LayeredMappingSpecBuilderTest extends Specification { } def "simple mojmap with parchment keep prefix alternate hash" () { + setup: + mockMinecraftProvider.minecraftVersion() >> "1.17" when: def spec = layered() { officialMojangMappings() @@ -96,7 +122,7 @@ class LayeredMappingSpecBuilderTest extends Specification { def layers = spec.layers() def parchment = layers[2] as ParchmentMappingsSpec then: - spec.version == "layered+hash.1144465487" + spec.version == "layered+hash.1097793778" layers.size() == 3 layers[0].class == IntermediaryMappingsSpec layers[1].class == MojangMappingsSpec @@ -111,7 +137,7 @@ class LayeredMappingSpecBuilderTest extends Specification { } LayeredMappingSpec layeredAction(Action action) { - LayeredMappingSpecBuilder builder = new LayeredMappingSpecBuilder() + LayeredMappingSpecBuilder builder = new LayeredMappingSpecBuilder(mockMinecraftProvider) action.execute(builder) return builder.build() } diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/MojangMappingLayerTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/MojangMappingLayerTest.groovy index 87eca55..c6ce8a4 100644 --- a/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/MojangMappingLayerTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/MojangMappingLayerTest.groovy @@ -35,7 +35,7 @@ class MojangMappingLayerTest extends LayeredMappingsSpecification { when: def mappings = getLayeredMappings( new IntermediaryMappingsSpec(), - new MojangMappingsSpec() + new MojangMappingsSpec("1.17") ) def tiny = getTiny(mappings) then: