Skip to content

Commit

Permalink
Make several changes to Minecraft releases plugin
Browse files Browse the repository at this point in the history
- Make gameVersions a list of MinecraftVersion
- Make loaders a list of ModLoader
- Return all loaders for Modrinth in all-lowercase
- Return all loaders for CurseForge with their proper name capitalization
  • Loading branch information
Deftu committed Sep 6, 2024
1 parent ec42165 commit 1dd096a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import org.gradle.api.provider.Property
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.bundling.Zip
import dev.deftu.gradle.utils.MCData
import dev.deftu.gradle.utils.MinecraftVersion
import dev.deftu.gradle.utils.ModLoader
import dev.deftu.gradle.utils.VersionType
import java.io.File

Expand All @@ -18,8 +20,8 @@ abstract class ReleasingExtension(
abstract val version: Property<String>
abstract val versionType: Property<VersionType>
abstract val detectVersionType: Property<Boolean>
abstract val gameVersions: ListProperty<String>
abstract val loaders: ListProperty<String>
abstract val gameVersions: ListProperty<MinecraftVersion>
abstract val loaders: ListProperty<ModLoader>
abstract val file: Property<Zip>

abstract val describeFabricWithQuilt: Property<Boolean>
Expand All @@ -44,8 +46,8 @@ abstract class ReleasingExtension(
val mcData = MCData.from(project)
versionType.convention(VersionType.RELEASE)
detectVersionType.convention(false)
gameVersions.set(listOf(mcData.version.toString()))
loaders.set(listOf(mcData.loader.friendlyString))
gameVersions.set(listOf(mcData.version))
loaders.set(listOf(mcData.loader))
describeFabricWithQuilt.convention(false)
useSourcesJar.convention(false)
useJavadocJar.convention(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ fun ReleasingExtension.getReleaseVersion(): String {

fun ReleasingExtension.getUploadFile() = file.getOrElse(tasks.named<org.gradle.jvm.tasks.Jar>("remapJar").get())

fun ReleasingExtension.getGameVersions() = gameVersions.getOrElse(listOf(mcData.version.toString()))
fun ReleasingExtension.getLoaders(capitalized: Boolean) = loaders.getOrElse(listOf(mcData.loader.friendlyString)).map { loader ->
if (capitalized) loader.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.US) else it.toString() } else loader
}
fun ReleasingExtension.getGameVersions() = gameVersions.getOrElse(listOf(mcData.version))

fun ReleasingExtension.getLoaders() = loaders.getOrElse(listOf(mcData.loader))

fun ReleasingExtension.getVersionType() = versionType.getOrElse(VersionType.RELEASE)

Expand Down Expand Up @@ -113,8 +112,6 @@ afterEvaluate {
})
}

if (mcData.isFabric && extension.describeFabricWithQuilt.get()) extension.loaders.add("quilt")

if (modData.isPresent) {
if (extension.detectVersionType.getOrElse(false)) {
val version = extension.version.getOrElse(modData.version)
Expand All @@ -129,14 +126,21 @@ afterEvaluate {
})
}

if (modrinthToken.isNotBlank()) setupModrinth(modrinthToken)
if (curseForgeApiKey.isNotBlank()) setupCurseForge(curseForgeApiKey)
if (modrinthToken.isNotBlank()) {
setupModrinth(modrinthToken)
}

if (curseForgeApiKey.isNotBlank()) {
setupCurseForge(curseForgeApiKey)
}
}
}

fun setupModrinth(token: String) {
val projectId = extension.modrinth.projectId.orNull
if (projectId.isNullOrBlank()) return
if (projectId.isNullOrBlank()) {
return
}

apply<Minotaur>()
configure<ModrinthExtension> {
Expand All @@ -151,12 +155,21 @@ fun setupModrinth(token: String) {
versionType.set(extension.getVersionType().value)
uploadFile.set(extension.getUploadFile())

if (extension.shouldAddSourcesJar()) additionalFiles.add(extension.getSourcesJar())
if (extension.shouldAddJavadocJar()) additionalFiles.add(extension.getJavadocJar())
if (extension.shouldAddSourcesJar()) {
additionalFiles.add(extension.getSourcesJar())
}

if (extension.shouldAddJavadocJar()) {
additionalFiles.add(extension.getJavadocJar())
}

changelog.set(extension.changelog.get())
gameVersions.addAll(extension.getGameVersions())
loaders.addAll(extension.getLoaders(false))
gameVersions.addAll(extension.getGameVersions().map(MinecraftVersion::toString))
loaders.addAll(extension.getLoaders().map(ModLoader::toString))
if (mcData.isFabric && extension.describeFabricWithQuilt.getOrElse(false)) {
loaders.add("quilt")
}

dependencies.addAll(extension.modrinth.dependencies.getOrElse(listOf()))
}

Expand All @@ -172,7 +185,9 @@ fun setupModrinth(token: String) {

fun setupCurseForge(apiKey: String) {
val projectId = extension.curseforge.projectId.orNull
if (projectId.isNullOrBlank()) return
if (projectId.isNullOrBlank()) {
return
}

val publishToCurseForge by tasks.registering(TaskPublishCurseForge::class) {
group = ToolkitConstants.TASK_GROUP
Expand All @@ -187,14 +202,23 @@ fun setupCurseForge(apiKey: String) {
releaseType = extension.getVersionType().value
changelog = extension.changelog.get()
changelogType = extension.curseforge.changelogType.getOrElse("text")
extension.getLoaders(true).forEach(this::addModLoader)
extension.getLoaders().map(ModLoader::friendlyName).forEach(this::addModLoader)
if (mcData.isFabric && extension.describeFabricWithQuilt.getOrElse(false)) {
addModLoader("Quilt")
}

extension.getGameVersions().forEach(this::addGameVersion)
extension.curseforge.relations.getOrElse(listOf()).forEach { relation ->
relation.applyTo(this)
}

if (extension.shouldAddSourcesJar()) withAdditionalFile(extension.getSourcesJar())
if (extension.shouldAddJavadocJar()) withAdditionalFile(extension.getJavadocJar())
if (extension.shouldAddSourcesJar()) {
withAdditionalFile(extension.getSourcesJar())
}

if (extension.shouldAddJavadocJar()) {
withAdditionalFile(extension.getJavadocJar())
}
}
}

Expand Down

0 comments on commit 1dd096a

Please sign in to comment.