From fc44d8e3baaa5ef5c794a99716f35b2f5db579e5 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Fri, 29 Nov 2024 10:12:05 +0000 Subject: [PATCH 1/3] Configure classpath groups for test task. Closes #1192 --- .../configuration/CompileConfiguration.java | 24 +++++++++++++ .../test/integration/FabricAPITest.groovy | 4 +-- src/test/resources/patches/fabric_api.patch | 35 ++++++++++++------- 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java index eea3de0bd..93c34b56a 100644 --- a/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java +++ b/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java @@ -26,6 +26,7 @@ import static net.fabricmc.loom.util.Constants.Configurations; +import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; @@ -34,6 +35,7 @@ import java.time.Duration; import java.util.Optional; import java.util.function.Consumer; +import java.util.stream.Collectors; import javax.inject.Inject; @@ -47,6 +49,7 @@ import org.gradle.api.tasks.TaskContainer; import org.gradle.api.tasks.compile.JavaCompile; import org.gradle.api.tasks.javadoc.Javadoc; +import org.gradle.api.tasks.testing.Test; import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.api.InterfaceInjectionExtensionAPI; @@ -128,6 +131,7 @@ public void run() { } configureDecompileTasks(configContext); + configureTestTask(); }); finalizedBy("eclipse", "genEclipseRuns"); @@ -244,6 +248,26 @@ private void configureDecompileTasks(ConfigContext configContext) { .afterEvaluation(); } + private void configureTestTask() { + final LoomGradleExtension extension = LoomGradleExtension.get(getProject()); + + if (extension.getMods().isEmpty()) { + return; + } + + getProject().getTasks().named(JavaPlugin.TEST_TASK_NAME, Test.class, test -> { + String classPathGroups = extension.getMods().stream() + .map(modSettings -> + SourceSetHelper.getClasspath(modSettings, getProject()).stream() + .map(File::getAbsolutePath) + .collect(Collectors.joining(File.pathSeparator)) + ) + .collect(Collectors.joining(File.pathSeparator+File.pathSeparator));; + + test.systemProperty("fabric.classPathGroups", classPathGroups); + }); + } + private LockFile getLockFile() { final LoomGradleExtension extension = LoomGradleExtension.get(getProject()); final Path cacheDirectory = extension.getFiles().getUserCache().toPath(); diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/FabricAPITest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/FabricAPITest.groovy index 76186f0c1..3ddf503ab 100644 --- a/src/test/groovy/net/fabricmc/loom/test/integration/FabricAPITest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/integration/FabricAPITest.groovy @@ -44,7 +44,7 @@ class FabricAPITest extends Specification implements GradleProjectTestTrait { setup: def gradle = gradleProject( repo: "https://github.com/FabricMC/fabric.git", - commit: "41bc64cd617f03d49ecc4a4f7788cb65d465415c", + commit: "70277babddfaf52ee30013af94764da19473b3b1", version: version, patch: "fabric_api" ) @@ -58,7 +58,7 @@ class FabricAPITest extends Specification implements GradleProjectTestTrait { """.stripIndent() } - def minecraftVersion = "1.21" + def minecraftVersion = "1.21.4-pre3" def server = ServerRunner.create(gradle.projectDir, minecraftVersion) .withMod(gradle.getOutputFile("fabric-api-999.0.0.jar")) diff --git a/src/test/resources/patches/fabric_api.patch b/src/test/resources/patches/fabric_api.patch index 5e8c24763..c51f6f161 100644 --- a/src/test/resources/patches/fabric_api.patch +++ b/src/test/resources/patches/fabric_api.patch @@ -1,15 +1,6 @@ diff --git a/build.gradle b/build.gradle ---- a/build.gradle (revision 41bc64cd617f03d49ecc4a4f7788cb65d465415c) -+++ b/build.gradle (date 1718312645477) -@@ -13,7 +13,7 @@ - - def ENV = System.getenv() - --version = project.version + "+" + (ENV.GITHUB_RUN_NUMBER ? "" : "local-") + getBranch() -+version = "999.0.0" - logger.lifecycle("Building Fabric: " + version) - - def metaProjects = [ +--- a/build.gradle (revision 70277babddfaf52ee30013af94764da19473b3b1) ++++ b/build.gradle (date 1732874605816) @@ -34,24 +34,7 @@ import org.apache.commons.codec.digest.DigestUtils @@ -34,5 +25,25 @@ diff --git a/build.gradle b/build.gradle - return version + "+" + latestCommits.get(0).id.substring(0, 8) + DigestUtils.sha256Hex(project.rootProject.minecraft_version).substring(0, 2) + return "999.0.0" } - + def getBranch() { +@@ -247,19 +230,6 @@ + + test { + useJUnitPlatform() +- +- afterEvaluate { +- // See: https://github.com/FabricMC/fabric-loader/pull/585 +- def classPathGroups = loom.mods.stream() +- .map { modSettings -> +- SourceSetHelper.getClasspath(modSettings, getProject()).stream() +- .map(File.&getAbsolutePath) +- .collect(Collectors.joining(File.pathSeparator)) +- } +- .collect(Collectors.joining(File.pathSeparator+File.pathSeparator)) +- +- systemProperty("fabric.classPathGroups", classPathGroups) +- } + } + + tasks.withType(ProcessResources).configureEach { From dd22172983a2ad7fb3ce6adff6f158140011bfa7 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Fri, 29 Nov 2024 10:14:22 +0000 Subject: [PATCH 2/3] Fix missing patch --- src/test/resources/patches/fabric_api.patch | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/test/resources/patches/fabric_api.patch b/src/test/resources/patches/fabric_api.patch index c51f6f161..b2b777754 100644 --- a/src/test/resources/patches/fabric_api.patch +++ b/src/test/resources/patches/fabric_api.patch @@ -1,6 +1,15 @@ diff --git a/build.gradle b/build.gradle --- a/build.gradle (revision 70277babddfaf52ee30013af94764da19473b3b1) -+++ b/build.gradle (date 1732874605816) ++++ b/build.gradle (date 1732875235843) +@@ -13,7 +13,7 @@ + + def ENV = System.getenv() + +-version = project.version + "+" + (ENV.GITHUB_RUN_NUMBER ? "" : "local-") + getBranch() ++version = "999.0.0" + logger.lifecycle("Building Fabric: " + version) + + def metaProjects = [ @@ -34,24 +34,7 @@ import org.apache.commons.codec.digest.DigestUtils From eec9c1028fc7766075224869b98dde7d954bdb09 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Fri, 29 Nov 2024 12:51:58 +0000 Subject: [PATCH 3/3] Fix test --- gradle/test.libs.versions.toml | 2 +- .../net/fabricmc/loom/test/integration/FabricAPITest.groovy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/test.libs.versions.toml b/gradle/test.libs.versions.toml index 0f8f4950d..4bc6312a1 100644 --- a/gradle/test.libs.versions.toml +++ b/gradle/test.libs.versions.toml @@ -7,7 +7,7 @@ java-debug = "0.52.0" mixin = "0.15.3+mixin.0.8.7" gradle-nightly = "8.12-20241110002642+0000" -fabric-loader = "0.16.5" +fabric-loader = "0.16.9" fabric-installer = "1.0.1" [libraries] diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/FabricAPITest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/FabricAPITest.groovy index 3ddf503ab..53547032a 100644 --- a/src/test/groovy/net/fabricmc/loom/test/integration/FabricAPITest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/integration/FabricAPITest.groovy @@ -75,7 +75,7 @@ class FabricAPITest extends Specification implements GradleProjectTestTrait { dependencies { minecraft "com.mojang:minecraft:${minecraftVersion}" - mappings "net.fabricmc:yarn:${minecraftVersion}+build.1:v2" + mappings "net.fabricmc:yarn:${minecraftVersion}+build.2:v2" modImplementation "net.fabricmc.fabric-api:fabric-api:999.0.0" }