use gradle properties to eliminate nullability
All checks were successful
Publish to snapshot maven / build (push) Successful in 25s

This commit is contained in:
moehreag 2024-07-05 14:15:29 +02:00
parent 97048555c6
commit dfb3aa47c5
3 changed files with 63 additions and 59 deletions

View file

@ -7,7 +7,7 @@ plugins {
}
group = "dev.frogmc"
version = "0.0.1-alpha.13"
version = "0.0.1-alpha.14"
repositories {
maven {

View file

@ -11,6 +11,7 @@ import dev.frogmc.thyroxine.provider.ParchmentProvider
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import java.nio.charset.StandardCharsets
import java.nio.file.FileSystems
@ -24,7 +25,7 @@ abstract class MinecraftConfiguration @Inject constructor(
private val objects: ObjectFactory
) {
var version: String? = null
val version: Property<String> = objects.property(String::class.java).unset()
var mappings: Provider<MappingBundle> = mojmapParchment()
internal lateinit var mappingsName: String
internal lateinit var targetNamespace: String
@ -36,23 +37,21 @@ abstract class MinecraftConfiguration @Inject constructor(
fun mojmapParchment(action: Action<ParchmentConfiguration>): Provider<MappingBundle> {
return project.provider {
val conf = objects.newInstance(ParchmentConfiguration::class.java)
conf.gameVersion = version
conf.gameVersion.convention(version)
conf.version.convention(project.provider { ParchmentProvider.findForMinecraftVersion(conf.gameVersion.get()) })
action.execute(conf)
val cacheDir = PhytotelmaPlugin.globalCacheDir
if (conf.version == null) {
conf.version = ParchmentProvider.findForMinecraftVersion(conf.gameVersion)
}
mappingsName = "mojmap($version)+parchment(${conf.gameVersion}, ${conf.version})"
mappingsName = "mojmap(${version.get()})+parchment(${conf.gameVersion.get()}, ${conf.version.get()})"
targetNamespace = "mojmap"
return@provider MappingBundle.merge(
MojmapProvider.get(
version,
cacheDir.resolve("net/minecraft/client/$version/client-$version.txt")
version.get(),
cacheDir.resolve("net/minecraft/client/${version.get()}/client-${version.get()}.txt")
).orElseThrow().reverse(),
ParchmentProvider.getParchment(
version,
version.get(),
cacheDir.resolve("org/parchmentmc/parchment/${conf.gameVersion}/${conf.version}")
)
).renameDstNamespace(targetNamespace)
@ -62,20 +61,17 @@ abstract class MinecraftConfiguration @Inject constructor(
fun parchment(action: Action<ParchmentConfiguration>): Provider<MappingBundle> {
return project.provider {
val conf = objects.newInstance(ParchmentConfiguration::class.java)
conf.gameVersion = version
conf.gameVersion.convention(version)
conf.version.convention(project.provider { ParchmentProvider.findForMinecraftVersion(conf.gameVersion.get()) })
action.execute(conf)
val cacheDir = PhytotelmaPlugin.globalCacheDir
if (conf.version == null) {
conf.version = ParchmentProvider.findForMinecraftVersion(conf.gameVersion)
}
mappingsName = "parchment(${conf.gameVersion}, ${conf.version})"
mappingsName = "parchment(${conf.gameVersion.get()}, ${conf.version.get()})"
targetNamespace = "parchment"
return@provider ParchmentProvider.getParchment(
version,
cacheDir.resolve("org/parchmentmc/parchment/${conf.gameVersion}/${conf.version}")
version.get(),
cacheDir.resolve("org/parchmentmc/parchment/${conf.gameVersion.get()}/${conf.version.get()}")
).renameNamespaces("mojmap", "parchment")
}
}
@ -83,11 +79,11 @@ abstract class MinecraftConfiguration @Inject constructor(
fun mojmap(): Provider<MappingBundle> {
return project.provider {
val cacheDir = PhytotelmaPlugin.globalCacheDir
mappingsName = "mojmap($version)"
mappingsName = "mojmap(${version.get()})"
targetNamespace = "mojmap"
return@provider MojmapProvider.get(
version,
cacheDir.resolve("net/minecraft/client/$version/client-$version.txt")
version.get(),
cacheDir.resolve("net/minecraft/client/${version.get()}/client-${version.get()}.txt")
).orElseThrow().reverse().renameDstNamespace(targetNamespace)
}
}
@ -96,15 +92,15 @@ abstract class MinecraftConfiguration @Inject constructor(
return project.provider {
val conf = objects.newInstance(VersionConfiguration::class.java)
action.execute(conf)
if (conf.version == null) {
if (!conf.version.isPresent) {
error("No version provided for quilt mappings!")
}
mappingsName = "quilt-mappings(${conf.version})"
mappingsName = "quilt-mappings(${conf.version.get()})"
targetNamespace = "quilt-mappings"
// Use qm via intermediary because hashed publications are broken
return@provider twoStepMappings(
"net.fabricmc:intermediary:$version:v2",
"org.quiltmc:quilt-mappings:${conf.version}:intermediary-v2"
"net.fabricmc:intermediary:${version.get()}:v2",
"org.quiltmc:quilt-mappings:${conf.version.get()}:intermediary-v2"
).filterClasses { !it.startsWith("net/minecraft/unmapped") }
.flatten(true).renameDstNamespace(targetNamespace)
}
@ -114,15 +110,15 @@ abstract class MinecraftConfiguration @Inject constructor(
return project.provider {
val conf = objects.newInstance(VersionConfiguration::class.java)
action.execute(conf)
if (conf.version == null) {
if (!conf.version.isPresent) {
error("No version provided for yarn!")
}
mappingsName = "yarn(${conf.version})"
mappingsName = "yarn(${conf.version.get()})"
targetNamespace = "yarn"
// Use qm via intermediary because hashed publications are broken
return@provider twoStepMappings(
"net.fabricmc:intermediary:$version:v2",
"net.fabricmc:yarn:${conf.version}:v2"
"net.fabricmc:intermediary:${version.get()}:v2",
"net.fabricmc:yarn:${conf.version.get()}:v2"
).filterClasses { !it.startsWith("net/minecraft/class_") }
.flatten(true).renameDstNamespace(targetNamespace)
}
@ -132,14 +128,14 @@ abstract class MinecraftConfiguration @Inject constructor(
return project.provider {
val conf = objects.newInstance(TwoStepMappingsConfiguration::class.java)
action.execute(conf)
if (conf.first == null) {
if (!conf.first.isPresent) {
error("No version provided for first mapping step!")
}
if (conf.second == null) {
if (!conf.second.isPresent) {
error("No version provided for second mapping step!")
}
mappingsName = "custom/two-step(${conf.first!!}, ${conf.second!!})"
val bundle = twoStepMappings(conf.first!!, conf.second!!)
mappingsName = "custom/two-step(${conf.first.get()}, ${conf.second.get()})"
val bundle = twoStepMappings(conf.first.get(), conf.second.get())
targetNamespace = bundle.flattenData().dstNamespace
return@provider bundle
}
@ -149,20 +145,24 @@ abstract class MinecraftConfiguration @Inject constructor(
return project.provider {
val conf = objects.newInstance(NameConfiguration::class.java)
action.execute(conf)
if (conf.name == null) {
if (!conf.name.isPresent) {
error("No maven coordinate provided for tiny mappings!")
}
mappingsName = "custom/tiny(${conf.name})"
val bundle = tinyMappings(conf.name!!)
mappingsName = "custom/tiny(${conf.name.get()})"
val bundle = tinyMappings(conf.name.get())
targetNamespace = bundle.flattenData().dstNamespace
return@provider bundle
}
}
fun mappings(action: Action<MappingBundle>): Provider<MappingBundle> {
fun mappings(action: Action<MappingConfiguration>): Provider<MappingBundle> {
return project.provider {
val bundle = MappingBundle()
action.execute(bundle)
val conf = objects.newInstance(MappingConfiguration::class.java)
action.execute(conf)
if (!conf.mappings.isPresent) {
error("No mappings provided!")
}
val bundle = conf.mappings.get()
mappingsName = "custom(${bundle.srcNamespaces()}, ${bundle.dstNamespaces()})"
targetNamespace = bundle.flattenData().dstNamespace
return@provider bundle
@ -177,8 +177,8 @@ abstract class MinecraftConfiguration @Inject constructor(
var back = MappingBundle()
var name = "layer["
val layers = conf.layers.mapIndexed { index, provider ->
val bundle = provider.get().flatten(true)
val layers = conf.layers.get().mapIndexed { index, provider ->
val bundle = (provider.get() as MappingBundle).flatten(true)
if (index == 0) {
name += mappingsName
back.insert(bundle)
@ -229,31 +229,35 @@ abstract class MinecraftConfiguration @Inject constructor(
return path
}
abstract class TwoStepMappingsConfiguration {
var first: String? = null
var second: String? = null
abstract class TwoStepMappingsConfiguration @Inject constructor(objects: ObjectFactory) {
val first: Property<String> = objects.property(String::class.java).unset()
val second: Property<String> = objects.property(String::class.java).unset()
}
abstract class ParchmentConfiguration {
var gameVersion: String? = null
var version: String? = null
abstract class ParchmentConfiguration @Inject constructor(objects: ObjectFactory) {
val gameVersion: Property<String> = objects.property(String::class.java).unset()
val version: Property<String> = objects.property(String::class.java).unset()
}
abstract class LayerConfiguration {
internal val layers = mutableListOf<Provider<MappingBundle>>()
abstract class LayerConfiguration @Inject constructor(objects: ObjectFactory) {
internal val layers = objects.listProperty(Provider::class.java)
fun add(mappings: Provider<MappingBundle>): LayerConfiguration {
layers.add(mappings)
return this
}
}
abstract class MappingConfiguration @Inject constructor(objects: ObjectFactory) {
val mappings: Property<MappingBundle> = objects.property(MappingBundle::class.java).unset()
}
}
abstract class NameConfiguration {
var name: String? = null
abstract class NameConfiguration @Inject constructor(objects: ObjectFactory) {
val name: Property<String> = objects.property(String::class.java).unset()
}
abstract class VersionConfiguration {
var version: String? = null
abstract class VersionConfiguration @Inject constructor(objects: ObjectFactory) {
val version: Property<String> = objects.property(String::class.java).unset()
}

View file

@ -256,10 +256,10 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
val mcConf = objects.newInstance(MinecraftConfiguration::class.java)
action.execute(mcConf)
if (mcConf.version == null) {
if (!mcConf.version.isPresent) {
error("No Minecraft version provided!")
}
val version = mcConf.version!!
val version = mcConf.version.get()
if (VersionChecker.validateVersion(version, offlineMode = project.gradle.startParameter.isOffline)) {
@ -311,18 +311,18 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
override fun loader(action: Action<VersionConfiguration>) {
val conf = objects.newInstance(VersionConfiguration::class.java)
action.execute(conf)
if (conf.version == null) {
if (!conf.version.isPresent) {
error("No loader version provided!")
}
project.dependencies.add("implementation", "dev.frogmc:frogloader:${conf.version!!}")
project.dependencies.add("implementation", "dev.frogmc:frogloader:${conf.version.get()}")
}
override fun froglib(action: Action<VersionConfiguration>) {
val conf = objects.newInstance(VersionConfiguration::class.java)
action.execute(conf)
if (conf.version == null) {
if (!conf.version.isPresent) {
error("No froglib version provided!")
}
project.dependencies.add("modImplementation", "dev.frogmc:froglib:${conf.version!!}")
project.dependencies.add("modImplementation", "dev.frogmc:froglib:${conf.version.get()}")
}
}