From b3eb5bc05cde42db238dc8d94fd79d2a6e6d988a Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Fri, 15 Nov 2024 16:46:43 +0200 Subject: [PATCH] Better logging --- .../net/neoforged/fml/loading/FMLConfig.java | 14 ++++++++++++-- .../net/neoforged/fml/loading/FMLLoaderTest.java | 16 +++++++++------- .../neoforged/fml/loading/ModFileBuilder.java | 4 ++++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/loader/src/main/java/net/neoforged/fml/loading/FMLConfig.java b/loader/src/main/java/net/neoforged/fml/loading/FMLConfig.java index 47307129f..772cd909c 100644 --- a/loader/src/main/java/net/neoforged/fml/loading/FMLConfig.java +++ b/loader/src/main/java/net/neoforged/fml/loading/FMLConfig.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.Objects; import java.util.function.Function; +import java.util.stream.Collectors; import org.slf4j.Logger; public class FMLConfig { @@ -146,12 +147,17 @@ public static void load() { } else { var removal = start == '-'; var depMod = str.substring(1); - LOGGER.warn("Found dependency override for mod '{}': {} '{}'", modId, removal ? "softening dependency constraints against" : "adding explicit AFTER ordering against", depMod); overrides.add(new DependencyOverride(depMod, removal)); } } }); } + + if (!DEPENDENCY_OVERRIDES.isEmpty()) { + LOGGER.warn("*".repeat(30) + " Found dependency overrides " + "*".repeat(30)); + DEPENDENCY_OVERRIDES.forEach((modId, ov) -> LOGGER.warn("Dependency overrides for mod '{}': {}", modId, ov.stream().map(DependencyOverride::getMessage).collect(Collectors.joining(", ")))); + LOGGER.warn("*".repeat(88)); + } } public static String getConfigValue(ConfigValue v) { @@ -191,5 +197,9 @@ public static Map> getDependencyOverrides() { return Collections.unmodifiableMap(DEPENDENCY_OVERRIDES); } - public record DependencyOverride(String modId, boolean remove) {} + public record DependencyOverride(String modId, boolean remove) { + public String getMessage() { + return (remove ? "softening dependency constraints against" : "adding explicit AFTER ordering against") + " '" + modId + "'"; + } + } } diff --git a/loader/src/test/java/net/neoforged/fml/loading/FMLLoaderTest.java b/loader/src/test/java/net/neoforged/fml/loading/FMLLoaderTest.java index 584c726f9..a050a11bf 100644 --- a/loader/src/test/java/net/neoforged/fml/loading/FMLLoaderTest.java +++ b/loader/src/test/java/net/neoforged/fml/loading/FMLLoaderTest.java @@ -398,12 +398,9 @@ void testUnsatisfiedNeoForgeRange() throws Exception { @Test void testDependencyOverride() throws Exception { installation.setupProductionClient(); - installation.appendToConfig("dependencyOverrides.targetmod = [\"-depmod\"]"); - installation.buildModJar("depmod.jar") - .withModsToml(builder -> { - builder.unlicensedJavaMod(); - builder.addMod("depmod", "1.0"); - }); + installation.appendToConfig("dependencyOverrides.targetmod = [\"-depmod\", \"-incompatiblemod\"]"); + installation.buildModJar("depmod.jar").withMod("depmod", "1.0"); + installation.buildModJar("incompatiblemod.jar").withMod("incompatiblemod", "1.0"); installation.buildModJar("targetmod.jar") .withModsToml(builder -> { builder.unlicensedJavaMod(); @@ -412,7 +409,12 @@ void testDependencyOverride() throws Exception { sub.set("modId", "depmod"); sub.set("versionRange", "[2,)"); sub.set("type", "required"); - c.set("dependencies.targetmod", new ArrayList<>(Arrays.asList(sub))); + + var sub2 = Config.inMemory(); + sub2.set("modId", "incompatiblemod"); + sub2.set("versionRange", "[1,"); + sub2.set("type", "incompatible"); + c.set("dependencies.targetmod", new ArrayList<>(Arrays.asList(sub, sub2))); }); }); assertThat(launchAndLoad("forgeclient").issues()).isEmpty(); diff --git a/loader/src/test/java/net/neoforged/fml/loading/ModFileBuilder.java b/loader/src/test/java/net/neoforged/fml/loading/ModFileBuilder.java index 3564e30e5..17342f932 100644 --- a/loader/src/test/java/net/neoforged/fml/loading/ModFileBuilder.java +++ b/loader/src/test/java/net/neoforged/fml/loading/ModFileBuilder.java @@ -64,6 +64,10 @@ public ModFileBuilder withTestmodModsToml(Consumer customizer) }); } + public ModFileBuilder withMod(String id, String version) { + return withModsToml(builder -> builder.unlicensedJavaMod().addMod(id, version)); + } + public ModFileBuilder withModTypeManifest(IModFile.Type type) { return withManifest(Map.of( "FMLModType", type.name()));