mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-26 14:30:17 +01:00
Add update helper task
This commit is contained in:
parent
723c05e7fe
commit
c7a463a736
2 changed files with 72 additions and 8 deletions
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue