Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure classpath groups for test task. #1227

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/test.libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -128,6 +131,7 @@ public void run() {
}

configureDecompileTasks(configContext);
configureTestTask();
});

finalizedBy("eclipse", "genEclipseRuns");
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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"))

Expand All @@ -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"
}
Expand Down
26 changes: 23 additions & 3 deletions src/test/resources/patches/fabric_api.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
diff --git a/build.gradle b/build.gradle
--- a/build.gradle (revision 41bc64cd617f03d49ecc4a4f7788cb65d465415c)
+++ b/build.gradle (date 1718312645477)
--- a/build.gradle (revision 70277babddfaf52ee30013af94764da19473b3b1)
+++ b/build.gradle (date 1732875235843)
@@ -13,7 +13,7 @@

def ENV = System.getenv()
Expand Down Expand Up @@ -34,5 +34,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 {