From 2d7b4d524688cf9e70714a9a79d603fab372d587 Mon Sep 17 00:00:00 2001 From: TopiSenpai Date: Tue, 22 Nov 2022 23:56:59 +0100 Subject: [PATCH 1/3] autocreate default config if none was found --- LavalinkServer/build.gradle.kts | 4 ++++ .../src/main/java/lavalink/server/Launcher.kt | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/LavalinkServer/build.gradle.kts b/LavalinkServer/build.gradle.kts index 0b3da0137..3a3b13b4f 100644 --- a/LavalinkServer/build.gradle.kts +++ b/LavalinkServer/build.gradle.kts @@ -82,6 +82,10 @@ tasks { ) filter(ReplaceTokens::class, mapOf("tokens" to tokens)) + copy { + from("application.yml.example") + into("$buildDir/resources/main") + } } // https://stackoverflow.com/questions/41444916/multiple-artifacts-issue-with-deploying-zip-to-nexus diff --git a/LavalinkServer/src/main/java/lavalink/server/Launcher.kt b/LavalinkServer/src/main/java/lavalink/server/Launcher.kt index 3e38dd491..532c4fdf1 100644 --- a/LavalinkServer/src/main/java/lavalink/server/Launcher.kt +++ b/LavalinkServer/src/main/java/lavalink/server/Launcher.kt @@ -40,6 +40,7 @@ import org.springframework.context.ConfigurableApplicationContext import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.FilterType import org.springframework.core.io.DefaultResourceLoader +import java.io.File import java.time.Instant import java.time.ZoneId import java.time.format.DateTimeFormatter @@ -120,6 +121,23 @@ object Launcher { println(getVersionInfo(indentation = "", vanity = false)) return } + + val config = File("./application.yml") + if (!config.exists()) { + log.info("No application.yml found, creating one...") + Launcher::class.java.getResource("/application.yml.example") + ?.openStream() + ?.use { + if (!config.createNewFile()) { + log.error("Unable to create application.yml") + return + } + config.outputStream().use { out -> + it.copyTo(out) + } + } + } + val parent = launchPluginBootstrap() log.info("You can safely ignore the big red warning about illegal reflection. See https://github.com/freyacodes/Lavalink/issues/295") launchMain(parent, args) From a37a8e105e462a1d6933c393aeb834e58c63447d Mon Sep 17 00:00:00 2001 From: TopiSenpai Date: Thu, 24 Nov 2022 10:32:52 +0100 Subject: [PATCH 2/3] log when not being able to find application.yml.example --- LavalinkServer/src/main/java/lavalink/server/Launcher.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/LavalinkServer/src/main/java/lavalink/server/Launcher.kt b/LavalinkServer/src/main/java/lavalink/server/Launcher.kt index 532c4fdf1..ed0e2bca9 100644 --- a/LavalinkServer/src/main/java/lavalink/server/Launcher.kt +++ b/LavalinkServer/src/main/java/lavalink/server/Launcher.kt @@ -125,9 +125,8 @@ object Launcher { val config = File("./application.yml") if (!config.exists()) { log.info("No application.yml found, creating one...") - Launcher::class.java.getResource("/application.yml.example") - ?.openStream() - ?.use { + Launcher::class.java.getResource("/application.yml.example")?.let { + it.openStream()?.use { if (!config.createNewFile()) { log.error("Unable to create application.yml") return @@ -136,6 +135,9 @@ object Launcher { it.copyTo(out) } } + } ?: run { + log.error("Unable to find application.yml.example in resources") + } } val parent = launchPluginBootstrap() From a8b48672b38f3ce44ac2e8984c8dedc8ef3249c6 Mon Sep 17 00:00:00 2001 From: TopiSenpai Date: Thu, 24 Nov 2022 20:30:37 +0100 Subject: [PATCH 3/3] fixup error logging --- LavalinkServer/src/main/java/lavalink/server/Launcher.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/LavalinkServer/src/main/java/lavalink/server/Launcher.kt b/LavalinkServer/src/main/java/lavalink/server/Launcher.kt index ed0e2bca9..3778049d9 100644 --- a/LavalinkServer/src/main/java/lavalink/server/Launcher.kt +++ b/LavalinkServer/src/main/java/lavalink/server/Launcher.kt @@ -126,7 +126,7 @@ object Launcher { if (!config.exists()) { log.info("No application.yml found, creating one...") Launcher::class.java.getResource("/application.yml.example")?.let { - it.openStream()?.use { + it.openStream().use { if (!config.createNewFile()) { log.error("Unable to create application.yml") return @@ -135,9 +135,7 @@ object Launcher { it.copyTo(out) } } - } ?: run { - log.error("Unable to find application.yml.example in resources") - } + } ?: log.error("Unable to find application.yml.example in resources") } val parent = launchPluginBootstrap()