Improve Server starter 'steamwar.devserver.gradle'

See build.gradle.kts of BauSystem
This commit is contained in:
2025-04-17 09:56:41 +02:00
parent 230ac09b61
commit 50543ddd4e
2 changed files with 132 additions and 0 deletions
+21
View File
@@ -1,3 +1,5 @@
import DevServer
/*
* This file is a part of the SteamWar software.
*
@@ -20,6 +22,7 @@
plugins {
`java-library`
alias(libs.plugins.shadow)
steamwar.devserver
}
tasks.build {
@@ -34,3 +37,21 @@ dependencies {
implementation(project(":BauSystem:BauSystem_20"))
implementation(project(":BauSystem:BauSystem_21"))
}
tasks.register<DevServer>("DevBau20") {
group = "run"
description = "Run a 1.20 Dev Bau"
dependsOn(":SpigotCore:shadowJar")
dependsOn(":BauSystem:shadowJar")
worldName = "245"
template = "Bau20"
}
tasks.register<DevServer>("DevBau21") {
group = "run"
description = "Run a 1.21 Dev Bau"
dependsOn(":SpigotCore:shadowJar")
dependsOn(":BauSystem:shadowJar")
worldName = "245"
template = "Bau21"
}
+111
View File
@@ -0,0 +1,111 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.bundling.AbstractArchiveTask
plugins {
}
class DevServer extends DefaultTask {
@Input
worldName = ""
@Input
template = ""
DevServer() {
super()
doLast {
uploadDependencies()
startDevServer()
}
finalizedBy(new Finalizer())
}
@Internal
def BufferedWriter processInput;
class Finalizer extends DefaultTask {
Finalizer() {
super()
doLast {
if (processInput != null) {
processInput.write("stop\n")
processInput.flush()
}
}
}
}
void uploadDependencies() {
this.dependsOn.forEach {
Project resolved;
if (it instanceof Project) {
resolved = (Project) it;
} else if (it instanceof String) {
resolved = project.findProject(it.substring(0, it.lastIndexOf(':')))
} else {
throw new GradleException("Illegal argument for uploading dependencies")
}
def archive = ((AbstractArchiveTask) resolved.tasks.findByName("shadowJar")).archiveFile.get().asFile
println("Uploading $archive to ~/plugins/${template}")
new ProcessBuilder("scp", archive.absolutePath, "sw:~/plugins/$template/${archive.name.replace("-all", "")}").start().waitFor()
println("Uploaded $archive to ~/plugins/${template}")
}
}
void startDevServer() {
println("Starting $template with world $worldName and plugins in ~/plugins/${template}")
def process = new ProcessBuilder("ssh", "sw", "-T", "dev.py -w $worldName -p plugins/$template $template").start();
def running = true;
def processOutput = new BufferedReader(new InputStreamReader(process.inputStream))
new Thread({
while (running) {
if (processOutput.ready()) {
println(processOutput.readLine())
}
}
}).start()
processInput = new BufferedWriter(new OutputStreamWriter(process.outputStream))
def input = new BufferedReader(new InputStreamReader(System.in))
new Thread({
while (running) {
def text = input.readLine()
if (text == null) break
processInput.write(text)
processInput.newLine()
processInput.flush()
}
}).start()
process.waitFor()
processInput = null
running = false
}
}