Skip to content

Commit

Permalink
Configure classpath groups for test task.
Browse files Browse the repository at this point in the history
Closes #1192
  • Loading branch information
modmuss50 committed Nov 29, 2024
1 parent 7cc7cb0 commit fc44d8e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
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 Down
35 changes: 23 additions & 12 deletions src/test/resources/patches/fabric_api.patch
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 {

0 comments on commit fc44d8e

Please sign in to comment.