Fix AlwaysUpToDate
This commit is contained in:
@@ -9,13 +9,16 @@ import org.plazmamc.alwaysuptodate.tasks.PurpurUpdateTask
|
||||
|
||||
class AlwaysUpToDate : Plugin<Project> {
|
||||
|
||||
override fun apply(target: Project) {
|
||||
override fun apply(target: Project) = with(target) {
|
||||
|
||||
target.extensions.create("alwaysUpToDate", AlwaysUpToDateExtension::class.java)
|
||||
target.tasks.register("updatePaper", PaperUpdateTask::class.java)
|
||||
target.tasks.register("updatePurpur", PurpurUpdateTask::class.java)
|
||||
target.tasks.register("checkPaperCommit", CheckPaperCommitTask::class.java)
|
||||
target.tasks.register("checkPurpurCommit", CheckPurpurCommitTask::class.java)
|
||||
extensions.create("alwaysUpToDate", AlwaysUpToDateExtension::class.java)
|
||||
|
||||
arrayOf(
|
||||
"updatePaper" to PaperUpdateTask::class.java,
|
||||
"updatePurpur" to PurpurUpdateTask::class.java,
|
||||
"checkPaperCommit" to CheckPaperCommitTask::class.java,
|
||||
"checkPurpurCommit" to CheckPurpurCommitTask::class.java,
|
||||
).forEach { tasks.register(it.first, it.second) }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -10,20 +10,18 @@ import org.plazmamc.alwaysuptodate.AlwaysUpToDateException
|
||||
import org.plazmamc.alwaysuptodate.AlwaysUpToDateExtension
|
||||
import org.plazmamc.alwaysuptodate.utils.pathIO
|
||||
import paper.libs.com.google.gson.JsonObject
|
||||
import java.net.URI
|
||||
import java.net.URI.create
|
||||
|
||||
abstract class CheckPaperCommitTask : Task() {
|
||||
|
||||
private val property = project.extensions["alwaysUpToDate"] as AlwaysUpToDateExtension
|
||||
|
||||
@TaskAction
|
||||
fun check() {
|
||||
println(project.checkCommit(
|
||||
project.property(property.paperRepoName.get()).toString(),
|
||||
project.property(property.paperBranchName.get()).toString(),
|
||||
property.paperCommitName.get()
|
||||
))
|
||||
}
|
||||
fun check() = println(project.checkCommit(
|
||||
project.property(property.paperRepoName.get()).toString(),
|
||||
project.property(property.paperBranchName.get()).toString(),
|
||||
property.paperCommitName.get()
|
||||
))
|
||||
|
||||
}
|
||||
|
||||
@@ -32,41 +30,32 @@ abstract class CheckPurpurCommitTask : Task() {
|
||||
private val property = project.extensions["alwaysUpToDate"] as AlwaysUpToDateExtension
|
||||
|
||||
@TaskAction
|
||||
fun check() {
|
||||
println(project.checkCommit(
|
||||
project.property(property.purpurRepoName.get()).toString(),
|
||||
project.property(property.purpurBranchName.get()).toString(),
|
||||
property.purpurCommitName.get()
|
||||
))
|
||||
}
|
||||
fun check() = println(project.checkCommit(
|
||||
project.property(property.purpurRepoName.get()).toString(),
|
||||
project.property(property.purpurBranchName.get()).toString(),
|
||||
property.purpurCommitName.get()
|
||||
))
|
||||
|
||||
}
|
||||
|
||||
fun Project.getLatest(repository: String, branch: String) : String {
|
||||
val regex = "[a-z0-9]{40}\trefs/heads/$branch".toRegex()
|
||||
val temp = Git(project.pathIO)("ls-remote", repository).readText()
|
||||
|
||||
return temp?.lines()?.first(regex::matches)?.split("\t")?.first()
|
||||
fun Project.getLatest(repository: String, branch: String) =
|
||||
Git(project.pathIO)("ls-remote", repository).readText()
|
||||
?.lines()?.first("[a-z0-9]{40}\trefs/heads/$branch".toRegex()::matches)?.split("\t")?.first()
|
||||
?: throw AlwaysUpToDateException("Failed to get latest commit of $repository")
|
||||
}
|
||||
|
||||
fun Project.checkCommit(repository: String, branch: String, propertyName: String) : Boolean {
|
||||
val latestCommit = project.getLatest(repository, branch)
|
||||
val currentCommit = project.properties[propertyName] as String
|
||||
|
||||
return currentCommit == latestCommit
|
||||
}
|
||||
fun Project.checkCommit(repository: String, branch: String, propertyName: String) =
|
||||
project.getLatest(repository, branch) == project.properties[propertyName] as String
|
||||
|
||||
fun Project.createCompareComment(repository: String, branch: String, before: String, clear: Boolean = false) {
|
||||
val builder = StringBuilder()
|
||||
val rawRepo = URI.create(repository).path.substring(1)
|
||||
val rawRepo = create(repository).path.substring(1)
|
||||
|
||||
if (!clear) builder.append(project.file("compare.txt").readText())
|
||||
if (clear) builder.append("\n\nUpstream has released updates that appear to apply and compile correctly.")
|
||||
else builder.append(project.file("compare.txt").readText())
|
||||
builder.append("\n\n[${rawRepo.split("/").last()} Changes]\n")
|
||||
|
||||
gson.fromJson<JsonObject>(URI.create("https://api.github.com/repos/$rawRepo/compare/$before...$branch").toURL().readText())["commits"].asJsonArray.forEach {
|
||||
val commit = it.asJsonObject
|
||||
builder.append("$rawRepo@${commit["sha"].asString.subSequence(0, 7)}: ${commit["commit"].asJsonObject["message"].asString.split("\n")[0]}\n")
|
||||
gson.fromJson<JsonObject>(create("https://api.github.com/repos/$rawRepo/compare/$before...$branch").toURL().readText())["commits"].asJsonArray.forEach { obj ->
|
||||
obj.asJsonObject.let { builder.append("$rawRepo@${it["sha"].asString.subSequence(0, 7)}: ${it["commit"].asJsonObject["message"].asString.split("\n")[0]}\n") }
|
||||
}
|
||||
project.file("compare.txt").writeText(builder.toString())
|
||||
}
|
||||
|
||||
@@ -11,44 +11,43 @@ abstract class PaperUpdateTask : Task() {
|
||||
|
||||
private val property = project.extensions["alwaysUpToDate"] as AlwaysUpToDateExtension
|
||||
|
||||
override fun init() {
|
||||
outputs.upToDateWhen {
|
||||
project.checkCommit(
|
||||
project.property(property.paperRepoName.get()).toString(),
|
||||
project.property(property.paperBranchName.get()).toString(),
|
||||
property.paperCommitName.get()
|
||||
)
|
||||
}
|
||||
override fun init() = outputs.upToDateWhen {
|
||||
project.checkCommit(
|
||||
project.property(property.paperRepoName.get()).toString(),
|
||||
project.property(property.paperBranchName.get()).toString(),
|
||||
property.paperCommitName.get()
|
||||
)
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun update() {
|
||||
if (project.checkCommit(
|
||||
project.property(property.paperRepoName.get()).toString(),
|
||||
project.property(property.purpurBranchName.get()).toString(),
|
||||
fun update() = with(project) {
|
||||
if (
|
||||
checkCommit(
|
||||
property(property.paperRepoName.get()).toString(),
|
||||
property(property.paperBranchName.get()).toString(),
|
||||
property.purpurCommitName.get()
|
||||
)) return
|
||||
)
|
||||
) return
|
||||
|
||||
project.createCompareComment(
|
||||
project.property(property.paperRepoName.get()).toString(),
|
||||
project.property(property.paperBranchName.get()).toString(),
|
||||
project.property(property.paperCommitName.get()).toString(),
|
||||
createCompareComment(
|
||||
property(property.paperRepoName.get()).toString(),
|
||||
property(property.paperBranchName.get()).toString(),
|
||||
property(property.paperCommitName.get()).toString(),
|
||||
true
|
||||
)
|
||||
|
||||
updatePaperCommit(
|
||||
project.property(property.paperRepoName.get()).toString(),
|
||||
project.property(property.paperBranchName.get()).toString(),
|
||||
project.file("gradle.properties")
|
||||
property(property.paperRepoName.get()).toString(),
|
||||
property(property.paperBranchName.get()).toString(),
|
||||
file("gradle.properties")
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun updatePaperCommit(repo: String, branch: String, properties: File, regexRule: String = "paperCommit = ") {
|
||||
val latestCommit = Git(properties.parentFile.toPath())("ls-remote", repo).readText()?.lines()
|
||||
?.filterNot { "[a-z0-9]{40}\trefs/heads/$branch".toRegex().matches(it) }?.first()?.split("\t")?.first()
|
||||
?: throw AlwaysUpToDateException("Failed to get latest Paper commit")
|
||||
|
||||
properties.writeText(properties.readText().replace("$regexRule.*".toRegex(), "$regexRule$latestCommit"))
|
||||
}
|
||||
fun updatePaperCommit(repo: String, branch: String, properties: File, regexRule: String = "paperCommit = ") =
|
||||
(Git(properties.parentFile.toPath())("ls-remote", repo).readText()?.lines()
|
||||
?.filterNot("[a-z0-9]{40}\trefs/heads/$branch".toRegex()::matches)?.first()?.split("\t")?.first()
|
||||
?: throw AlwaysUpToDateException("Failed to get latest Paper commit")).let {
|
||||
properties.writeText(properties.readText().replace("$regexRule.*".toRegex(), "$regexRule$it"))
|
||||
}
|
||||
|
||||
@@ -3,22 +3,23 @@ package org.plazmamc.alwaysuptodate.tasks
|
||||
import io.papermc.paperweight.util.Git
|
||||
import io.papermc.paperweight.util.cache
|
||||
import io.papermc.paperweight.util.path
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.get
|
||||
import org.plazmamc.alwaysuptodate.AlwaysUpToDateException
|
||||
import org.plazmamc.alwaysuptodate.AlwaysUpToDateExtension
|
||||
import org.plazmamc.alwaysuptodate.utils.Gradle
|
||||
import org.plazmamc.alwaysuptodate.utils.addCommit
|
||||
import org.plazmamc.alwaysuptodate.utils.clone
|
||||
import org.plazmamc.alwaysuptodate.utils.propValue
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
import java.util.Calendar
|
||||
import kotlin.io.path.createDirectories
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.*
|
||||
|
||||
abstract class PurpurUpdateTask : Task() {
|
||||
|
||||
private val property = project.extensions["alwaysUpToDate"] as AlwaysUpToDateExtension
|
||||
private val pufferfishCommit = """
|
||||
private val pufferfishHeader = """
|
||||
Pufferfish
|
||||
Copyright (C) ${Calendar.getInstance().get(Calendar.YEAR)} Pufferfish Studios LLC
|
||||
|
||||
@@ -35,7 +36,7 @@ abstract class PurpurUpdateTask : Task() {
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
""".trimIndent()
|
||||
private val purpurCommit = """
|
||||
private val purpurHeader = """
|
||||
PurpurMC
|
||||
Copyright (C) ${Calendar.getInstance().get(Calendar.YEAR)} PurpurMC
|
||||
|
||||
@@ -58,233 +59,130 @@ abstract class PurpurUpdateTask : Task() {
|
||||
SOFTWARE.
|
||||
""".trimIndent()
|
||||
|
||||
override fun init() {
|
||||
outputs.upToDateWhen {
|
||||
project.checkCommit(
|
||||
project.property(property.purpurRepoName.get()).toString(),
|
||||
project.property(property.purpurBranchName.get()).toString(),
|
||||
property.purpurCommitName.get()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun withoutPufferfish(dir: Path) {
|
||||
val git = Git(dir)
|
||||
val purpur = git.clone(
|
||||
"Purpur",
|
||||
project.property(property.purpurRepoName.get()).toString(),
|
||||
project.property(property.purpurBranchName.get()).toString(),
|
||||
dir
|
||||
override fun init() = outputs.upToDateWhen {
|
||||
project.checkCommit(
|
||||
project.propValue(property.purpurRepoName),
|
||||
project.propValue(property.purpurBranchName),
|
||||
property.purpurCommitName.get()
|
||||
)
|
||||
val purpurPatches = purpur.resolve("patches")
|
||||
|
||||
project.properties.let {
|
||||
it[property.paperRepoName.get()].toString() to it[property.paperBranchName.get()].toString()
|
||||
}.also {
|
||||
updatePaperCommit(it.first, it.second, purpur.resolve("gradle.properties").toFile())
|
||||
|
||||
if (project.checkCommit(
|
||||
it.first,
|
||||
it.second,
|
||||
property.paperCommitName.get()
|
||||
)) return@also
|
||||
|
||||
project.createCompareComment(
|
||||
it.first,
|
||||
it.second,
|
||||
project.property(property.paperCommitName.get()).toString()
|
||||
)
|
||||
updatePaperCommit(
|
||||
it.first,
|
||||
it.second,
|
||||
project.file("gradle.properties")
|
||||
)
|
||||
}
|
||||
|
||||
val latestCommit = git("ls-remote", project.property(property.purpurRepoName.get()).toString()).readText()?.lines()
|
||||
?.filterNot { "[a-z0-9]{40}\trefs/heads/${project.property(property.purpurBranchName.get())}".toRegex().matches(it) }
|
||||
?.first()?.split("\t")?.first()
|
||||
?: throw AlwaysUpToDateException("Failed to get latest Purpur commit")
|
||||
|
||||
val purpurGradle = Gradle(purpur)
|
||||
purpurGradle("applyPatches").executeOut()
|
||||
|
||||
purpur.resolve("Purpur-Server").also {
|
||||
val dotGit = it.resolve(".git").toFile()
|
||||
dotGit.deleteRecursively()
|
||||
copySource(it)
|
||||
|
||||
val paper = purpur.resolve(".gradle/caches/paperweight/upstreams/paper/Paper-Server")
|
||||
copySource(paper)
|
||||
Git(paper).addCommit("Vanilla Sources", "--author=Vanilla <auto@mated.null>")
|
||||
Thread.sleep(1_000)
|
||||
paper.resolve(".git").toFile().copyRecursively(dotGit, overwrite = true)
|
||||
Git(it).addCommit("Purpur Server Changes\n\n$purpurCommit", "--author=granny <contact@granny.dev>")
|
||||
}
|
||||
|
||||
purpur.resolve("Purpur-API").also {
|
||||
val dotGit = it.resolve(".git").toFile()
|
||||
dotGit.deleteRecursively()
|
||||
|
||||
val paper = purpur.resolve(".gradle/caches/paperweight/upstreams/paper/Paper-API")
|
||||
paper.resolve(".git").toFile().copyRecursively(dotGit, overwrite = true)
|
||||
Git(it).addCommit("Purpur API Changes\n\n$purpurCommit", "--author=granny <contact@granny.dev>")
|
||||
}
|
||||
|
||||
purpurGradle("rebuildPatches").executeOut()
|
||||
project.layout.projectDirectory.path.resolve("patches").also {
|
||||
with(purpurPatches.resolve("server")) {
|
||||
val target = it.resolve("server")
|
||||
copyPatch(this, target, "0001-Purpur-Server-Changes.patch")
|
||||
}
|
||||
|
||||
with(purpurPatches.resolve("api")) {
|
||||
val target = it.resolve("api")
|
||||
copyPatch(this, target, "0001-Purpur-API-Changes.patch")
|
||||
}
|
||||
}
|
||||
|
||||
project.file("gradle.properties").writeText(
|
||||
project.file("gradle.properties").readText()
|
||||
.replace("purpurCommit = .*".toRegex(), "purpurCommit = $latestCommit")
|
||||
)
|
||||
}
|
||||
|
||||
private fun withPufferfish(dir: Path) {
|
||||
val git = Git(dir)
|
||||
val pufferfish = git.clone(
|
||||
"Pufferfish",
|
||||
project.property(property.pufferfishRepoName.get()).toString(),
|
||||
project.property(property.pufferfishBranchName.get()).toString(),
|
||||
dir
|
||||
)
|
||||
val purpur = git.clone(
|
||||
"Purpur",
|
||||
project.property(property.purpurRepoName.get()).toString(),
|
||||
project.property(property.purpurBranchName.get()).toString(),
|
||||
dir
|
||||
)
|
||||
|
||||
project.properties.let {
|
||||
it[property.paperRepoName.get()].toString() to it[property.paperBranchName.get()].toString()
|
||||
}.also {
|
||||
updatePaperCommit(it.first, it.second, pufferfish.resolve("gradle.properties").toFile(), "paperRef=")
|
||||
updatePaperCommit(it.first, it.second, purpur.resolve("gradle.properties").toFile())
|
||||
|
||||
if (project.checkCommit(
|
||||
it.first,
|
||||
it.second,
|
||||
property.paperCommitName.get()
|
||||
)) return@also
|
||||
|
||||
project.createCompareComment(
|
||||
it.first,
|
||||
it.second,
|
||||
project.property(property.paperCommitName.get()).toString()
|
||||
)
|
||||
updatePaperCommit(
|
||||
it.first,
|
||||
it.second,
|
||||
project.file("gradle.properties")
|
||||
)
|
||||
}
|
||||
|
||||
val latestCommit = git("ls-remote", project.property(property.purpurRepoName.get()).toString()).readText()?.lines()
|
||||
?.filterNot { "[a-z0-9]{40}\trefs/heads/${project.property(property.purpurBranchName.get())}".toRegex().matches(it) }
|
||||
?.first()?.split("\t")?.first()
|
||||
?: throw AlwaysUpToDateException("Failed to get latest Purpur commit")
|
||||
|
||||
val purpurGradle = Gradle(purpur)
|
||||
val purpurPatches = purpur.resolve("patches").also {
|
||||
val puffefishPatches = pufferfish.resolve("patches").also { that -> that.toFile().deleteRecursively() }
|
||||
copyPatch(it.resolve("server"), puffefishPatches.resolve("server"), "0001-Pufferfish-Server-Changes.patch")
|
||||
copyPatch(it.resolve("api"), puffefishPatches.resolve("api"), "0001-Pufferfish-API-Changes.patch")
|
||||
}
|
||||
|
||||
Gradle(pufferfish)("applyPatches").executeOut()
|
||||
purpurGradle("applyPatches").executeOut()
|
||||
|
||||
pufferfish.resolve("pufferfish-server").also {
|
||||
val dotGit = it.resolve(".git").toFile()
|
||||
dotGit.deleteRecursively()
|
||||
copySource(it)
|
||||
|
||||
val paper = pufferfish.resolve(".gradle/caches/paperweight/upstreams/paper/Paper-Server")
|
||||
copySource(paper)
|
||||
Git(paper).addCommit("Vanilla Sources", "--author=Vanilla <auto@mated.null>")
|
||||
Thread.sleep(1_000)
|
||||
paper.resolve(".git").toFile().copyRecursively(dotGit, overwrite = true)
|
||||
|
||||
Git(it).addCommit("Pufferfish Server Changes\n\n$pufferfishCommit", "--author=Kevin Raneri <kevin.raneri@gmail.com>")
|
||||
|
||||
val server = purpur.resolve("Purpur-Server")
|
||||
copySource(server)
|
||||
dotGit.copyRecursively(server.resolve(".git").toFile().also { that -> that.deleteRecursively() }, overwrite = true)
|
||||
Git(server).addCommit("Purpur Server Changes\n\n$purpurCommit", "--author=granny <contact@granny.dev>")
|
||||
}
|
||||
|
||||
with(purpur.resolve("Purpur-API")) {
|
||||
pufferfish.resolve("pufferfish-api/.git").toFile()
|
||||
.copyRecursively(resolve(".git").toFile().also { it.deleteRecursively() }, overwrite = true)
|
||||
Git(this).addCommit("Purpur API Changes\n\n$purpurCommit", "--author=granny <contact@granny.dev>")
|
||||
}
|
||||
|
||||
purpurGradle("rebuildPatches").executeOut()
|
||||
project.layout.projectDirectory.path.resolve("patches").also {
|
||||
with(purpurPatches.resolve("server")) {
|
||||
val target = it.resolve("server")
|
||||
copyPatch(this, target, "0001-Pufferfish-Server-Changes.patch")
|
||||
copyPatch(this, target, "0002-Purpur-Server-Changes.patch")
|
||||
}
|
||||
|
||||
with(purpurPatches.resolve("api")) {
|
||||
val target = it.resolve("api")
|
||||
copyPatch(this, target, "0001-Pufferfish-API-Changes.patch")
|
||||
copyPatch(this, target, "0002-Purpur-API-Changes.patch")
|
||||
}
|
||||
}
|
||||
|
||||
project.file("gradle.properties").writeText(project.file("gradle.properties").readText().replace("purpurCommit = .*".toRegex(), "purpurCommit = $latestCommit"))
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun update() {
|
||||
if (project.checkCommit(
|
||||
project.property(property.purpurRepoName.get()).toString(),
|
||||
project.property(property.purpurBranchName.get()).toString(),
|
||||
property.purpurCommitName.get()
|
||||
)) return
|
||||
|
||||
fun update() = with(project) {
|
||||
Git.checkForGit()
|
||||
|
||||
project.createCompareComment(
|
||||
project.property(property.purpurRepoName.get()).toString(),
|
||||
project.property(property.purpurBranchName.get()).toString(),
|
||||
project.property(property.purpurCommitName.get()).toString(),
|
||||
true
|
||||
)
|
||||
val dir = project.layout.cache.resolve("AlwaysUpToDate/UpdatePurpur")
|
||||
if (dir.exists()) dir.toFile().deleteRecursively()
|
||||
if (checkCommit(propValue(property.purpurRepoName), propValue(property.purpurBranchName), property.purpurCommitName.get()))
|
||||
return
|
||||
|
||||
createCompareComment(
|
||||
propValue(property.purpurRepoName), propValue(property.purpurBranchName), propValue(property.purpurCommitName), true
|
||||
)
|
||||
|
||||
val dir = layout.cache.resolve("AlwaysUpToDate/UpdatePurpur")
|
||||
|
||||
if (dir.exists()) dir.toFile().deleteRecursively()
|
||||
dir.createDirectories()
|
||||
|
||||
if (project.property(property.pufferfishToggleName.get()).toString().toBoolean()) withPufferfish(dir)
|
||||
else withoutPufferfish(dir)
|
||||
}
|
||||
val git = Git(dir)
|
||||
val purpur = git.clone("Purpur", propValue(property.purpurRepoName), propValue(property.purpurBranchName), dir)
|
||||
val pufferfish = if (propValue(property.pufferfishToggleName).toBoolean()) git.clone("Pufferfish", propValue(property.pufferfishRepoName), propValue(property.pufferfishBranchName), dir) else null
|
||||
|
||||
private fun copySource(dir: Path) {
|
||||
with(dir.resolve(".gradle/caches/paperweight/mc-dev-sources")) {
|
||||
val target = dir.resolve("src/main")
|
||||
resolve("net").toFile().copyRecursively(target.resolve("java/net").toFile(), overwrite = true)
|
||||
resolve("data").toFile().copyRecursively(target.resolve("resources/data").toFile(), overwrite = true)
|
||||
updateSourceBase(purpur)
|
||||
if (pufferfish != null) updateSourceBase(pufferfish, "paperRef=")
|
||||
|
||||
val latest = getLatest(property.purpurRepoName.get(), property.purpurBranchName.get())
|
||||
|
||||
val gradle = Gradle(purpur)
|
||||
val patches = purpur.resolve("patches").also { patch ->
|
||||
if (pufferfish == null) return@also
|
||||
|
||||
val base = pufferfish.resolve("patches").also { it.toFile().deleteRecursively() }
|
||||
patch.resolve("server").copyPatch(base.resolve("server"), "Pufferfish-Server-Changes")
|
||||
patch.resolve("api").copyPatch(base.resolve("api"), "Pufferfish-API-Changes")
|
||||
Gradle(pufferfish)("applyPatches").executeOut()
|
||||
}
|
||||
gradle("applyPatches").executeOut()
|
||||
|
||||
(pufferfish?.resolve("pufferfish-server") ?: purpur.resolve("Purpur-Server")).let {
|
||||
val dotGit = it.resolve(".git").toFile().also(File::deleteRecursively)
|
||||
copySource(it)
|
||||
|
||||
val paper = it.resolve("../.gradle/caches/paperweight/upstreams/paper/Paper-Server")
|
||||
copySource(paper)
|
||||
|
||||
Git(paper).addCommit("Vanilla Sources", "--author=Vanilla <auto@mated.null>")
|
||||
Thread.sleep(1_000)
|
||||
paper.resolve(".git").toFile().copyRecursively(dotGit, overwrite = true)
|
||||
|
||||
if (pufferfish == null)
|
||||
return@let Git(it).addCommit("Purpur Server Changes\n\n$purpurHeader", "--author=granny <contact@granny.dev>")
|
||||
|
||||
Git(it).addCommit("Pufferfish Server Changes\n\n$pufferfishHeader", "--author=Kevin Raneri <kevin.raneri@gmail.com>")
|
||||
|
||||
purpur.resolve("Purpur-Server").let { that ->
|
||||
val purpurDotGit = that.resolve(".git").toFile().also(File::deleteRecursively)
|
||||
|
||||
copySource(that)
|
||||
dotGit.copyRecursively(purpurDotGit, overwrite = true)
|
||||
Git(that).addCommit("Purpur Server Changes\n\n$purpurHeader", "--author=granny <contact@granny.dev>")
|
||||
}
|
||||
}
|
||||
|
||||
with(purpur.resolve("Purpur-API")) {
|
||||
val dotGit = resolve(".git").toFile().also(File::deleteRecursively)
|
||||
|
||||
(pufferfish?.resolve("pufferfish-api/.git")?.toFile()?.also {
|
||||
it.deleteRecursively()
|
||||
it.resolve("../.gradle/caches/paperweight/upstreams/paper/Paper-API/.git").copyRecursively(it, overwrite = true)
|
||||
Git(it).addCommit("Pufferfish API Changes\n\n$pufferfishHeader", "--author=Kevin Raneri <kevin.raneri@gmail.com>")
|
||||
} ?: resolve("../.gradle/caches/paperweight/upstreams/paper/Paper-API/.git").toFile())
|
||||
.copyRecursively(dotGit, overwrite = true)
|
||||
|
||||
Git(this).addCommit("Purpur API Changes\n\n$purpurHeader", "--author=granny <contact@granny.dev>")
|
||||
}
|
||||
|
||||
gradle("rebuildPatches").executeOut()
|
||||
with(layout.projectDirectory.path.resolve("patches")) {
|
||||
patches.resolve("server").copyPatch(resolve("server"),
|
||||
if (pufferfish == null) "" else "Pufferfish-Server-Changes",
|
||||
"Purpur-Server-Changes"
|
||||
)
|
||||
|
||||
patches.resolve("api").copyPatch(resolve("api"),
|
||||
if (pufferfish == null) "" else "Pufferfish-API-Changes",
|
||||
"Purpur-API-Changes"
|
||||
)
|
||||
}
|
||||
|
||||
file("gradle.properties").let {
|
||||
it.writeText(it.readText().replace("purpurCommit = .*".toRegex(), "purpurCommit = $latest"))
|
||||
}
|
||||
}
|
||||
|
||||
private fun copyPatch(from: Path, to: Path, name: String) {
|
||||
with(from.resolve(name)) {
|
||||
if (exists()) toFile().copyTo(to.resolve(name).toFile(), overwrite = true)
|
||||
else from.toFile().walk().filter { it.name.endsWith(name.substring(4)) }.first().copyTo(to.resolve(name).toFile(), overwrite = true)
|
||||
private fun Project.updateSourceBase(source: Path, regex: String? = null) = properties
|
||||
.let { it[property.paperRepoName.get()].toString() to it[property.paperBranchName.get()].toString() }
|
||||
.let {
|
||||
updatePaperCommit(it.first, it.second, source.resolve("gradle.properties").toFile(), regex ?: "paperCommit = ")
|
||||
|
||||
if (checkCommit(it.first, it.second, property.paperCommitName.get())) return@let
|
||||
|
||||
createCompareComment(it.first, it.second, propValue(property.paperCommitName))
|
||||
updatePaperCommit(it.first, it.second, file("gradle.properties"))
|
||||
}
|
||||
|
||||
private fun copySource(dir: Path) = with(dir.resolve(".gradle/caches/paperweight/mc-dev-sources")) {
|
||||
val target = dir.resolve("src/main")
|
||||
resolve("net").toFile().copyRecursively(target.resolve("java/net").toFile(), overwrite = true)
|
||||
resolve("data").toFile().copyRecursively(target.resolve("resources/data").toFile(), overwrite = true)
|
||||
}
|
||||
|
||||
private fun Path.copyPatch(to: Path, vararg name: String) = listDirectoryEntries()
|
||||
.filter { entry -> name.any { it.endsWith(entry.name.substring(5) + ".patch") } }.map(Path::toFile)
|
||||
.forEachIndexed { count, patch ->
|
||||
patch.copyTo(
|
||||
to.resolve(count.toString().padStart(4, '0') + "-" + name.first { patch.name.substring(5) == "$it.patch" }).toFile(),
|
||||
overwrite = true
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,11 +4,8 @@ import org.gradle.api.DefaultTask
|
||||
|
||||
abstract class Task : DefaultTask() {
|
||||
|
||||
protected open fun init() {
|
||||
}
|
||||
protected abstract fun init()
|
||||
|
||||
init {
|
||||
this.init()
|
||||
}
|
||||
init { this.init() }
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ package org.plazmamc.alwaysuptodate.utils
|
||||
|
||||
import io.papermc.paperweight.util.path
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.provider.Property
|
||||
import java.nio.file.Path
|
||||
|
||||
val Project.pathIO: Path get() = layout.projectDirectory.path
|
||||
|
||||
fun Project.propValue(name: Property<String>) =
|
||||
this.property(name.get()) as String
|
||||
|
||||
@@ -25,5 +25,5 @@ pufferfishRepo = https://github.com/PlazmaMC/Pufferfish
|
||||
pufferfishBranch = ver/1.20
|
||||
usePufferfish = true
|
||||
|
||||
paperCommit = 347bbe389786d5cdae7cd1c6ec32cacba2a9aac7
|
||||
paperCommit = 23fe1166d4fa24ec81243f79e8dbb01dee4ab948
|
||||
purpurCommit = a5b3783e35e3486ec3b0829e54d3eff665030bb7
|
||||
|
||||
Reference in New Issue
Block a user