mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-03 05:30:55 +00:00
Gradle: Implement setupPaperServer action which downloads Paper and links plugin JARs.
This commit is contained in:
parent
763b61ba04
commit
01999eadd7
3
.gitignore
vendored
3
.gitignore
vendored
@ -116,3 +116,6 @@ run/
|
|||||||
|
|
||||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||||
!gradle-wrapper.jar
|
!gradle-wrapper.jar
|
||||||
|
|
||||||
|
# Foundation Server
|
||||||
|
/server
|
||||||
|
@ -5,9 +5,7 @@ import java.io.FileWriter
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
java
|
java
|
||||||
id("org.jetbrains.kotlin.jvm") version "1.6.10" apply false
|
id("foundation-gradle")
|
||||||
id("org.jetbrains.kotlin.plugin.serialization") version "1.6.10" apply false
|
|
||||||
id("com.github.johnrengelman.shadow") version "7.1.1" apply false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Project.isFoundationPlugin() = name.startsWith("foundation-")
|
fun Project.isFoundationPlugin() = name.startsWith("foundation-")
|
||||||
@ -23,6 +21,7 @@ allprojects {
|
|||||||
name = "papermc-repo"
|
name = "papermc-repo"
|
||||||
url = uri("https://papermc.io/repo/repository/maven-public/")
|
url = uri("https://papermc.io/repo/repository/maven-public/")
|
||||||
}
|
}
|
||||||
|
|
||||||
maven {
|
maven {
|
||||||
name = "sonatype"
|
name = "sonatype"
|
||||||
url = uri("https://oss.sonatype.org/content/groups/public/")
|
url = uri("https://oss.sonatype.org/content/groups/public/")
|
||||||
@ -135,3 +134,8 @@ subprojects {
|
|||||||
dependsOn("shadowJar")
|
dependsOn("shadowJar")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.setupPaperServer {
|
||||||
|
minecraftServerPath = "server"
|
||||||
|
paperVersionGroup = "1.18"
|
||||||
|
}
|
||||||
|
18
buildSrc/build.gradle.kts
Normal file
18
buildSrc/build.gradle.kts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
plugins {
|
||||||
|
`kotlin-dsl`
|
||||||
|
kotlin("plugin.serialization") version "1.5.31"
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
|
||||||
|
implementation("org.jetbrains.kotlin:kotlin-serialization:1.6.10")
|
||||||
|
implementation("gradle.plugin.com.github.johnrengelman:shadow:7.1.1")
|
||||||
|
implementation("com.google.code.gson:gson:2.8.9")
|
||||||
|
}
|
||||||
|
|
||||||
|
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
java.targetCompatibility = JavaVersion.VERSION_1_8
|
@ -0,0 +1,10 @@
|
|||||||
|
package cloud.kubelet.foundation.gradle
|
||||||
|
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
|
||||||
|
class FoundationGradlePlugin : Plugin<Project> {
|
||||||
|
override fun apply(project: Project) {
|
||||||
|
project.tasks.create("setupPaperServer", SetupPaperServer::class.java)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package cloud.kubelet.foundation.gradle
|
||||||
|
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import java.net.URI
|
||||||
|
import java.net.http.HttpClient
|
||||||
|
import java.net.http.HttpRequest
|
||||||
|
import java.net.http.HttpResponse
|
||||||
|
|
||||||
|
class PaperVersionClient(val client: HttpClient = HttpClient.newHttpClient()) {
|
||||||
|
private val apiBaseUrl = URI.create("https://papermc.io/api/v2/")
|
||||||
|
private val gson = Gson()
|
||||||
|
|
||||||
|
fun getVersionBuilds(group: String): List<PaperBuild> {
|
||||||
|
val response = client.send(
|
||||||
|
HttpRequest.newBuilder()
|
||||||
|
.GET()
|
||||||
|
.uri(apiBaseUrl.resolve("projects/paper/version_group/${group}/builds"))
|
||||||
|
.build(),
|
||||||
|
HttpResponse.BodyHandlers.ofString()
|
||||||
|
)
|
||||||
|
|
||||||
|
val body = response.body()
|
||||||
|
val root = gson.fromJson(body, PaperVersionRoot::class.java)
|
||||||
|
return root.builds
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resolveDownloadUrl(build: PaperBuild, download: PaperVersionDownload): URI =
|
||||||
|
apiBaseUrl.resolve("projects/paper/versions/${build.version}/builds/${build.build}/downloads/${download.name}")
|
||||||
|
|
||||||
|
data class PaperVersionRoot(
|
||||||
|
val builds: List<PaperBuild>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class PaperBuild(
|
||||||
|
val version: String,
|
||||||
|
val build: Int,
|
||||||
|
val downloads: Map<String, PaperVersionDownload>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class PaperVersionDownload(
|
||||||
|
val name: String,
|
||||||
|
val sha256: String
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package cloud.kubelet.foundation.gradle
|
||||||
|
|
||||||
|
import org.gradle.api.DefaultTask
|
||||||
|
import org.gradle.api.tasks.Input
|
||||||
|
import org.gradle.api.tasks.TaskAction
|
||||||
|
import java.nio.file.Files
|
||||||
|
|
||||||
|
open class SetupPaperServer : DefaultTask() {
|
||||||
|
@get:Input
|
||||||
|
lateinit var paperVersionGroup: String
|
||||||
|
|
||||||
|
@get:Input
|
||||||
|
lateinit var minecraftServerPath: String
|
||||||
|
|
||||||
|
@TaskAction
|
||||||
|
fun downloadPaperTask() {
|
||||||
|
val minecraftServerDirectory = project.file(minecraftServerPath)
|
||||||
|
val client = PaperVersionClient()
|
||||||
|
val builds = client.getVersionBuilds(paperVersionGroup)
|
||||||
|
val build = builds.last()
|
||||||
|
val download = build.downloads["application"]!!
|
||||||
|
val url = client.resolveDownloadUrl(build, download)
|
||||||
|
|
||||||
|
if (!minecraftServerDirectory.exists()) {
|
||||||
|
minecraftServerDirectory.mkdirs()
|
||||||
|
}
|
||||||
|
|
||||||
|
ant.invokeMethod(
|
||||||
|
"get", mapOf(
|
||||||
|
"src" to url.toString(),
|
||||||
|
"dest" to project.file("${minecraftServerPath}/paper.jar").absolutePath
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val paperPluginsDirectory = minecraftServerDirectory.resolve("plugins")
|
||||||
|
|
||||||
|
if (!paperPluginsDirectory.exists()) {
|
||||||
|
paperPluginsDirectory.mkdirs()
|
||||||
|
}
|
||||||
|
|
||||||
|
for (project in project.subprojects) {
|
||||||
|
if (!project.name.startsWith("foundation-")) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
val pluginJarFile = project.buildDir.resolve("libs/${project.name}-DEV-plugin.jar")
|
||||||
|
val pluginLinkFile = paperPluginsDirectory.resolve("${project.name}.jar")
|
||||||
|
if (pluginLinkFile.exists()) {
|
||||||
|
pluginLinkFile.delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
Files.createSymbolicLink(pluginLinkFile.toPath(), pluginJarFile.toPath())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
implementation-class=cloud.kubelet.foundation.gradle.FoundationGradlePlugin
|
Loading…
Reference in New Issue
Block a user