-
Notifications
You must be signed in to change notification settings - Fork 237
Make fabric.mod.json path configurable at configuration stage.
#1364
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
Changes from 5 commits
1c86983
1159657
87cb7b7
4dceae8
5f92ab2
4f790ba
a932931
af18d97
23f97b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,39 +24,54 @@ | |
|
|
||
| package net.fabricmc.loom.util.fmj; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import net.fabricmc.loom.api.LoomGradleExtensionAPI; | ||
| import org.gradle.api.Project; | ||
| import org.gradle.api.tasks.SourceSet; | ||
|
|
||
| import net.fabricmc.loom.LoomGradleExtension; | ||
| import net.fabricmc.loom.util.gradle.SourceSetHelper; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| public class FabricModJsonHelpers { | ||
| // Returns a list of Mods found in the provided project's main or client sourcesets | ||
| /** | ||
| * Returns the list of mods provided by either {@link LoomGradleExtensionAPI#getFabricModJsonPath()} | ||
| * or {@code fabric.mod.json} in main or client resources. | ||
| */ | ||
| public static List<FabricModJson> getModsInProject(Project project) { | ||
| final LoomGradleExtension extension = LoomGradleExtension.get(project); | ||
| LoomGradleExtension extension = LoomGradleExtension.get(project); | ||
| var overrideFile = extension.getFabricModJsonPath().getAsFile(); | ||
kikugie marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| var sourceSets = new ArrayList<SourceSet>(); | ||
| sourceSets.add(SourceSetHelper.getMainSourceSet(project)); | ||
|
|
||
| sourceSets.add(SourceSetHelper.getMainSourceSet(project)); | ||
| if (extension.areEnvironmentSourceSetsSplit()) { | ||
kikugie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| sourceSets.add(SourceSetHelper.getSourceSetByName("client", project)); | ||
| } | ||
|
|
||
| try { | ||
| final FabricModJson fabricModJson = FabricModJsonFactory.createFromSourceSetsNullable(project, sourceSets.toArray(SourceSet[]::new)); | ||
| return getModsInProject(project, overrideFile.getOrNull(), sourceSets.toArray(SourceSet[]::new)); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the list of mods provided by either {@code overrideFile} property | ||
| * or {@code fabric.mod.json} in the {@code sourceSets} array. | ||
| */ | ||
| public static List<FabricModJson> getModsInProject(Project project, @Nullable File overrideFile, SourceSet... sourceSets) { | ||
kikugie marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try { | ||
| var fabricModJson = overrideFile != null | ||
| ? FabricModJsonFactory.createFromOverrideNullable(overrideFile) | ||
| : FabricModJsonFactory.createFromSourceSetsNullable(project, sourceSets); | ||
| if (fabricModJson != null) { | ||
| return List.of(fabricModJson); | ||
| } | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException(e); | ||
| } | ||
|
|
||
| return Collections.emptyList(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package net.fabricmc.loom.test.integration | ||
|
|
||
| import net.fabricmc.loom.test.util.GradleProjectTestTrait | ||
| import org.gradle.testkit.runner.BuildResult | ||
| import spock.lang.Specification | ||
| import spock.lang.Unroll | ||
|
|
||
| import static org.gradle.testkit.runner.TaskOutcome.SUCCESS | ||
|
|
||
| class FabricModJsonPathTest extends Specification implements GradleProjectTestTrait { | ||
| @Unroll | ||
| def "Resolve custom FMJ"() { | ||
| setup: | ||
| GradleProject gradle = gradleProject(project: "fmjPathConfig") | ||
|
|
||
| when: | ||
| BuildResult result = gradle.run(task: "build", args: ["-PoverrideFMJ=true"]) | ||
|
|
||
| then: | ||
| result.task(":build").outcome == SUCCESS | ||
| } | ||
|
|
||
| @Unroll | ||
| def "Fail to find FMJ"() { | ||
| setup: | ||
| GradleProject gradle = gradleProject(project: "fmjPathConfig") | ||
|
|
||
| when: | ||
| BuildResult result = gradle.run(task: "build", expectFailure: true) | ||
|
|
||
| then: | ||
| result.task(":build") == null | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // This is used by a range of tests that append to this file before running the gradle tasks. | ||
| // Can be used for tests that require minimal custom setup | ||
| plugins { | ||
| id 'fabric-loom' | ||
| id 'maven-publish' | ||
| } | ||
|
|
||
| version = "1.0.0" | ||
| group = "com.example" | ||
|
|
||
| // In multi-version setup this would be a separate project, | ||
| // but a source set will suffice for a test. | ||
| sourceSets { | ||
| custom { | ||
|
|
||
| } | ||
| main { | ||
| compileClasspath += sourceSets.custom.compileClasspath | ||
| runtimeClasspath += sourceSets.custom.runtimeClasspath | ||
| } | ||
| } | ||
|
|
||
|
|
||
| dependencies { | ||
| minecraft "com.mojang:minecraft:1.17.1" | ||
| mappings "net.fabricmc:yarn:1.17.1+build.59:v2" | ||
| modImplementation "net.fabricmc:fabric-loader:0.11.6" | ||
| } | ||
|
|
||
| base { | ||
| archivesName = "fabric-example-mod" | ||
| } | ||
|
|
||
| if (project.hasProperty("overrideFMJ")) { | ||
| loom { | ||
| fabricModJsonPath = file("src/custom/resources/fabric.mod.json") | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "schemaVersion": 1, | ||
| "id": "testmod", | ||
| "version": "1", | ||
| "name": "Test Mod", | ||
| "custom": { | ||
| "loom:injected_interfaces": { | ||
| "net/minecraft/class_310": ["InjectedInterface"] | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import net.minecraft.client.MinecraftClient; | ||
|
|
||
| import net.fabricmc.api.ModInitializer; | ||
|
|
||
| public class ExampleMod implements ModInitializer { | ||
| @Override | ||
| public void onInitialize() { | ||
| MinecraftClient.getInstance().newMethodThatDidNotExist(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| public interface InjectedInterface { | ||
| default void newMethodThatDidNotExist() { | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.