-
-
Notifications
You must be signed in to change notification settings - Fork 445
[7.0] Add support for mavenizer output json, and expose mappings helper methods #1042
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
+261
−38
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
24a7d83
Add support for mavenizer output json, and expose mappings helper met…
LexManos d4ea0e3
Fix file variants
LexManos 693aaee
Move to MapProperty
LexManos d9823bb
Address a couple of minor nitpicks
Jonathing e36044e
Make MavenizerInstance a ProviderConvertible<ExternalModuleDependency>
Jonathing 46aa860
Document new interfaces and methods
Jonathing b6fb47e
Throw on `minecraft.getDependency()` if dependency is not found
Jonathing 8964f94
Forgot to document this method
Jonathing 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
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
56 changes: 56 additions & 0 deletions
56
src/main/java/net/minecraftforge/gradle/MavenizerInstance.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,56 @@ | ||
| /* | ||
| * Copyright (c) Forge Development LLC and contributors | ||
| * SPDX-License-Identifier: LGPL-2.1-only | ||
| */ | ||
| package net.minecraftforge.gradle; | ||
|
|
||
| import org.gradle.api.artifacts.ExternalModuleDependency; | ||
| import org.gradle.api.provider.Provider; | ||
| import org.gradle.api.provider.ProviderConvertible; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| /// A Mavenizer instance is an abstraction over an invocation of the Minecraft Mavenizer and its output when generating | ||
| /// a Minecraft dependency. This is designed to be consumed by one of the various | ||
| /// [MinecraftExtensionForProject#dependency] methods as it is a [ProviderConvertible] of a dependency. | ||
| /// | ||
| /// This is not to be confused with [MinecraftDependency], which is designed to add additional DSL features on top of | ||
| /// [ExternalModuleDependency] when configuring a Minecraft dependency in your buildscript. | ||
| public interface MavenizerInstance extends ProviderConvertible<ExternalModuleDependency> { | ||
| /// Gets the dependency (used by Gradle) generated by the Mavenizer instance. | ||
| /// | ||
| /// @return The dependency generated by this instance | ||
| @Override Provider<ExternalModuleDependency> asProvider(); | ||
|
|
||
| /// Gets the mappings version used by the Mavenizer instance. | ||
| /// | ||
| /// @return The mappings version used | ||
| /// @see MinecraftMappings#getVersion() | ||
| Provider<String> getMappingVersion(); | ||
|
|
||
| /// Gets the artifact coordinates for the SRG mappings used by the Mavenizer instance. | ||
| /// | ||
| /// @return The SRG mapping artifact coordinate | ||
| Provider<String> getToSrg(); | ||
|
|
||
| /// Gets the SRG mapping file used by the Mavenizer instance. | ||
| /// | ||
| /// @return The SRG mapping file | ||
| /// @apiNote Buildscript authors should prefer to use [#getToSrg()] with | ||
| /// [org.gradle.api.artifacts.dsl.DependencyFactory#create(CharSequence)] or | ||
| /// [org.gradle.api.artifacts.dsl.DependencyHandler#addProvider(String, Provider)]. | ||
| Provider<File> getToSrgFile(); | ||
|
|
||
| /// Gets the artifact coordinates for the SRG mappings used by the Mavenizer instance. | ||
| /// | ||
| /// @return The SRG mapping artifact coordinate | ||
| Provider<String> getToObf(); | ||
|
|
||
| /// Gets the notch mapping file used by the Mavenizer instance. | ||
| /// | ||
| /// @return The notch mapping file | ||
| /// @apiNote Buildscript authors should prefer to use [#getToObf()] with | ||
| /// [org.gradle.api.artifacts.dsl.DependencyFactory#create(CharSequence)] or | ||
| /// [org.gradle.api.artifacts.dsl.DependencyHandler#addProvider(String, Provider)]. | ||
| Provider<File> getToObfFile(); | ||
| } |
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
87 changes: 87 additions & 0 deletions
87
src/main/java/net/minecraftforge/gradle/internal/MavenizerInstanceImpl.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,87 @@ | ||
| /* | ||
| * Copyright (c) Forge Development LLC and contributors | ||
| * SPDX-License-Identifier: LGPL-2.1-only | ||
| */ | ||
| package net.minecraftforge.gradle.internal; | ||
|
|
||
| import groovy.json.JsonSlurper; | ||
| import net.minecraftforge.gradle.MavenizerInstance; | ||
| import org.gradle.api.Transformer; | ||
| import org.gradle.api.artifacts.ExternalModuleDependency; | ||
| import org.gradle.api.provider.MapProperty; | ||
| import org.gradle.api.provider.Provider; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import java.io.File; | ||
| import java.util.Map; | ||
|
|
||
| class MavenizerInstanceImpl implements MavenizerInstance { | ||
| private final MinecraftExtensionImpl.ForProjectImpl extension; | ||
| private final Provider<Boolean> valueSource; | ||
| private final ExternalModuleDependency dependency; | ||
| private final File jsonFile; | ||
|
|
||
| private final MapProperty<String, String> invoke; | ||
| private @Nullable Map<String, String> map; | ||
|
|
||
| MavenizerInstanceImpl( | ||
| MinecraftExtensionImpl.ForProjectImpl extension, | ||
| Provider<Boolean> valueSource, | ||
| ExternalModuleDependency dependency, | ||
| File jsonFile | ||
| ) { | ||
| this.extension = extension; | ||
| this.dependency = dependency; | ||
| this.valueSource = valueSource; | ||
| this.jsonFile = jsonFile; | ||
| this.invoke = this.extension.getObjects().mapProperty(String.class, String.class) | ||
| .convention(this.extension.getProviders().provider(this::invoke)); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private Map<String, String> invoke() { | ||
| if (this.map == null) { | ||
| valueSource.get(); // Execute Mavenizer, probably called before, but just be sure. | ||
| this.map = (Map<String, String>) new JsonSlurper().parse(this.jsonFile, "UTF-8"); | ||
| //this.map.forEach((k, v) -> this.extension.getProject().getLogger().lifecycle(k + " => " + v)); | ||
| } | ||
| return this.map; | ||
| } | ||
|
|
||
| private Provider<String> get(String key) { | ||
| return this.invoke.getting(key) | ||
| .orElse(this.extension.getProviders().provider(() -> { | ||
| throw new IllegalStateException("Mavenizer did not output expected json data " + key); | ||
| })); | ||
| } | ||
|
|
||
| @Override | ||
| public Provider<ExternalModuleDependency> asProvider() { | ||
| return this.invoke.map(m -> this.dependency); | ||
| } | ||
|
|
||
| @Override | ||
| public Provider<String> getMappingVersion() { | ||
| return get("mappings.version"); | ||
| } | ||
|
|
||
| @Override | ||
| public Provider<String> getToSrg() { | ||
| return get("mappings.srg.artifact"); | ||
| } | ||
|
|
||
| @Override | ||
| public Provider<File> getToSrgFile() { | ||
| return get("mappings.srg.file").map(this.extension.getProject()::file); | ||
| } | ||
|
|
||
| @Override | ||
| public Provider<String> getToObf() { | ||
| return get("mappings.obf.artifact"); | ||
| } | ||
|
|
||
| @Override | ||
| public Provider<File> getToObfFile() { | ||
| return get("mappings.obf.file").map(this.extension.getProject()::file); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are using Gson in Mavenizer, we should prefer using it in here as well. This is fine for now, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didnt want to add extra deps to FG as we are not using GSON for anything else currently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FG already bundles Gson as it is a transitive dependency of JSON Data Utils. But not a big deal, we can revisit this as needed.