13
0
geforkt von Mirrors/Paper

Add update helper task

Dieser Commit ist enthalten in:
Jason Penilla 2023-12-05 20:35:33 -07:00
Ursprung 723c05e7fe
Commit c7a463a736
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0E75A301420E48F8
2 geänderte Dateien mit 72 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -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.TestLogEvent
import java.io.ByteArrayOutputStream
import java.nio.file.Path
import kotlin.io.path.*
plugins {
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") {
doLast {
println(providers.gradleProperty("mcVersion").get().trim())
@ -150,3 +147,67 @@ tasks.register("printPaperVersion") {
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")
}
}
}

Datei anzeigen

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