mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-27 19:57:00 -05:00
Validate jar and fail if it was built with Loom 1.5 or later.
This commit is contained in:
@@ -88,6 +88,12 @@ public class ModConfigurationRemapper {
|
||||
final List<ModDependency> modDependencies = new ArrayList<>();
|
||||
|
||||
for (ArtifactRef artifact : resolveArtifacts(project, sourceConfig)) {
|
||||
try {
|
||||
ModUtils.validateJarManifest(artifact.path());
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to read manifest from" + artifact.path(), e);
|
||||
}
|
||||
|
||||
if (!ModUtils.shouldRemapMod(project.getLogger(), artifact.path(), extension.getPlatform().get(), sourceConfig.getName())) {
|
||||
artifact.applyToConfiguration(project, targetConfig);
|
||||
continue;
|
||||
|
||||
@@ -24,10 +24,14 @@
|
||||
|
||||
package net.fabricmc.loom.util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.gradle.api.logging.Logger;
|
||||
@@ -71,4 +75,21 @@ public final class ModUtils {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void validateJarManifest(Path path) throws IOException {
|
||||
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(path)) {
|
||||
final Path manifestPath = fs.get().getPath("META-INF/MANIFEST.MF");
|
||||
|
||||
if (Files.exists(manifestPath)) {
|
||||
final var manifest = new Manifest(new ByteArrayInputStream(Files.readAllBytes(manifestPath)));
|
||||
final Attributes mainAttributes = manifest.getMainAttributes();
|
||||
|
||||
// Check to see if the jar was built with a newer version of loom.
|
||||
// This version of loom does not support the remap type value so throw an exception.
|
||||
if (mainAttributes.getValue("Fabric-Loom-Mixin-Remap-Type") != null) {
|
||||
throw new IllegalStateException("This version of loom does not support the mixin remap type value. Please update to the latest version of loom.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user