-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
218 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 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
85 changes: 85 additions & 0 deletions
85
src/main/java/net/neoforged/moddevgradle/dsl/Parchment.java
This file contains 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,85 @@ | ||
package net.neoforged.moddevgradle.dsl; | ||
|
||
import net.neoforged.moddevgradle.internal.utils.PropertyUtils; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.artifacts.repositories.MavenArtifactRepository; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.Internal; | ||
import org.gradle.api.tasks.Optional; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import javax.inject.Inject; | ||
import java.net.URI; | ||
|
||
/** | ||
* Allows configuration of Parchment mappings for userdev. | ||
*/ | ||
@ApiStatus.NonExtendable | ||
public abstract class Parchment { | ||
@Inject | ||
public Parchment(Project project) { | ||
getParchmentArtifact().convention( | ||
project.getProviders().gradleProperty("neoForge.parchment.parchmentArtifact").orElse( | ||
getMinecraftVersion() | ||
.zip(getMappingsVersion(), (minecraftVersion, mappingVersion) -> { | ||
return "org.parchmentmc.data" | ||
+ ":" + "parchment-" + minecraftVersion | ||
+ ":" + mappingVersion | ||
// We need the checked variant for now since it resolves | ||
// parameters conflicting with local variables by prefixing everything with "p" | ||
+ ":checked" | ||
+ "@zip"; | ||
}) | ||
) | ||
); | ||
getMinecraftVersion().convention( | ||
project.getProviders().gradleProperty("neoForge.parchment.minecraftVersion") | ||
); | ||
getMappingsVersion().convention( | ||
project.getProviders().gradleProperty("neoForge.parchment.mappingsVersion") | ||
); | ||
getAddRepository().convention( | ||
PropertyUtils.getBooleanProperty(project, "neoForge.parchment.addRepository").orElse(true) | ||
); | ||
getEnabled().convention(getParchmentArtifact() | ||
.map(s -> !s.isEmpty()).orElse(PropertyUtils.getBooleanProperty(project, "neoForge.parchment.enabled").orElse(false))); | ||
} | ||
|
||
/** | ||
* Artifact coordinates for parchment mappings. | ||
*/ | ||
@Input | ||
@Optional | ||
public abstract Property<String> getParchmentArtifact(); | ||
|
||
/** | ||
* Minecraft version of parchment to use. This property is | ||
* ignored if {@link #getParchmentArtifact()} is set explicitly. | ||
*/ | ||
@Input | ||
@Optional | ||
public abstract Property<String> getMinecraftVersion(); | ||
|
||
/** | ||
* Mapping version of default parchment to use. This property is | ||
* ignored if {@link #getParchmentArtifact()} is set explicitly. | ||
*/ | ||
@Input | ||
@Optional | ||
public abstract Property<String> getMappingsVersion(); | ||
|
||
/** | ||
* If enabled (the default), the parchment repository will automatically be added to the project, | ||
* if {@link #getEnabled()} is true. | ||
*/ | ||
@Internal | ||
public abstract Property<Boolean> getAddRepository(); | ||
|
||
/** | ||
* Enables or disables the system. It is enabled by default if a {@link #getParchmentArtifact()} is specified. | ||
*/ | ||
@Input | ||
public abstract Property<Boolean> getEnabled(); | ||
|
||
} |
This file contains 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 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
26 changes: 26 additions & 0 deletions
26
src/main/java/net/neoforged/moddevgradle/internal/utils/PropertyUtils.java
This file contains 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,26 @@ | ||
package net.neoforged.moddevgradle.internal.utils; | ||
|
||
import org.gradle.api.GradleException; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.provider.Provider; | ||
|
||
public final class PropertyUtils { | ||
private PropertyUtils() { | ||
} | ||
|
||
public static Provider<String> getStringProperty(Project project, String propertyName) { | ||
return project.getProviders().gradleProperty(propertyName); | ||
} | ||
|
||
public static Provider<Boolean> getBooleanProperty(Project project, String propertyName) { | ||
return project.getProviders().gradleProperty(propertyName) | ||
.map(value -> { | ||
try { | ||
return Boolean.valueOf(value); | ||
} catch (Exception e) { | ||
throw new GradleException("Gradle Property " + propertyName + " is not set to a boolean value: '" + value + "'"); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains 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