mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-02 21:20:55 +00:00
Initial port to Concrete.
This commit is contained in:
parent
b650e9f8a7
commit
cf2a812b75
@ -1,18 +0,0 @@
|
||||
image: gradle:7.3-jdk17
|
||||
|
||||
variables:
|
||||
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
script: gradle --build-cache assemble
|
||||
cache:
|
||||
key: "$CI_COMMIT_REF_NAME"
|
||||
policy: push
|
||||
paths:
|
||||
- build
|
||||
- .gradle
|
||||
artifacts:
|
||||
paths:
|
||||
- "build/manifests/update.json"
|
||||
- "**/build/libs/*-plugin.jar"
|
@ -1,20 +1,14 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import gay.pizza.foundation.gradle.FoundationProjectPlugin
|
||||
import gay.pizza.foundation.gradle.isFoundationPlugin
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
java
|
||||
id("gay.pizza.foundation.gradle")
|
||||
id("gay.pizza.foundation.concrete-root") version "0.6.0-SNAPSHOT"
|
||||
id("gay.pizza.foundation.concrete-plugin") version "0.6.0-SNAPSHOT" apply false
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = "papermc"
|
||||
url = uri("https://papermc.io/repo/repository/maven-public/")
|
||||
}
|
||||
|
||||
maven {
|
||||
name = "sonatype"
|
||||
@ -23,19 +17,15 @@ allprojects {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.assemble {
|
||||
dependsOn("updateManifests")
|
||||
}
|
||||
|
||||
version = "0.2"
|
||||
|
||||
subprojects {
|
||||
plugins.apply("org.jetbrains.kotlin.jvm")
|
||||
plugins.apply("org.jetbrains.kotlin.plugin.serialization")
|
||||
plugins.apply("com.github.johnrengelman.shadow")
|
||||
plugins.apply(FoundationProjectPlugin::class)
|
||||
plugins.apply("gay.pizza.foundation.concrete-plugin")
|
||||
|
||||
group = "lgbt.mystic"
|
||||
group = "gay.pizza.foundation"
|
||||
|
||||
dependencies {
|
||||
// Kotlin dependencies
|
||||
@ -53,9 +43,6 @@ subprojects {
|
||||
// Persistence
|
||||
implementation("org.jetbrains.xodus:xodus-openAPI:1.3.232")
|
||||
implementation("org.jetbrains.xodus:xodus-entity-store:1.3.232")
|
||||
|
||||
// Paper API
|
||||
compileOnly("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
java {
|
||||
@ -66,32 +53,14 @@ subprojects {
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs =
|
||||
freeCompilerArgs + "-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi"
|
||||
freeCompilerArgs += "-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
val props = mapOf("version" to version)
|
||||
inputs.properties(props)
|
||||
filteringCharset = "UTF-8"
|
||||
filesMatching("plugin.yml") {
|
||||
expand(props)
|
||||
}
|
||||
}
|
||||
|
||||
if (project.isFoundationPlugin()) {
|
||||
tasks.withType<ShadowJar> {
|
||||
archiveClassifier.set("plugin")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.assemble {
|
||||
dependsOn("shadowJar")
|
||||
}
|
||||
}
|
||||
|
||||
foundation {
|
||||
concrete {
|
||||
minecraftServerPath.set("server")
|
||||
paperVersionGroup.set("1.18")
|
||||
paperApiVersion.set("1.18.2-R0.1-SNAPSHOT")
|
||||
acceptServerEula.set(true)
|
||||
}
|
||||
|
@ -1,28 +0,0 @@
|
||||
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")
|
||||
implementation("org.bouncycastle:bcprov-jdk15on:1.70")
|
||||
}
|
||||
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
java.targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("foundation") {
|
||||
id = "gay.pizza.foundation.gradle"
|
||||
implementationClass = "gay.pizza.foundation.gradle.FoundationGradlePlugin"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package gay.pizza.foundation.gradle
|
||||
|
||||
import org.gradle.api.provider.Property
|
||||
|
||||
interface FoundationExtension {
|
||||
val paperVersionGroup: Property<String>
|
||||
val minecraftServerPath: Property<String>
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package gay.pizza.foundation.gradle
|
||||
|
||||
import com.google.gson.Gson
|
||||
|
||||
object FoundationGlobals {
|
||||
val gson = Gson()
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package gay.pizza.foundation.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.create
|
||||
|
||||
class FoundationGradlePlugin : Plugin<Project> {
|
||||
override fun apply(project: Project) {
|
||||
project.extensions.create<gay.pizza.foundation.gradle.FoundationExtension>("foundation")
|
||||
val setupPaperServer = project.tasks.create<gay.pizza.foundation.gradle.SetupPaperServer>("setupPaperServer")
|
||||
project.afterEvaluate { ->
|
||||
setupPaperServer.dependsOn(*project.subprojects
|
||||
.filter { it.name.startsWith("foundation-") }
|
||||
.map { it.tasks.getByName("shadowJar") }
|
||||
.toTypedArray()
|
||||
)
|
||||
}
|
||||
val runPaperServer = project.tasks.create<gay.pizza.foundation.gradle.RunPaperServer>("runPaperServer")
|
||||
runPaperServer.dependsOn(setupPaperServer)
|
||||
|
||||
val updateManifests = project.tasks.create<gay.pizza.foundation.gradle.UpdateManifestTask>("updateManifests")
|
||||
project.tasks.getByName("assemble").dependsOn(updateManifests)
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package gay.pizza.foundation.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
|
||||
class FoundationProjectPlugin : Plugin<Project> {
|
||||
override fun apply(project: Project) {
|
||||
val versionWithBuild = if (System.getenv("CI_PIPELINE_IID") != null) {
|
||||
project.rootProject.version.toString() + ".${System.getenv("CI_PIPELINE_IID")}"
|
||||
} else {
|
||||
"DEV"
|
||||
}
|
||||
|
||||
project.version = versionWithBuild
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package gay.pizza.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 gson: Gson = gay.pizza.foundation.gradle.FoundationGlobals.gson
|
||||
) {
|
||||
private val apiBaseUrl = URI.create("https://papermc.io/api/v2/")
|
||||
|
||||
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
|
||||
)
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package gay.pizza.foundation.gradle
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
import java.io.File
|
||||
import java.util.jar.JarFile
|
||||
|
||||
open class RunPaperServer : DefaultTask() {
|
||||
init {
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun runPaperServer() {
|
||||
val foundation = project.extensions.getByType<gay.pizza.foundation.gradle.FoundationExtension>()
|
||||
|
||||
val minecraftServerDirectory = project.file(foundation.minecraftServerPath.get())
|
||||
val paperJarFile = minecraftServerDirectory.resolve("paper.jar")
|
||||
val mainClassName = readMainClass(paperJarFile)
|
||||
|
||||
project.javaexec {
|
||||
classpath(paperJarFile.absolutePath)
|
||||
workingDir(minecraftServerDirectory)
|
||||
args("nogui")
|
||||
mainClass.set(mainClassName)
|
||||
}
|
||||
}
|
||||
|
||||
private fun readMainClass(file: File): String = JarFile(file).use { jar ->
|
||||
jar.manifest.mainAttributes.getValue("Main-Class")!!
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package gay.pizza.foundation.gradle
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.api.tasks.options.Option
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
open class SetupPaperServer : DefaultTask() {
|
||||
init {
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
|
||||
@get:Input
|
||||
@set:Option(option = "update", description = "Update Paper Server")
|
||||
var shouldUpdatePaperServer = false
|
||||
|
||||
private val paperVersionClient = PaperVersionClient()
|
||||
|
||||
@TaskAction
|
||||
fun downloadPaperTask() {
|
||||
val foundation = project.extensions.getByType<gay.pizza.foundation.gradle.FoundationExtension>()
|
||||
val minecraftServerDirectory = project.file(foundation.minecraftServerPath.get())
|
||||
|
||||
if (!minecraftServerDirectory.exists()) {
|
||||
minecraftServerDirectory.mkdirs()
|
||||
}
|
||||
|
||||
val paperJarFile = project.file("${foundation.minecraftServerPath.get()}/paper.jar")
|
||||
if (!paperJarFile.exists() || shouldUpdatePaperServer) {
|
||||
downloadLatestBuild(foundation.paperVersionGroup.get(), paperJarFile)
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
private fun downloadLatestBuild(paperVersionGroup: String, paperJarFile: File) {
|
||||
val builds = paperVersionClient.getVersionBuilds(paperVersionGroup)
|
||||
val build = builds.last()
|
||||
val download = build.downloads["application"]!!
|
||||
val url = paperVersionClient.resolveDownloadUrl(build, download)
|
||||
val downloader = SmartDownloader(paperJarFile.toPath(), url, download.sha256)
|
||||
if (downloader.download()) {
|
||||
logger.lifecycle("Installed Paper Server ${build.version} build ${build.build}")
|
||||
} else {
|
||||
logger.lifecycle("Paper Server ${build.version} build ${build.build} is up-to-date")
|
||||
}
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
package gay.pizza.foundation.gradle
|
||||
|
||||
import java.net.URI
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.security.MessageDigest
|
||||
|
||||
class SmartDownloader(
|
||||
private val localFilePath: Path,
|
||||
private val remoteDownloadUrl: URI,
|
||||
private val sha256: String
|
||||
) {
|
||||
fun download(): Boolean {
|
||||
val hashResult = checkLocalFileHash()
|
||||
if (hashResult != HashResult.ValidHash) {
|
||||
downloadRemoteFile()
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun downloadRemoteFile() {
|
||||
val url = remoteDownloadUrl.toURL()
|
||||
val remoteFileStream = url.openStream()
|
||||
val localFileStream = Files.newOutputStream(localFilePath)
|
||||
remoteFileStream.transferTo(localFileStream)
|
||||
val hashResult = checkLocalFileHash()
|
||||
if (hashResult != HashResult.ValidHash) {
|
||||
throw RuntimeException("Download of $remoteDownloadUrl did not result in valid hash.")
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkLocalFileHash(): HashResult {
|
||||
if (!Files.exists(localFilePath)) {
|
||||
return HashResult.DoesNotExist
|
||||
}
|
||||
|
||||
val digest = MessageDigest.getInstance("SHA-256")
|
||||
val localFileStream = Files.newInputStream(localFilePath)
|
||||
val buffer = ByteArray(16 * 1024)
|
||||
|
||||
while (true) {
|
||||
val size = localFileStream.read(buffer)
|
||||
if (size <= 0) {
|
||||
break
|
||||
}
|
||||
|
||||
val bytes = buffer.take(size).toByteArray()
|
||||
digest.update(bytes)
|
||||
}
|
||||
|
||||
val sha256Bytes = digest.digest()
|
||||
val localSha256Hash = bytesToHex(sha256Bytes)
|
||||
return if (localSha256Hash.equals(sha256, ignoreCase = true)) {
|
||||
HashResult.ValidHash
|
||||
} else {
|
||||
HashResult.InvalidHash
|
||||
}
|
||||
}
|
||||
|
||||
private fun bytesToHex(hash: ByteArray): String {
|
||||
val hexString = StringBuilder(2 * hash.size)
|
||||
for (i in hash.indices) {
|
||||
val hex = Integer.toHexString(0xff and hash[i].toInt())
|
||||
if (hex.length == 1) {
|
||||
hexString.append('0')
|
||||
}
|
||||
hexString.append(hex)
|
||||
}
|
||||
return hexString.toString()
|
||||
}
|
||||
|
||||
enum class HashResult {
|
||||
DoesNotExist,
|
||||
InvalidHash,
|
||||
ValidHash
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package gay.pizza.foundation.gradle
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
|
||||
open class UpdateManifestTask : DefaultTask() {
|
||||
@TaskAction
|
||||
fun update() {
|
||||
val manifestsDir = ensureManifestsDir()
|
||||
val updateFile = manifestsDir.resolve("update.json")
|
||||
val rootPath = project.rootProject.rootDir.toPath()
|
||||
val updateManifest = project.findPluginProjects().mapNotNull { project ->
|
||||
val paths = project.shadowJarOutputs.allFilesRelativeToPath(rootPath)
|
||||
if (paths.isNotEmpty()) {
|
||||
project.name to mapOf(
|
||||
"version" to project.version,
|
||||
"artifacts" to paths.map { it.toUnixString() }
|
||||
)
|
||||
} else null
|
||||
}.toMap()
|
||||
|
||||
Files.writeString(updateFile, gay.pizza.foundation.gradle.FoundationGlobals.gson.toJson(updateManifest))
|
||||
}
|
||||
|
||||
private fun ensureManifestsDir(): Path {
|
||||
val manifestsDir = project.buildDir.resolve("manifests")
|
||||
manifestsDir.mkdirs()
|
||||
return manifestsDir.toPath()
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package gay.pizza.foundation.gradle
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.TaskOutputs
|
||||
import java.nio.file.FileSystems
|
||||
import java.nio.file.Path
|
||||
|
||||
fun Project.isFoundationPlugin() = name.startsWith("foundation-")
|
||||
|
||||
fun Project.findPluginProjects() = rootProject.subprojects.filter { project -> project.isFoundationPlugin() }
|
||||
|
||||
val Project.shadowJarOutputs: TaskOutputs
|
||||
get() = project.tasks.getByName("shadowJar").outputs
|
||||
|
||||
fun TaskOutputs.allFilesRelativeToPath(root: Path): List<Path> = files.map { root.relativize(it.toPath()) }
|
||||
|
||||
fun Path.toUnixString() = toString().replace(FileSystems.getDefault().separator, "/")
|
@ -1,5 +1,13 @@
|
||||
rootProject.name = "foundation"
|
||||
|
||||
pluginManagement {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
maven(url = "https://gitlab.com/api/v4/projects/42873094/packages/maven")
|
||||
}
|
||||
}
|
||||
|
||||
include(
|
||||
":foundation-core",
|
||||
":foundation-bifrost",
|
||||
|
Loading…
Reference in New Issue
Block a user