diff options
author | Jason Penilla <[email protected]> | 2023-12-05 20:35:33 -0700 |
---|---|---|
committer | Jason Penilla <[email protected]> | 2023-12-05 20:35:33 -0700 |
commit | c7a463a736847243948bbadfaca1e4bad962fdf7 (patch) | |
tree | 53321bf3106043670d81c9b896ad46f77cba75c6 /build.gradle.kts | |
parent | 723c05e7fec35a4994db312d3acd553d7ffe0fc9 (diff) | |
download | Paper-c7a463a736847243948bbadfaca1e4bad962fdf7.tar.gz Paper-c7a463a736847243948bbadfaca1e4bad962fdf7.zip |
Add update helper task
Diffstat (limited to 'build.gradle.kts')
-rw-r--r-- | build.gradle.kts | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/build.gradle.kts b/build.gradle.kts index cda5021dba..cb9e7e93b8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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") + } + } +} |