Add update helper task

This commit is contained in:
Jason Penilla 2023-12-05 20:35:33 -07:00
parent 723c05e7fe
commit c7a463a736
No known key found for this signature in database
GPG Key ID: 0E75A301420E48F8
2 changed files with 72 additions and 8 deletions

View File

@ -1,5 +1,10 @@
import io.papermc.paperweight.tasks.BaseTask
import io.papermc.paperweight.util.*
import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent import org.gradle.api.tasks.testing.logging.TestLogEvent
import java.io.ByteArrayOutputStream
import java.nio.file.Path
import kotlin.io.path.*
plugins { plugins {
java java
@ -131,14 +136,6 @@ allprojects {
} }
} }
// Uncomment while updating for a new Minecraft version
tasks.collectAtsFromPatches {
extraPatchDir.set(layout.projectDirectory.dir("patches/unapplied/server"))
}
tasks.withType<io.papermc.paperweight.tasks.RebuildGitPatches> {
filterPatches.set(false)
}
tasks.register("printMinecraftVersion") { tasks.register("printMinecraftVersion") {
doLast { doLast {
println(providers.gradleProperty("mcVersion").get().trim()) println(providers.gradleProperty("mcVersion").get().trim())
@ -150,3 +147,67 @@ tasks.register("printPaperVersion") {
println(project.version) println(project.version)
} }
} }
// see gradle.properties
if (providers.gradleProperty("updatingMinecraft").getOrElse("false").toBoolean()) {
tasks.collectAtsFromPatches {
extraPatchDir.set(layout.projectDirectory.dir("patches/unapplied/server"))
}
tasks.withType<io.papermc.paperweight.tasks.RebuildGitPatches>().configureEach {
filterPatches.set(false)
}
tasks.register("continueServerUpdate", RebasePatches::class) {
projectDir = project.projectDir
appliedPatches = file("patches/server")
unappliedPatches = file("patches/unapplied/server")
}
}
@UntrackedTask(because = "Does not make sense to track state")
abstract class RebasePatches : BaseTask() {
@get:Internal
abstract val projectDir: DirectoryProperty
@get:InputFiles
abstract val appliedPatches: DirectoryProperty
@get:InputFiles
abstract val unappliedPatches: DirectoryProperty
private fun unapplied(): List<Path> =
unappliedPatches.path.listDirectoryEntries("*.patch").sortedBy { it.name }
@TaskAction
fun run() {
for (patch in unapplied()) {
val appliedLoc = appliedPatches.path.resolve(unappliedPatches.path.relativize(patch))
patch.copyTo(appliedLoc)
val out = ByteArrayOutputStream()
val proc = ProcessBuilder()
.directory(projectDir.path)
.command("./gradlew", "applyServerPatches")
.redirectErrorStream(true)
.start()
redirect(proc.inputStream, out)
val exit = proc.waitFor()
patch.deleteIfExists()
if (exit != 0) {
logger.lifecycle("Patch failed at $patch; Git output:")
logger.lifecycle(String(out.toByteArray()))
break
}
val git = Git(projectDir.path)
git("add", appliedPatches.path.toString() + "/*").runSilently()
git("add", unappliedPatches.path.toString() + "/*").runSilently()
logger.lifecycle("Applied $patch")
}
}
}

View File

@ -2,6 +2,9 @@ group=io.papermc.paper
version=1.20.3-R0.1-SNAPSHOT version=1.20.3-R0.1-SNAPSHOT
mcVersion=1.20.3 mcVersion=1.20.3
# Set to true while updating Minecraft version
updatingMinecraft=true
org.gradle.caching=true org.gradle.caching=true
org.gradle.parallel=true org.gradle.parallel=true
org.gradle.vfs.watch=false org.gradle.vfs.watch=false