From a2a63563d4680f181ca36f6b2113bb02ec376d6e Mon Sep 17 00:00:00 2001 From: marcus8448 Date: Sat, 6 Jul 2024 09:56:43 -0700 Subject: [PATCH] feat: skip merging mappings on CI --- gradle.properties | 4 +-- .../mojarn/api/MojarnMappingsSpecBuilder.java | 25 ++++++++++++------- .../mojarn/impl/MojarnExtensionImpl.java | 2 +- .../mojarn/impl/MojarnMappingsLayer.java | 16 ++++++++---- .../mojarn/impl/MojarnMappingsSpec.java | 6 +++-- .../impl/MojarnMappingsSpecBuilderImpl.java | 7 ++++++ .../mojarn/impl/MojarnPlugin.java | 1 + 7 files changed, 42 insertions(+), 19 deletions(-) diff --git a/gradle.properties b/gradle.properties index dfb500b..db83af0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,8 +2,8 @@ plugin.group=dev.galacticraft plugin.name=Mojarn plugin.id=mojarn plugin.description=Mixes official and yarn mappings for better argument names -plugin.version=0.3.0 +plugin.version=0.4.0 -loom.version=1.7.1 +loom.version=1.7.2 mapping-io.version=0.6.1 junit.version=5.10.2 diff --git a/src/main/java/dev/galacticraft/mojarn/api/MojarnMappingsSpecBuilder.java b/src/main/java/dev/galacticraft/mojarn/api/MojarnMappingsSpecBuilder.java index 14c022a..cdbe6ac 100644 --- a/src/main/java/dev/galacticraft/mojarn/api/MojarnMappingsSpecBuilder.java +++ b/src/main/java/dev/galacticraft/mojarn/api/MojarnMappingsSpecBuilder.java @@ -30,35 +30,42 @@ public interface MojarnMappingsSpecBuilder { /** * Whether to remap arguments with class types. - * @param remapArguments Whether to map arguments with class types - * @return This builder + * @param remapArguments whether to map arguments with class types + * @return this builder */ MojarnMappingsSpecBuilder remapArguments(boolean remapArguments); /** * Whether to remap partial argument matches with class types. - * @param partialMatch Whether to remap partial argument matches with class types - * @return This builder + * @param partialMatch whether to remap partial argument matches with class types + * @return this builder */ MojarnMappingsSpecBuilder partialMatch(boolean partialMatch); /** * Disable mapping when the class name is different. - * @param skipDifferent Whether to skip mapping when the class name is different - * @return This builder + * @param skipDifferent whether to skip mapping when the class name is different + * @return this builder */ MojarnMappingsSpecBuilder skipDifferent(boolean skipDifferent); /** * Whether to map variables. - * @param mapVariables Whether to map variables - * @return This builder + * @param mapVariables whether to map variables + * @return this builder */ MojarnMappingsSpecBuilder mapVariables(boolean mapVariables); + + /** + * Whether to disable mojarn when in a CI environment. + * @param skipCI whether to disable mojarn when in a CI environment + * @return this builder + */ + MojarnMappingsSpecBuilder skipCI(boolean skipCI); /** * Whether the mapping file is an Enigma mappings file (forwarded to file mapping builder). - * @return This builder + * @return this builder * @see FileMappingsSpecBuilder#enigmaMappings() */ MojarnMappingsSpecBuilder fileIsEnigma(); diff --git a/src/main/java/dev/galacticraft/mojarn/impl/MojarnExtensionImpl.java b/src/main/java/dev/galacticraft/mojarn/impl/MojarnExtensionImpl.java index 84fafaa..cc938ff 100644 --- a/src/main/java/dev/galacticraft/mojarn/impl/MojarnExtensionImpl.java +++ b/src/main/java/dev/galacticraft/mojarn/impl/MojarnExtensionImpl.java @@ -56,6 +56,6 @@ public Dependency mappings(Object file, Action b.addLayer(new MojarnMappingsSpec(new IntermediaryMappingsSpec(), mojangSpec, fileSpec, builder.remapArguments, builder.partialMatch, builder.skipDifferent, builder.mapVariables))); + return loom.layered(b -> b.addLayer(new MojarnMappingsSpec(new IntermediaryMappingsSpec(), mojangSpec, fileSpec, builder.remapArguments, builder.partialMatch, builder.skipDifferent, builder.skipCI, builder.mapVariables))); } } diff --git a/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsLayer.java b/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsLayer.java index 3d174f1..ad93d0c 100644 --- a/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsLayer.java +++ b/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsLayer.java @@ -47,8 +47,9 @@ public class MojarnMappingsLayer implements MappingLayer { private final boolean partialMatch; private final boolean skipDifferent; private final boolean mapVariables; + private final boolean skipCI; - public MojarnMappingsLayer(@NotNull MappingLayer intermediary, @NotNull MappingLayer mojang, @NotNull MappingLayer yarn, boolean remapArguments, boolean partialMatch, boolean skipDifferent, boolean mapVariables) { + public MojarnMappingsLayer(@NotNull MappingLayer intermediary, @NotNull MappingLayer mojang, @NotNull MappingLayer yarn, boolean remapArguments, boolean partialMatch, boolean skipDifferent, boolean mapVariables, boolean skipCI) { this.intermediary = intermediary; this.mojang = mojang; this.yarn = yarn; @@ -56,6 +57,7 @@ public MojarnMappingsLayer(@NotNull MappingLayer intermediary, @NotNull MappingL this.partialMatch = partialMatch; this.skipDifferent = skipDifferent; this.mapVariables = mapVariables; + this.skipCI = skipCI; } @Override @@ -64,6 +66,11 @@ public void visit(MappingVisitor mappingVisitor) throws IOException { this.mojang.visit(mappingVisitor); + if (MojarnPlugin.isCI && this.skipCI) { + MojarnPlugin.LOGGER.info("Skipping mapping layer generation for CI build."); + return; + } + // generate a tree of official mappings MemoryMappingTree officialTree = new MemoryMappingTree(); this.intermediary.visit(officialTree); @@ -124,9 +131,8 @@ public void visit(MappingVisitor mappingVisitor) throws IOException { if (desc[i] == 'L') { // parse class types StringBuilder sb = new StringBuilder(); - while (desc[i] != ';') { + while (desc[++i] != ';') { sb.append(desc[i]); - i++; } descriptor.add(sb.toString()); } else if (desc[i] == ')') { @@ -148,7 +154,7 @@ public void visit(MappingVisitor mappingVisitor) throws IOException { // check if the argument is a class if (descriptor.get(i) != null) { // get the class mapping of the argument type - MappingTree.ClassMapping typeClass = yarnTree.getClass(descriptor.get(i)); + MappingTree.ClassMapping typeClass = yarnTree.getClass(descriptor.get(i), named); // if there is a mapping for this type, try to remap it. if (typeClass != null) { // skip if class remapping is disabled @@ -156,7 +162,7 @@ public void visit(MappingVisitor mappingVisitor) throws IOException { continue; } - String typeName = typeClass.getDstName(named); + String typeName = getClassName(descriptor.get(i)); if (typeName != null) { // check if class ends in numeric suffix diff --git a/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpec.java b/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpec.java index 1993acd..cfb86d8 100644 --- a/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpec.java +++ b/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpec.java @@ -26,9 +26,11 @@ import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec; import org.jetbrains.annotations.NotNull; -public record MojarnMappingsSpec(@NotNull MappingsSpec intermediary, @NotNull MappingsSpec mojang, @NotNull MappingsSpec yarn, boolean remapArguments, boolean partialMatch, boolean skipDifferent, boolean matchVariables) implements MappingsSpec { +import java.util.Objects; + +public record MojarnMappingsSpec(@NotNull MappingsSpec intermediary, @NotNull MappingsSpec mojang, @NotNull MappingsSpec yarn, boolean remapArguments, boolean partialMatch, boolean skipDifferent, boolean skipCI, boolean matchVariables) implements MappingsSpec { @Override public MojarnMappingsLayer createLayer(MappingContext context) { - return new MojarnMappingsLayer(this.intermediary.createLayer(context), this.mojang.createLayer(context), this.yarn.createLayer(context), this.remapArguments, this.partialMatch, this.skipDifferent, this.matchVariables); + return new MojarnMappingsLayer(this.intermediary.createLayer(context), this.mojang.createLayer(context), this.yarn.createLayer(context), this.remapArguments, this.partialMatch, this.skipDifferent, this.skipCI, this.matchVariables); } } diff --git a/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpecBuilderImpl.java b/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpecBuilderImpl.java index 66502b1..808bbc7 100644 --- a/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpecBuilderImpl.java +++ b/src/main/java/dev/galacticraft/mojarn/impl/MojarnMappingsSpecBuilderImpl.java @@ -29,6 +29,7 @@ public class MojarnMappingsSpecBuilderImpl implements MojarnMappingsSpecBuilder boolean partialMatch = false; boolean skipDifferent = false; boolean mapVariables = true; + boolean skipCI = true; boolean fileIsEnigma = false; @Override @@ -55,6 +56,12 @@ public MojarnMappingsSpecBuilder mapVariables(boolean mapVariables) { return this; } + @Override + public MojarnMappingsSpecBuilder skipCI(boolean skipCI) { + this.skipCI = skipCI; + return this; + } + @Override public MojarnMappingsSpecBuilder fileIsEnigma() { this.fileIsEnigma = true; diff --git a/src/main/java/dev/galacticraft/mojarn/impl/MojarnPlugin.java b/src/main/java/dev/galacticraft/mojarn/impl/MojarnPlugin.java index 110e1f4..13377ec 100644 --- a/src/main/java/dev/galacticraft/mojarn/impl/MojarnPlugin.java +++ b/src/main/java/dev/galacticraft/mojarn/impl/MojarnPlugin.java @@ -34,6 +34,7 @@ */ public final class MojarnPlugin implements Plugin { public static final Logger LOGGER = LoggerFactory.getLogger("Mojarn"); + public static final boolean isCI = System.getenv("CI") != null; @Override public void apply(Project project) {