Update mapping namespace manifest entry when remapping mod dependencies.

This commit is contained in:
modmuss50
2022-04-16 00:14:42 +01:00
parent 66ef9659a2
commit 463847184e
2 changed files with 20 additions and 2 deletions

View File

@@ -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();
}));
}
}

View File

@@ -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);