mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-28 04:07:01 -05:00
Merge remote-tracking branch 'FabricMC/dev/0.10' into dev/0.10.0
# Conflicts: # src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingSpecBuilderImpl.java # src/main/java/net/fabricmc/loom/configuration/providers/mappings/mojmap/MojangMappingLayer.java # src/main/java/net/fabricmc/loom/configuration/providers/mappings/mojmap/MojangMappingsSpec.java # src/test/groovy/net/fabricmc/loom/test/unit/layeredmappings/LayeredMappingSpecBuilderTest.groovy
This commit is contained in:
@@ -145,7 +145,7 @@ dependencies {
|
||||
exclude module: 'groovy-all'
|
||||
}
|
||||
testImplementation 'io.javalin:javalin:3.13.11'
|
||||
testImplementation 'net.fabricmc:fabric-installer:0.7.4'
|
||||
testImplementation 'net.fabricmc:fabric-installer:0.9.0'
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:22.0.0'
|
||||
}
|
||||
|
||||
@@ -24,7 +24,10 @@
|
||||
|
||||
package net.fabricmc.loom.api.mappings.layered.spec;
|
||||
|
||||
import groovy.lang.Closure;
|
||||
import groovy.lang.DelegatesTo;
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.util.ConfigureUtil;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
@@ -38,14 +41,34 @@ public interface LayeredMappingSpecBuilder {
|
||||
LayeredMappingSpecBuilder addLayer(MappingsSpec<?> mappingSpec);
|
||||
|
||||
/**
|
||||
* Add a layer that uses the official mappings provided by Mojang.
|
||||
* Add a layer that uses the official mappings provided by Mojang with the default options.
|
||||
*/
|
||||
LayeredMappingSpecBuilder officialMojangMappings();
|
||||
default LayeredMappingSpecBuilder officialMojangMappings() {
|
||||
return officialMojangMappings(builder -> { });
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure and add a layer that uses the official mappings provided by Mojang.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
default LayeredMappingSpecBuilder officialMojangMappings(@DelegatesTo(value = MojangMappingsSpecBuilder.class, strategy = Closure.DELEGATE_FIRST) Closure closure) {
|
||||
return officialMojangMappings(mojangMappingsSpecBuilder -> ConfigureUtil.configure(closure, mojangMappingsSpecBuilder));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure and add a layer that uses the official mappings provided by Mojang.
|
||||
*/
|
||||
LayeredMappingSpecBuilder officialMojangMappings(Action<MojangMappingsSpecBuilder> action);
|
||||
|
||||
default LayeredMappingSpecBuilder parchment(Object object) {
|
||||
return parchment(object, parchmentMappingsSpecBuilder -> parchmentMappingsSpecBuilder.setRemovePrefix(true));
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
default LayeredMappingSpecBuilder parchment(Object object, @DelegatesTo(value = ParchmentMappingsSpecBuilder.class, strategy = Closure.DELEGATE_FIRST) Closure closure) {
|
||||
return parchment(object, parchmentMappingsSpecBuilder -> ConfigureUtil.configure(closure, parchmentMappingsSpecBuilder));
|
||||
}
|
||||
|
||||
LayeredMappingSpecBuilder parchment(Object object, Action<ParchmentMappingsSpecBuilder> action);
|
||||
|
||||
LayeredMappingSpecBuilder crane(Object object);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public interface MojangMappingsSpecBuilder {
|
||||
/**
|
||||
* When enabled synthetic fields and methods will be mapped to name specified in the official mojang mappings.
|
||||
*
|
||||
* <p>When disabled synthetic fields and methods will not be mapped leaving them with their intermediary name.
|
||||
*/
|
||||
MojangMappingsSpecBuilder setNameSyntheticMembers(boolean value);
|
||||
|
||||
boolean getNameSyntheticMembers();
|
||||
}
|
||||
@@ -142,8 +142,8 @@ public final class CompileConfiguration {
|
||||
extendsFrom(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME, entry.getRemappedConfiguration(), project);
|
||||
}
|
||||
|
||||
if (entry.hasConsumerConfiguration()) {
|
||||
extendsFrom(entry.consumerConfiguration(), entry.sourceConfiguration(), project);
|
||||
for (String outgoingConfiguration : entry.publishingMode().outgoingConfigurations()) {
|
||||
extendsFrom(outgoingConfiguration, entry.sourceConfiguration(), project);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import groovy.util.Node;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
@@ -48,7 +49,9 @@ import net.fabricmc.loom.util.DeprecationHelper;
|
||||
import net.fabricmc.loom.util.GroovyXmlUtil;
|
||||
|
||||
public final class MavenPublication {
|
||||
private static final Map<String, String> CONFIGURATION_TO_SCOPE = Map.of(
|
||||
// ImmutableMap is needed since it guarantees ordering
|
||||
// (compile must go before runtime, or otherwise dependencies might get the "weaker" runtime scope).
|
||||
private static final Map<String, String> CONFIGURATION_TO_SCOPE = ImmutableMap.of(
|
||||
JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, "compile",
|
||||
JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, "runtime"
|
||||
);
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.gradle.api.Action;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.UnknownTaskException;
|
||||
import org.gradle.api.artifacts.ConfigurablePublishArtifact;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.PublishArtifact;
|
||||
import org.gradle.api.artifacts.dsl.ArtifactHandler;
|
||||
@@ -69,24 +70,17 @@ public class RemapConfiguration {
|
||||
if (extension.getSetupRemappedVariants().get()) {
|
||||
ArtifactHandler artifacts = project.getArtifacts();
|
||||
project.getTasks().named(DEFAULT_REMAP_JAR_TASK_NAME, task -> {
|
||||
artifacts.add(JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, task);
|
||||
artifacts.add(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, task);
|
||||
artifacts.add(JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, task, artifactConfigurationAction(task, DEFAULT_REMAP_JAR_TASK_NAME, project));
|
||||
artifacts.add(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, task, artifactConfigurationAction(task, DEFAULT_REMAP_JAR_TASK_NAME, project));
|
||||
});
|
||||
project.getTasks().named(DEFAULT_REMAP_SOURCES_JAR_TASK_NAME, RemapSourcesJarTask.class, task -> {
|
||||
if (!project.getConfigurations().getNames().contains(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME)) {
|
||||
// Sources jar may not have been created with withSourcesJar
|
||||
project.getLogger().info("Not publishing sources jar as it was not found. Use java.withSourcesJar() to fix.");
|
||||
return;
|
||||
}
|
||||
|
||||
PublishArtifact artifact = artifacts.add(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME, task.getOutput(), configurablePublishArtifact -> {
|
||||
Task remapJarTask = task;
|
||||
|
||||
if (extension.getShareRemapCaches().get()) {
|
||||
remapJarTask = project.getRootProject().getTasks().getByName(DEFAULT_REMAP_ALL_JARS_TASK_NAME);
|
||||
}
|
||||
|
||||
configurablePublishArtifact.builtBy(remapJarTask);
|
||||
});
|
||||
PublishArtifact artifact = artifacts.add(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME, task.getOutput(), artifactConfigurationAction(task, DEFAULT_REMAP_ALL_SOURCES_TASK_NAME, project));
|
||||
|
||||
// Remove the existing artifact that does not run remapSourcesJar.
|
||||
// It doesn't seem to hurt, but I'm not sure if the file-level duplicates cause issues.
|
||||
@@ -238,4 +232,18 @@ public class RemapConfiguration {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
|
||||
private static Action<ConfigurablePublishArtifact> artifactConfigurationAction(Task standardTask, String sharedTaskName, Project project) {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
|
||||
return artifact -> {
|
||||
Task remapTask = standardTask;
|
||||
|
||||
if (extension.getShareRemapCaches().get()) {
|
||||
remapTask = project.getRootProject().getTasks().getByName(sharedTaskName);
|
||||
}
|
||||
|
||||
artifact.builtBy(remapTask);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,17 +24,15 @@
|
||||
|
||||
package net.fabricmc.loom.configuration;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.gradle.api.artifacts.ConfigurationContainer;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public record RemappedConfigurationEntry(String sourceConfiguration, String targetConfiguration, boolean compileClasspath, boolean runtimeClasspath, String consumerConfiguration, @Nullable String replacedWith) {
|
||||
public RemappedConfigurationEntry(String sourceConfiguration, String targetConfiguration, boolean compileClasspath, boolean runtimeClasspath, String consumerConfiguration) {
|
||||
this(sourceConfiguration, targetConfiguration, compileClasspath, runtimeClasspath, consumerConfiguration, null);
|
||||
}
|
||||
|
||||
public boolean hasConsumerConfiguration() {
|
||||
return consumerConfiguration != null && !consumerConfiguration.isEmpty();
|
||||
public record RemappedConfigurationEntry(String sourceConfiguration, String targetConfiguration, boolean compileClasspath, boolean runtimeClasspath, PublishingMode publishingMode, @Nullable String replacedWith) {
|
||||
public RemappedConfigurationEntry(String sourceConfiguration, String targetConfiguration, boolean compileClasspath, boolean runtimeClasspath, PublishingMode publishingMode) {
|
||||
this(sourceConfiguration, targetConfiguration, compileClasspath, runtimeClasspath, publishingMode, null);
|
||||
}
|
||||
|
||||
public String getRemappedConfiguration() {
|
||||
@@ -48,4 +46,21 @@ public record RemappedConfigurationEntry(String sourceConfiguration, String targ
|
||||
|
||||
return targetConfiguration;
|
||||
}
|
||||
|
||||
public enum PublishingMode {
|
||||
NONE,
|
||||
COMPILE_ONLY(JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME),
|
||||
RUNTIME_ONLY(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME),
|
||||
COMPILE_AND_RUNTIME(JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME);
|
||||
|
||||
private final Set<String> outgoingConfigurations;
|
||||
|
||||
PublishingMode(String... outgoingConfigurations) {
|
||||
this.outgoingConfigurations = Set.of(outgoingConfigurations);
|
||||
}
|
||||
|
||||
public Set<String> outgoingConfigurations() {
|
||||
return outgoingConfigurations;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,12 @@ public final class TransitiveAccessWidenerMappingsProcessor {
|
||||
comment += "\n";
|
||||
}
|
||||
|
||||
comment += "Access widened by %s to %s".formatted(modId(), access);
|
||||
String awComment = "Access widened by %s to %s".formatted(modId(), access);
|
||||
|
||||
if (!comment.contains(awComment)) {
|
||||
// Ensure we don't comment the same thing twice. A bit of a cheap way to do this, but should work ok.
|
||||
comment += awComment;
|
||||
}
|
||||
|
||||
return comment;
|
||||
}
|
||||
|
||||
@@ -34,12 +34,13 @@ import org.jetbrains.annotations.Nullable;
|
||||
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.MojangMappingsSpecBuilder;
|
||||
import net.fabricmc.loom.api.mappings.layered.spec.ParchmentMappingsSpecBuilder;
|
||||
import net.fabricmc.loom.api.LoomGradleExtensionAPI;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.crane.CraneMappingsSpec;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.extras.signatures.SignatureFixesSpec;
|
||||
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.mojmap.MojangMappingsSpecBuilderImpl;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.parchment.ParchmentMappingsSpecBuilderImpl;
|
||||
|
||||
public class LayeredMappingSpecBuilderImpl implements LayeredMappingSpecBuilder {
|
||||
@@ -58,8 +59,10 @@ public class LayeredMappingSpecBuilderImpl implements LayeredMappingSpecBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public LayeredMappingSpecBuilder officialMojangMappings() {
|
||||
layers.add(new MojangMappingsSpec(() -> extension != null && extension.isSilentMojangMappingsLicenseEnabled()));
|
||||
public LayeredMappingSpecBuilder officialMojangMappings(Action<MojangMappingsSpecBuilder> action) {
|
||||
MojangMappingsSpecBuilderImpl builder = MojangMappingsSpecBuilderImpl.builder();
|
||||
action.execute(builder);
|
||||
layers.add(builder.build(() -> extension != null && extension.isSilentMojangMappingsLicenseEnabled()));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ import org.apache.tools.ant.util.StringUtils;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.LoomGradlePlugin;
|
||||
@@ -439,6 +440,20 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
|
||||
getProject().getDependencies().add(Constants.Configurations.UNPICK_CLASSPATH,
|
||||
String.format("%s:%s:%s", unpickMetadata.unpickGroup, unpickCliName, unpickMetadata.unpickVersion)
|
||||
);
|
||||
|
||||
// Unpick ships with a slightly older version of asm, ensure it runs with at least the same version as loom.
|
||||
String[] asmDeps = new String[] {
|
||||
"org.ow2.asm:asm:%s",
|
||||
"org.ow2.asm:asm-tree:%s",
|
||||
"org.ow2.asm:asm-commons:%s",
|
||||
"org.ow2.asm:asm-util:%s"
|
||||
};
|
||||
|
||||
for (String asm : asmDeps) {
|
||||
getProject().getDependencies().add(Constants.Configurations.UNPICK_CLASSPATH,
|
||||
asm.formatted(Opcodes.class.getPackage().getImplementationVersion())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void mergeAndSaveMappings(Project project, Path from, Path out) throws IOException {
|
||||
|
||||
@@ -31,13 +31,15 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.gradle.api.logging.Logger;
|
||||
|
||||
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.configuration.providers.mappings.utils.DstNameFilterMappingVisitor;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftVersionMeta;
|
||||
import net.fabricmc.loom.util.HashedDownloadUtil;
|
||||
import net.fabricmc.mappingio.MappingVisitor;
|
||||
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch;
|
||||
@@ -46,9 +48,10 @@ import net.fabricmc.mappingio.format.ProGuardReader;
|
||||
public record MojangMappingLayer(String minecraftVersion,
|
||||
MinecraftVersionMeta.Download clientDownload,
|
||||
MinecraftVersionMeta.Download serverDownload,
|
||||
Path workingDir,
|
||||
Path workingDir, boolean nameSyntheticMembers,
|
||||
Logger logger,
|
||||
MojangMappingsSpec.SilenceLicenseOption silenceLicense) implements MappingLayer {
|
||||
private static final Pattern SYNTHETIC_NAME_PATTERN = Pattern.compile("^(access|this|val\\$this|lambda\\$.*)\\$[0-9]+$");
|
||||
@Override
|
||||
public void visit(MappingVisitor mappingVisitor) throws IOException {
|
||||
Path clientMappings = workingDir().resolve("%s.client.txt".formatted(minecraftVersion));
|
||||
@@ -60,8 +63,11 @@ public record MojangMappingLayer(String minecraftVersion,
|
||||
printMappingsLicense(clientMappings);
|
||||
}
|
||||
|
||||
// Filter out field names matching the pattern
|
||||
DstNameFilterMappingVisitor nameFilter = new DstNameFilterMappingVisitor(mappingVisitor, SYNTHETIC_NAME_PATTERN);
|
||||
|
||||
// Make official the source namespace
|
||||
MappingSourceNsSwitch nsSwitch = new MappingSourceNsSwitch(mappingVisitor, MappingsNamespace.OFFICIAL.toString());
|
||||
MappingSourceNsSwitch nsSwitch = new MappingSourceNsSwitch(nameSyntheticMembers() ? mappingVisitor : nameFilter, MappingsNamespace.OFFICIAL.toString());
|
||||
|
||||
try (BufferedReader clientBufferedReader = Files.newBufferedReader(clientMappings, StandardCharsets.UTF_8);
|
||||
BufferedReader serverBufferedReader = Files.newBufferedReader(serverMappings, StandardCharsets.UTF_8)) {
|
||||
|
||||
@@ -28,7 +28,7 @@ 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(SilenceLicenseOption silenceLicense) implements MappingsSpec<MojangMappingLayer> {
|
||||
public record MojangMappingsSpec(SilenceLicenseOption silenceLicense, boolean nameSyntheticMembers) implements MappingsSpec<MojangMappingLayer> {
|
||||
// Keys in dependency manifest
|
||||
private static final String MANIFEST_CLIENT_MAPPINGS = "client_mappings";
|
||||
private static final String MANIFEST_SERVER_MAPPINGS = "server_mappings";
|
||||
@@ -82,6 +82,7 @@ public record MojangMappingsSpec(SilenceLicenseOption silenceLicense) implements
|
||||
versionInfo.download(MANIFEST_CLIENT_MAPPINGS),
|
||||
versionInfo.download(MANIFEST_SERVER_MAPPINGS),
|
||||
context.workingDirectory("mojang"),
|
||||
nameSyntheticMembers(),
|
||||
context.getLogger(),
|
||||
silenceLicense()
|
||||
);
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.mojmap;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.spec.MojangMappingsSpecBuilder;
|
||||
|
||||
public class MojangMappingsSpecBuilderImpl implements MojangMappingsSpecBuilder {
|
||||
// TODO 0.11 loom change default to false
|
||||
private boolean nameSyntheticMembers = true;
|
||||
|
||||
private MojangMappingsSpecBuilderImpl() {
|
||||
}
|
||||
|
||||
public static MojangMappingsSpecBuilderImpl builder() {
|
||||
return new MojangMappingsSpecBuilderImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MojangMappingsSpecBuilder setNameSyntheticMembers(boolean value) {
|
||||
nameSyntheticMembers = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getNameSyntheticMembers() {
|
||||
return nameSyntheticMembers;
|
||||
}
|
||||
|
||||
public MojangMappingsSpec build() {
|
||||
return new MojangMappingsSpec(nameSyntheticMembers);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.fabricmc.mappingio.MappedElementKind;
|
||||
import net.fabricmc.mappingio.MappingVisitor;
|
||||
import net.fabricmc.mappingio.adapter.ForwardingMappingVisitor;
|
||||
|
||||
/**
|
||||
* Filters out method and field names based on the provided regex pattern.
|
||||
*/
|
||||
public class DstNameFilterMappingVisitor extends ForwardingMappingVisitor {
|
||||
private final Pattern pattern;
|
||||
|
||||
public DstNameFilterMappingVisitor(MappingVisitor next, Pattern pattern) {
|
||||
super(next);
|
||||
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDstName(MappedElementKind targetKind, int namespace, String name) throws IOException {
|
||||
if ((targetKind == MappedElementKind.FIELD || targetKind == MappedElementKind.METHOD) && pattern.matcher(name).matches()) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.visitDstName(targetKind, namespace, name);
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import net.fabricmc.loom.configuration.RemappedConfigurationEntry;
|
||||
import net.fabricmc.loom.configuration.RemappedConfigurationEntry.PublishingMode;
|
||||
|
||||
public class Constants {
|
||||
public static final String PLUGIN_ID = "dev.architectury.loom";
|
||||
@@ -45,13 +46,13 @@ public class Constants {
|
||||
public static final int ASM_VERSION = Opcodes.ASM9;
|
||||
|
||||
public static final List<RemappedConfigurationEntry> MOD_COMPILE_ENTRIES = ImmutableList.of(
|
||||
new RemappedConfigurationEntry("modApi", JavaPlugin.API_CONFIGURATION_NAME, true, true, JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME),
|
||||
new RemappedConfigurationEntry("modImplementation", JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, true, true, JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME),
|
||||
new RemappedConfigurationEntry("modRuntime", JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME, false, true, "", "modRuntimeOnly"),
|
||||
new RemappedConfigurationEntry("modCompileOnly", JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, true, false, ""),
|
||||
new RemappedConfigurationEntry("modCompileOnlyApi", JavaPlugin.COMPILE_ONLY_API_CONFIGURATION_NAME, true, false, JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME),
|
||||
new RemappedConfigurationEntry("modRuntimeOnly", JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME, false, true, JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME),
|
||||
new RemappedConfigurationEntry("modLocalRuntime", Configurations.LOCAL_RUNTIME, false, true, "")
|
||||
new RemappedConfigurationEntry("modApi", JavaPlugin.API_CONFIGURATION_NAME, true, true, PublishingMode.COMPILE_AND_RUNTIME),
|
||||
new RemappedConfigurationEntry("modImplementation", JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, true, true, PublishingMode.RUNTIME_ONLY),
|
||||
new RemappedConfigurationEntry("modRuntime", JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME, false, true, PublishingMode.NONE, "modRuntimeOnly"),
|
||||
new RemappedConfigurationEntry("modCompileOnly", JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, true, false, PublishingMode.NONE),
|
||||
new RemappedConfigurationEntry("modCompileOnlyApi", JavaPlugin.COMPILE_ONLY_API_CONFIGURATION_NAME, true, false, PublishingMode.COMPILE_ONLY),
|
||||
new RemappedConfigurationEntry("modRuntimeOnly", JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME, false, true, PublishingMode.RUNTIME_ONLY),
|
||||
new RemappedConfigurationEntry("modLocalRuntime", Configurations.LOCAL_RUNTIME, false, true, PublishingMode.NONE)
|
||||
);
|
||||
|
||||
private Constants() {
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.gradle.util.GradleVersion
|
||||
|
||||
class LoomTestConstants {
|
||||
public final static String DEFAULT_GRADLE = GradleVersion.current().getVersion()
|
||||
public final static String PRE_RELEASE_GRADLE = "7.4-20211110232442+0000"
|
||||
public final static String PRE_RELEASE_GRADLE = "7.4-20211124232407+0000"
|
||||
|
||||
public final static String[] STANDARD_TEST_VERSIONS = [DEFAULT_GRADLE, PRE_RELEASE_GRADLE]
|
||||
}
|
||||
|
||||
@@ -43,10 +43,10 @@ class FabricAPITest extends Specification implements GradleProjectTestTrait {
|
||||
def "build and run (gradle #version)"() {
|
||||
setup:
|
||||
def gradle = gradleProject(
|
||||
repo: "https://github.com/modmuss50/fabric.git",
|
||||
commit: "e954edb6069e36139fd70428cfe4cddb5826c498",
|
||||
repo: "https://github.com/FabricMC/fabric.git",
|
||||
commit: "ce6198f63bbe0e17ba631420e9186fb72cc8b2af",
|
||||
version: version,
|
||||
// patch: "fabric_api"
|
||||
patch: "fabric_api"
|
||||
)
|
||||
|
||||
// Set the version to something constant
|
||||
@@ -64,8 +64,11 @@ class FabricAPITest extends Specification implements GradleProjectTestTrait {
|
||||
then:
|
||||
result.task(":build").outcome == SUCCESS
|
||||
|
||||
new File(gradle.mavenLocalDir, "net/fabricmc/fabric-api/fabric-biome-api-v1/3.2.2/fabric-biome-api-v1-3.2.2.jar").exists()
|
||||
new File(gradle.mavenLocalDir, "net/fabricmc/fabric-api/fabric-biome-api-v1/3.2.2/fabric-biome-api-v1-3.2.2-sources.jar").exists()
|
||||
|
||||
serverResult.successful()
|
||||
serverResult.output.contains("fabric@$API_VERSION")
|
||||
serverResult.output.contains("- fabric $API_VERSION")
|
||||
where:
|
||||
version << STANDARD_TEST_VERSIONS
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ class MavenProjectTest extends Specification implements MockMavenServerTrait, Gr
|
||||
then:
|
||||
result.task(":publish").outcome == SUCCESS
|
||||
gradle.hasOutputZipEntry("fabric-example-lib-${version}.jar", "net/fabricmc/example/ExampleLib.class")
|
||||
gradle.hasOutputZipEntry("fabric-example-lib-${version}-sources.jar", "net/fabricmc/example/ExampleLib.java")
|
||||
|
||||
where:
|
||||
version | gradleVersion
|
||||
|
||||
@@ -48,4 +48,30 @@ class MojangMappingsProjectTest extends Specification implements GradleProjectTe
|
||||
where:
|
||||
version << STANDARD_TEST_VERSIONS
|
||||
}
|
||||
|
||||
@Unroll
|
||||
def "mojang mappings without synthetic field names (gradle #version)"() {
|
||||
setup:
|
||||
def gradle = gradleProject(project: "minimalBase", version: version)
|
||||
|
||||
gradle.buildGradle << '''
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:1.18-pre5"
|
||||
mappings loom.layered {
|
||||
officialMojangMappings {
|
||||
nameSyntheticMembers = false
|
||||
}
|
||||
}
|
||||
}
|
||||
'''
|
||||
|
||||
when:
|
||||
def result = gradle.run(task: "build")
|
||||
|
||||
then:
|
||||
result.task(":build").outcome == SUCCESS
|
||||
|
||||
where:
|
||||
version << STANDARD_TEST_VERSIONS
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class LayeredMappingSpecBuilderTest extends LayeredMappingsSpecification {
|
||||
}
|
||||
def layers = spec.layers()
|
||||
then:
|
||||
spec.getVersion() == "layered+hash.2198"
|
||||
spec.version == "layered+hash.2192"
|
||||
layers.size() == 2
|
||||
layers[0].class == IntermediaryMappingsSpec
|
||||
layers[1].class == MojangMappingsSpec
|
||||
@@ -56,7 +56,7 @@ class LayeredMappingSpecBuilderTest extends LayeredMappingsSpecification {
|
||||
def layers = spec.layers()
|
||||
def parchment = layers[2] as ParchmentMappingsSpec
|
||||
then:
|
||||
spec.getVersion() == "layered+hash.863752751"
|
||||
spec.version == "layered+hash.863752565"
|
||||
layers.size() == 3
|
||||
layers[0].class == IntermediaryMappingsSpec
|
||||
layers[1].class == MojangMappingsSpec
|
||||
@@ -76,7 +76,7 @@ class LayeredMappingSpecBuilderTest extends LayeredMappingsSpecification {
|
||||
def layers = spec.layers()
|
||||
def parchment = layers[2] as ParchmentMappingsSpec
|
||||
then:
|
||||
spec.getVersion() == "layered+hash.863752757"
|
||||
spec.version == "layered+hash.863752571"
|
||||
layers.size() == 3
|
||||
layers[0].class == IntermediaryMappingsSpec
|
||||
layers[1].class == MojangMappingsSpec
|
||||
@@ -96,7 +96,7 @@ class LayeredMappingSpecBuilderTest extends LayeredMappingsSpecification {
|
||||
def layers = spec.layers()
|
||||
def parchment = layers[2] as ParchmentMappingsSpec
|
||||
then:
|
||||
spec.getVersion() == "layered+hash.1144427140"
|
||||
spec.version == "layered+hash.1144427326"
|
||||
layers.size() == 3
|
||||
layers[0].class == IntermediaryMappingsSpec
|
||||
layers[1].class == MojangMappingsSpec
|
||||
|
||||
@@ -25,17 +25,17 @@
|
||||
package net.fabricmc.loom.test.unit.layeredmappings
|
||||
|
||||
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.mojmap.MojangMappingsSpecBuilderImpl
|
||||
|
||||
class MojangMappingLayerTest extends LayeredMappingsSpecification {
|
||||
def "Read mojang mappings" () {
|
||||
def "Read mojang mappings with synthetic field names" () {
|
||||
setup:
|
||||
mockMappingsProvider.intermediaryTinyFile() >> extractFileFromZip(downloadFile(INTERMEDIARY_1_17_URL, "intermediary.jar"), "mappings/mappings.tiny")
|
||||
mockMinecraftProvider.getVersionInfo() >> VERSION_META_1_17
|
||||
when:
|
||||
def mappings = getLayeredMappings(
|
||||
new IntermediaryMappingsSpec(),
|
||||
new MojangMappingsSpec()
|
||||
buildMojangMappingsSpec(true)
|
||||
)
|
||||
def tiny = getTiny(mappings)
|
||||
then:
|
||||
@@ -45,5 +45,32 @@ class MojangMappingLayerTest extends LayeredMappingsSpecification {
|
||||
mappings.classes[0].srcName.hashCode() == 1869546970 // MojMap name, just check the hash
|
||||
mappings.classes[0].getDstName(0) == "net/minecraft/class_2354"
|
||||
mappings.classes[0].methods[0].args.size() == 0 // No Args
|
||||
tiny.contains('this$0')
|
||||
}
|
||||
|
||||
def "Read mojang mappings without synthetic field names" () {
|
||||
setup:
|
||||
mockMappingsProvider.intermediaryTinyFile() >> extractFileFromZip(downloadFile(INTERMEDIARY_1_17_URL, "intermediary.jar"), "mappings/mappings.tiny")
|
||||
mockMinecraftProvider.getVersionInfo() >> VERSION_META_1_17
|
||||
when:
|
||||
def mappings = getLayeredMappings(
|
||||
new IntermediaryMappingsSpec(),
|
||||
buildMojangMappingsSpec(false)
|
||||
)
|
||||
def tiny = getTiny(mappings)
|
||||
then:
|
||||
mappings.srcNamespace == "named"
|
||||
mappings.dstNamespaces == ["intermediary", "official"]
|
||||
mappings.classes.size() == 6113
|
||||
mappings.classes[0].srcName.hashCode() == 1869546970 // MojMap name, just check the hash
|
||||
mappings.classes[0].getDstName(0) == "net/minecraft/class_2354"
|
||||
mappings.classes[0].methods[0].args.size() == 0 // No Args
|
||||
!tiny.contains('this$0')
|
||||
}
|
||||
|
||||
static def buildMojangMappingsSpec(boolean nameSyntheticFields) {
|
||||
def builder = MojangMappingsSpecBuilderImpl.builder()
|
||||
builder.setNameSyntheticMembers(nameSyntheticFields)
|
||||
return builder.build()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class ParchmentMappingLayerTest extends LayeredMappingsSpecification {
|
||||
withMavenFile(PARCHMENT_NOTATION, downloadFile(PARCHMENT_URL, "parchment.zip"))
|
||||
def mappings = getLayeredMappings(
|
||||
new IntermediaryMappingsSpec(),
|
||||
new MojangMappingsSpec(),
|
||||
new MojangMappingsSpec(true),
|
||||
new ParchmentMappingsSpec(FileSpec.create(PARCHMENT_NOTATION), false)
|
||||
)
|
||||
def tiny = getTiny(mappings)
|
||||
@@ -61,7 +61,7 @@ class ParchmentMappingLayerTest extends LayeredMappingsSpecification {
|
||||
withMavenFile(PARCHMENT_NOTATION, downloadFile(PARCHMENT_URL, "parchment.zip"))
|
||||
def mappings = getLayeredMappings(
|
||||
new IntermediaryMappingsSpec(),
|
||||
new MojangMappingsSpec(),
|
||||
new MojangMappingsSpec(true),
|
||||
new ParchmentMappingsSpec(FileSpec.create(PARCHMENT_NOTATION), true)
|
||||
)
|
||||
def tiny = getTiny(mappings)
|
||||
|
||||
@@ -138,7 +138,7 @@ trait GradleProjectTestTrait {
|
||||
// And override the CI check to ensure that everything is ran
|
||||
System.setProperty("fabric.loom.test", "true")
|
||||
System.setProperty("fabric.loom.ci", "false")
|
||||
System.setProperty("maven.repo.local", new File(getGradleHomeDir(), "m2").absolutePath)
|
||||
System.setProperty("maven.repo.local", mavenLocalDir.absolutePath)
|
||||
|
||||
def runner = this.runner
|
||||
def args = []
|
||||
@@ -180,6 +180,10 @@ trait GradleProjectTestTrait {
|
||||
return new File(getProjectDir(), "build/libs/$filename")
|
||||
}
|
||||
|
||||
File getMavenLocalDir() {
|
||||
return new File(gradleHomeDir, "m2")
|
||||
}
|
||||
|
||||
void printOutputFiles() {
|
||||
new File(getProjectDir(), "build/libs/").listFiles().each {
|
||||
println(it.name)
|
||||
|
||||
@@ -29,7 +29,7 @@ import groovy.transform.Immutable
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class ServerRunner {
|
||||
static final String LOADER_VERSION = "0.11.6"
|
||||
static final String LOADER_VERSION = "0.12.5"
|
||||
static final Map<String, String> FABRIC_API_URLS = [
|
||||
"1.16.5": "https://github.com/FabricMC/fabric/releases/download/0.37.1%2B1.16/fabric-api-0.37.1+1.16.jar",
|
||||
"1.17.1": "https://github.com/FabricMC/fabric/releases/download/0.37.1%2B1.17/fabric-api-0.37.1+1.17.jar"
|
||||
|
||||
62
src/test/resources/patches/fabric_api.patch
Normal file
62
src/test/resources/patches/fabric_api.patch
Normal file
@@ -0,0 +1,62 @@
|
||||
diff --git a/build.gradle b/build.gradle
|
||||
--- a/build.gradle (revision ce6198f63bbe0e17ba631420e9186fb72cc8b2af)
|
||||
+++ b/build.gradle (date 1637848132986)
|
||||
@@ -31,17 +31,7 @@
|
||||
throw new NullPointerException("Could not find version for " + project.name)
|
||||
}
|
||||
|
||||
- if (grgit == null) {
|
||||
- return version + "+nogit"
|
||||
- }
|
||||
-
|
||||
- def latestCommits = grgit.log(paths: [project.name], maxCommits: 1)
|
||||
-
|
||||
- if (latestCommits.isEmpty()) {
|
||||
- return version + "+uncommited"
|
||||
- }
|
||||
-
|
||||
- return version + "+" + latestCommits.get(0).id.substring(0, 8) + DigestUtils.sha256Hex(project.rootProject.minecraft_version).substring(0, 2)
|
||||
+ return version
|
||||
}
|
||||
|
||||
def getBranch() {
|
||||
@@ -132,9 +122,8 @@
|
||||
include "**/*.java"
|
||||
}
|
||||
|
||||
- task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
- archiveClassifier = "sources"
|
||||
- from sourceSets.main.allSource
|
||||
+ java {
|
||||
+ withSourcesJar()
|
||||
}
|
||||
|
||||
checkstyle {
|
||||
@@ -229,12 +218,16 @@
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
from components.java
|
||||
+
|
||||
+ artifact javadocJar
|
||||
}
|
||||
}
|
||||
|
||||
setupRepositories(repositories)
|
||||
}
|
||||
|
||||
+ loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)
|
||||
+
|
||||
javadoc.enabled = false
|
||||
|
||||
afterEvaluate {
|
||||
@@ -242,10 +235,6 @@
|
||||
genSourcesWithFernFlower.enabled = false
|
||||
genSourcesWithCfr.enabled = false
|
||||
unpickJar.enabled = false
|
||||
-
|
||||
- // Work around a loom bug causing empty jars to be pushed to maven local.
|
||||
- publishMavenJavaPublicationToMavenLocal.dependsOn rootProject.tasks.getByName("remapAllJars")
|
||||
- publishMavenJavaPublicationToMavenLocal.dependsOn rootProject.tasks.getByName("remapAllSources")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user