From 71169a7e3d174fa69f754e5511565e58d96e2932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?To=CF=80Senpai?= <15636011+TopiSenpai@users.noreply.github.com> Date: Thu, 24 Nov 2022 21:26:01 +0000 Subject: [PATCH] autocreate default config if none was found (#781) * autocreate default config if none was found * log when not being able to find application.yml.example * fixup error logging --- 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..3778049d9 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")?.let { + it.openStream().use { + if (!config.createNewFile()) { + log.error("Unable to create application.yml") + return + } + config.outputStream().use { out -> + it.copyTo(out) + } + } + } ?: log.error("Unable to find application.yml.example in resources") + } + 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)