mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 05:05:20 -05:00
Support mixins without refmaps in mod dependencies (#976)
* Support mixins without refmaps in mod dependencies * Fix review concerns * Add test for MixinDetector * Change warning to a RuntimeException * FabricAPITest: Test building without mixin AP * Deal with Eclipse being stuck in the 2010s and not supporting basic Groovy syntax * Auto-fix Groovy code format * Fix FabricAPITest not running * Fix code style
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 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.mods;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
import net.fabricmc.loom.LoomGradlePlugin;
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
import net.fabricmc.loom.util.fmj.FabricModJson;
|
||||
import net.fabricmc.loom.util.fmj.FabricModJsonFactory;
|
||||
|
||||
public final class MixinDetector {
|
||||
public static boolean hasMixinsWithoutRefmap(Path modJar) throws IOException {
|
||||
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(modJar)) {
|
||||
final List<String> mixinConfigs = getMixinConfigs(modJar);
|
||||
|
||||
if (!mixinConfigs.isEmpty()) {
|
||||
for (String mixinConfig : mixinConfigs) {
|
||||
final Path configPath = fs.getPath(mixinConfig);
|
||||
if (Files.notExists(configPath)) continue;
|
||||
|
||||
try (BufferedReader reader = Files.newBufferedReader(configPath)) {
|
||||
final JsonObject json = LoomGradlePlugin.GSON.fromJson(reader, JsonObject.class);
|
||||
|
||||
if (!json.has("refmap")) {
|
||||
// We found a mixin config with no refmap, exit the loop.
|
||||
return true;
|
||||
}
|
||||
} catch (JsonParseException e) {
|
||||
throw new RuntimeException("Could not parse mixin config %s from jar %s".formatted(mixinConfig, modJar.toAbsolutePath()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> getMixinConfigs(Path modJar) {
|
||||
// Nullable because we don't care here if we can't read it.
|
||||
// We can just assume there are no mixins.
|
||||
final FabricModJson fabricModJson = FabricModJsonFactory.createFromZipNullable(modJar);
|
||||
return fabricModJson != null ? fabricModJson.getMixinConfigurations() : List.of();
|
||||
}
|
||||
}
|
||||
@@ -32,9 +32,11 @@ import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -61,6 +63,7 @@ import net.fabricmc.tinyremapper.InputTag;
|
||||
import net.fabricmc.tinyremapper.NonClassCopyMode;
|
||||
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
import net.fabricmc.tinyremapper.extension.mixin.MixinExtension;
|
||||
|
||||
public class ModProcessor {
|
||||
private static final String fromM = MappingsNamespace.INTERMEDIARY.toString();
|
||||
@@ -146,6 +149,10 @@ public class ModProcessor {
|
||||
builder.extension(kotlinRemapperClassloader.getTinyRemapperExtension());
|
||||
}
|
||||
|
||||
final Set<InputTag> hasMixinsWithoutRefmaps = new HashSet<>();
|
||||
// Configure the mixin extension to remap mixins from mod jars detected not to contain refmaps.
|
||||
builder.extension(new MixinExtension(hasMixinsWithoutRefmaps::contains));
|
||||
|
||||
final TinyRemapper remapper = builder.build();
|
||||
|
||||
for (Path minecraftJar : extension.getMinecraftJars(MappingsNamespace.INTERMEDIARY)) {
|
||||
@@ -173,6 +180,12 @@ public class ModProcessor {
|
||||
|
||||
project.getLogger().debug("Adding " + info.getInputFile() + " as a remap input");
|
||||
|
||||
// Note: this is done at a jar level, not at the level of an individual mixin config.
|
||||
// If a mod has multiple mixin configs, it's assumed that either all or none of them have refmaps.
|
||||
if (MixinDetector.hasMixinsWithoutRefmap(info.getInputFile())) {
|
||||
hasMixinsWithoutRefmaps.add(tag);
|
||||
}
|
||||
|
||||
remapper.readInputsAsync(tag, info.getInputFile());
|
||||
tagMap.put(info, tag);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user