From 25f43b154280049e4814680d41797fb191ef2ba6 Mon Sep 17 00:00:00 2001 From: Greg Date: Wed, 20 Mar 2024 01:41:54 +0000 Subject: [PATCH] Fix release script bundling (#499) * Store the scripts in resources --- game/build.gradle.kts | 50 ++++++-------------------- game/src/main/resources/run-server.bat | 4 +++ game/src/main/resources/run-server.sh | 15 ++++++++ 3 files changed, 29 insertions(+), 40 deletions(-) create mode 100644 game/src/main/resources/run-server.bat create mode 100644 game/src/main/resources/run-server.sh diff --git a/game/build.gradle.kts b/game/build.gradle.kts index 53c12129b..93960df0d 100644 --- a/game/build.gradle.kts +++ b/game/build.gradle.kts @@ -43,43 +43,14 @@ application { } tasks { - val name = "void-server-${version}" named("shadowJar") { minimize { exclude(dependency("ch.qos.logback:logback-classic:.*")) } - archiveBaseName.set(name) + archiveBaseName.set("void-server-${version}") archiveClassifier.set("") archiveVersion.set("") } - register("buildScripts") { - var file = layout.buildDirectory.get().file("scripts/run-server.bat").asFile - file.parentFile.mkdirs() - file.writeText(""" - @echo off - title Void Game Sever - java -jar $name.jar - pause - """.trimIndent()) - file = layout.buildDirectory.get().file("scripts/run-server.sh").asFile - file.writeText(""" - #!/usr/bin/env bash - title="Void Game Server" - echo -e '\033]2;'${'$'}title'\007' - # Early exit on cancel - cleanup() { - echo "" - exit 1 - } - trap cleanup INT - java -jar $name.jar - # Stop console closing - if [ ${'$'}? -ne 0 ]; then - echo "Error: The Java application exited with a non-zero status." - read -p "Press enter to continue..." - fi - """.trimIndent()) - } } distributions { @@ -87,7 +58,6 @@ distributions { distributionBaseName = "void" contents { from(tasks["shadowJar"]) - from(tasks["buildScripts"]) from("../data/definitions/") { into("data/definitions") } @@ -105,14 +75,14 @@ distributions { from(layout.buildDirectory.dir("tmp/empty/")) { into("data") } - from(layout.projectDirectory.dir("src/main/resources/game.properties")) - from(layout.buildDirectory.dir("scripts/run-server.bat")) - from(layout.buildDirectory.dir("scripts/run-server.sh")) + val resourcesDir = layout.projectDirectory.dir("src/main/resources") + from(resourcesDir.file("game.properties")) + val bat = resourcesDir.file("run-server.bat").asFile + bat.writeText(bat.readText().replace("-dev.jar", "-${version}.jar")) + from(bat) + val shell = resourcesDir.file("run-server.sh").asFile + shell.writeText(shell.readText().replace("-dev.jar", "-${version}.jar")) + from(shell) } } -} - -tasks["bundleDistTar"].dependsOn("buildScripts") -tasks["bundleDistZip"].dependsOn("buildScripts") -tasks["bundleDistTar"].dependsOn("startScripts") -tasks["bundleDistZip"].dependsOn("startScripts") \ No newline at end of file +} \ No newline at end of file diff --git a/game/src/main/resources/run-server.bat b/game/src/main/resources/run-server.bat new file mode 100644 index 000000000..aded5359a --- /dev/null +++ b/game/src/main/resources/run-server.bat @@ -0,0 +1,4 @@ +@echo off +title Void Game Sever +java -jar void-server-dev.jar +pause \ No newline at end of file diff --git a/game/src/main/resources/run-server.sh b/game/src/main/resources/run-server.sh new file mode 100644 index 000000000..1a8583ca6 --- /dev/null +++ b/game/src/main/resources/run-server.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +title="Void Game Server" +echo -e '\033]2;'$title'\007' +# Early exit on cancel +cleanup() { + echo "" + exit 1 +} +trap cleanup INT +java -jar void-server-dev.jar +# Stop console closing +if [ $? -ne 0 ]; then + echo "Error: The Java application exited with a non-zero status." + read -p "Press enter to continue..." +fi \ No newline at end of file