-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1c86983
Add `fabric.mod.json` path property.
kikugie 1159657
Add path provider integration tests.
kikugie 87cb7b7
Separate fabric.mod.json reading methods and move selection to the he…
kikugie 4dceae8
Separate FMJ getter methods and add configuration to datagen and test…
kikugie 5f92ab2
Remove the `fabricModJsonPath` property from Fabric API source sets
kikugie 4f790ba
Address review requests by fixing formatting and removing redundant c…
kikugie a932931
Fix build
modmuss50 af18d97
Move tests to existing file, and remove var usage.
modmuss50 23f97b1
Fix build :)
modmuss50 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,16 +25,15 @@ | |
| package net.fabricmc.loom.extension; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import org.gradle.api.Action; | ||
| import org.gradle.api.NamedDomainObjectContainer; | ||
| import org.gradle.api.NamedDomainObjectList; | ||
| import org.gradle.api.Project; | ||
| import org.gradle.api.UncheckedIOException; | ||
| import org.gradle.api.artifacts.Dependency; | ||
| import org.gradle.api.file.ConfigurableFileCollection; | ||
| import org.gradle.api.file.FileCollection; | ||
|
|
@@ -74,7 +73,7 @@ | |
| import net.fabricmc.loom.util.DeprecationHelper; | ||
| import net.fabricmc.loom.util.MirrorUtil; | ||
| import net.fabricmc.loom.util.fmj.FabricModJson; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Linters - my greatest nemesis |
||
| import net.fabricmc.loom.util.fmj.FabricModJsonFactory; | ||
| import net.fabricmc.loom.util.fmj.FabricModJsonHelpers; | ||
| import net.fabricmc.loom.util.gradle.SourceSetHelper; | ||
|
|
||
| /** | ||
|
|
@@ -86,6 +85,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA | |
| protected final ListProperty<JarProcessor> jarProcessors; | ||
| protected final ConfigurableFileCollection log4jConfigs; | ||
| protected final RegularFileProperty accessWidener; | ||
| protected final RegularFileProperty fabricModJsonPath; | ||
| protected final ManifestLocations versionsManifests; | ||
| protected final Property<String> customMetadata; | ||
| protected final SetProperty<String> knownIndyBsms; | ||
|
|
@@ -118,6 +118,7 @@ protected LoomGradleExtensionApiImpl(Project project, LoomFiles directories) { | |
| .empty(); | ||
| this.log4jConfigs = project.files(directories.getDefaultLog4jConfigFile()); | ||
| this.accessWidener = project.getObjects().fileProperty(); | ||
| this.fabricModJsonPath = project.getObjects().fileProperty(); | ||
| this.versionsManifests = new ManifestLocations(); | ||
| this.versionsManifests.add("mojang", MirrorUtil.getVersionManifests(project), -2); | ||
| this.versionsManifests.add("fabric_experimental", MirrorUtil.getExperimentalVersions(project), -1); | ||
|
|
@@ -205,6 +206,11 @@ public RegularFileProperty getAccessWidenerPath() { | |
| return accessWidener; | ||
| } | ||
|
|
||
| @Override | ||
| public RegularFileProperty getFabricModJsonPath() { | ||
| return fabricModJsonPath; | ||
| } | ||
|
|
||
| @Override | ||
| public NamedDomainObjectContainer<DecompilerOptions> getDecompilerOptions() { | ||
| return decompilers; | ||
|
|
@@ -293,17 +299,13 @@ public SetProperty<String> getKnownIndyBsms() { | |
|
|
||
| @Override | ||
| public String getModVersion() { | ||
| try { | ||
| final FabricModJson fabricModJson = FabricModJsonFactory.createFromSourceSetsNullable(getProject(), SourceSetHelper.getMainSourceSet(getProject())); | ||
| List<FabricModJson> fabricModJsons = FabricModJsonHelpers.getModsInProject(getProject()); | ||
|
|
||
| if (fabricModJson == null) { | ||
| throw new RuntimeException("Could not find a fabric.mod.json file in the main sourceset"); | ||
| } | ||
|
|
||
| return fabricModJson.getModVersion(); | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException("Failed to read mod version from main sourceset.", e); | ||
| if (fabricModJsons.isEmpty()) { | ||
| throw new RuntimeException("Could not find a fabric.mod.json file in the main sourceset"); | ||
| } | ||
|
|
||
| return fabricModJsons.getFirst().getModVersion(); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // 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") | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/test/resources/projects/fmjPathConfig/src/custom/resources/fabric.mod.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] | ||
| } | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/test/resources/projects/fmjPathConfig/src/main/java/ExampleMod.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
| } |
4 changes: 4 additions & 0 deletions
4
src/test/resources/projects/fmjPathConfig/src/main/java/InjectedInterface.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| public interface InjectedInterface { | ||
| default void newMethodThatDidNotExist() { | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.