mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 13:05:27 -05:00
Merge branch 'exp/0.12' into dev/0.12
This commit is contained in:
@@ -70,9 +70,7 @@ public interface LoomGradleExtensionAPI {
|
||||
|
||||
ConfigurableFileCollection getLog4jConfigs();
|
||||
|
||||
default Dependency officialMojangMappings() {
|
||||
return layered(LayeredMappingSpecBuilder::officialMojangMappings);
|
||||
}
|
||||
Dependency officialMojangMappings();
|
||||
|
||||
Dependency layered(Action<LayeredMappingSpecBuilder> action);
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
package net.fabricmc.loom.configuration.mods;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
@@ -33,6 +35,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.gradle.api.Project;
|
||||
@@ -47,6 +50,7 @@ import net.fabricmc.loom.configuration.RemappedConfigurationEntry;
|
||||
import net.fabricmc.loom.configuration.processors.dependency.ModDependencyInfo;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
|
||||
import net.fabricmc.loom.kotlin.remapping.KotlinMetadataTinyRemapperExtension;
|
||||
import net.fabricmc.loom.task.RemapJarTask;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.TinyRemapperHelper;
|
||||
import net.fabricmc.loom.util.ZipUtils;
|
||||
@@ -217,8 +221,21 @@ public class ModProcessor {
|
||||
}
|
||||
|
||||
stripNestedJars(info.getRemappedOutput());
|
||||
remapJarManifestEntries(info.getRemappedOutput().toPath());
|
||||
|
||||
info.finaliseRemapping();
|
||||
}
|
||||
}
|
||||
|
||||
private void remapJarManifestEntries(Path jar) throws IOException {
|
||||
ZipUtils.transform(jar, Map.of(RemapJarTask.MANIFEST_PATH, bytes -> {
|
||||
var manifest = new Manifest(new ByteArrayInputStream(bytes));
|
||||
|
||||
manifest.getMainAttributes().putValue(RemapJarTask.MANIFEST_NAMESPACE_KEY, toM);
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
manifest.write(out);
|
||||
return out.toByteArray();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,9 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
private final NamedDomainObjectContainer<DecompilerOptions> decompilers;
|
||||
private final NamedDomainObjectContainer<ModSettings> mods;
|
||||
|
||||
// A common mistake with layered mappings is to call the wrong `officialMojangMappings` method, use this to keep track of when we are building a layered mapping spec.
|
||||
protected final ThreadLocal<Boolean> layeredSpecBuilderScope = ThreadLocal.withInitial(() -> false);
|
||||
|
||||
protected LoomGradleExtensionApiImpl(Project project, LoomFiles directories) {
|
||||
this.jarProcessors = project.getObjects().listProperty(JarProcessor.class)
|
||||
.empty();
|
||||
@@ -165,10 +168,23 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
return jarProcessors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dependency officialMojangMappings() {
|
||||
if (layeredSpecBuilderScope.get()) {
|
||||
throw new IllegalStateException("Use `officialMojangMappings()` when configuring layered mappings, not the extension method `loom.officialMojangMappings()`");
|
||||
}
|
||||
|
||||
return layered(LayeredMappingSpecBuilder::officialMojangMappings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dependency layered(Action<LayeredMappingSpecBuilder> action) {
|
||||
LayeredMappingSpecBuilderImpl builder = new LayeredMappingSpecBuilderImpl();
|
||||
|
||||
layeredSpecBuilderScope.set(true);
|
||||
action.execute(builder);
|
||||
layeredSpecBuilderScope.set(false);
|
||||
|
||||
LayeredMappingSpec builtSpec = builder.build();
|
||||
return new LayeredMappingsDependency(getProject(), new GradleMappingContext(getProject(), builtSpec.getVersion().replace("+", "_").replace(".", "_")), builtSpec, builtSpec.getVersion());
|
||||
}
|
||||
|
||||
@@ -83,7 +83,8 @@ import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
|
||||
public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
private static final String MANIFEST_PATH = "META-INF/MANIFEST.MF";
|
||||
public static final String MANIFEST_PATH = "META-INF/MANIFEST.MF";
|
||||
public static final String MANIFEST_NAMESPACE_KEY = "Fabric-Mapping-Namespace";
|
||||
|
||||
@InputFiles
|
||||
public abstract ConfigurableFileCollection getNestedJars();
|
||||
@@ -306,7 +307,7 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
var manifest = new Manifest(new ByteArrayInputStream(bytes));
|
||||
|
||||
getParameters().getJarManifestService().get().apply(manifest, getParameters().getManifestAttributes().get());
|
||||
manifest.getMainAttributes().putValue("Fabric-Mapping-Namespace", getParameters().getTargetNamespace().get());
|
||||
manifest.getMainAttributes().putValue(MANIFEST_NAMESPACE_KEY, getParameters().getTargetNamespace().get());
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
manifest.write(out);
|
||||
|
||||
Reference in New Issue
Block a user