Files
purpur-quest-board/build.gradle.kts
dmg 7496564b94
CI / build (pull_request) Successful in 49s
CI / build (push) Successful in 1m7s
feat(platform): support Purpur 26.3
2026-10-16 23:49:39 -04:00

142 lines
4.7 KiB
Kotlin

import java.net.URI
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.security.MessageDigest
plugins {
java
}
group = "games.dmg"
version = providers.gradleProperty("releaseVersion")
.orElse("0.1.0-SNAPSHOT")
.get()
repositories {
mavenCentral()
maven("https://repo.purpurmc.org/snapshots/")
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
}
tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.addAll(listOf("-Xlint:all,-deprecation,-removal", "-Werror"))
}
dependencies {
compileOnly("org.purpurmc.purpur:purpur-api:26.3.build.2651-stable")
testImplementation("org.purpurmc.purpur:purpur-api:26.3.build.2651-stable")
testImplementation(platform("org.junit:junit-bom:5.13.4"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.mockito:mockito-core:5.18.0")
testImplementation("org.yaml:snakeyaml:2.4")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
val purpurVersion = "26.3"
val purpurBuild = "2651"
val purpurRuntimeSha256 = "0677c1febecfbc2e5b0a7f76abd647b70a1f38d3cbdf3dd6a82e401b4262a598"
val purpurRuntimeJar = layout.projectDirectory.file(".gradle/purpur-runtime/purpur-$purpurVersion-$purpurBuild.jar")
fun sha256(file: File): String {
val digest = MessageDigest.getInstance("SHA-256")
file.inputStream().buffered().use { input ->
val buffer = ByteArray(8192)
while (true) {
val read = input.read(buffer)
if (read < 0) break
digest.update(buffer, 0, read)
}
}
return digest.digest().joinToString("") { "%02x".format(it) }
}
val downloadPurpurRuntime = tasks.register("downloadPurpurRuntime") {
description = "Downloads and verifies the exact supported Purpur runtime"
group = "verification"
outputs.file(purpurRuntimeJar)
outputs.upToDateWhen { false }
doLast {
val destination = purpurRuntimeJar.asFile
destination.parentFile.mkdirs()
if (!destination.isFile || sha256(destination) != purpurRuntimeSha256) {
Files.deleteIfExists(destination.toPath())
val temporary = Files.createTempFile(destination.parentFile.toPath(), destination.name, ".part")
try {
val connection = URI(
"https://api.purpurmc.org/v2/purpur/$purpurVersion/$purpurBuild/download"
).toURL().openConnection().apply {
connectTimeout = 30_000
readTimeout = 120_000
}
connection.getInputStream().use { input ->
Files.newOutputStream(temporary).use(input::copyTo)
}
val actual = sha256(temporary.toFile())
check(actual == purpurRuntimeSha256) {
"Purpur runtime SHA-256 mismatch: expected $purpurRuntimeSha256, got $actual"
}
Files.move(
temporary,
destination.toPath(),
StandardCopyOption.ATOMIC_MOVE,
StandardCopyOption.REPLACE_EXISTING
)
} finally {
Files.deleteIfExists(temporary)
}
}
check(sha256(destination) == purpurRuntimeSha256) {
"Cached Purpur runtime failed SHA-256 verification"
}
}
}
val java25Launcher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(25)
}
val pluginJar = tasks.jar.flatMap { it.archiveFile }
tasks.test {
useJUnitPlatform()
dependsOn(tasks.jar)
exclude("**/PurpurRuntimeLifecycleTest.class")
javaLauncher = java25Launcher
systemProperty("distribution.jar", pluginJar.get().asFile.absolutePath)
systemProperty("distribution.version", project.version.toString())
}
val purpurRuntimeTest = tasks.register<Test>("purpurRuntimeTest") {
description = "Loads, enables, and disables the plugin on the supported Purpur runtime"
group = "verification"
dependsOn(downloadPurpurRuntime, tasks.jar)
testClassesDirs = sourceSets.test.get().output.classesDirs
classpath = sourceSets.test.get().runtimeClasspath
useJUnitPlatform()
include("**/PurpurRuntimeLifecycleTest.class")
javaLauncher = java25Launcher
systemProperty("purpur.runtime.jar", purpurRuntimeJar.asFile.absolutePath)
systemProperty("purpur.runtime.version", purpurVersion)
systemProperty("purpur.runtime.build", purpurBuild)
systemProperty("distribution.jar", pluginJar.get().asFile.absolutePath)
shouldRunAfter(tasks.test)
}
tasks.check {
dependsOn(purpurRuntimeTest)
}
val pluginVersion = version
tasks.processResources {
filesMatching("plugin.yml") {
expand("version" to pluginVersion)
}
}