Skip to content

Commit

Permalink
autocreate default config if none was found (#781)
Browse files Browse the repository at this point in the history
* autocreate default config if none was found

* log when not being able to find application.yml.example

* fixup error logging
  • Loading branch information
topi314 authored Nov 24, 2022
1 parent 2932490 commit 71169a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions LavalinkServer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions LavalinkServer/src/main/java/lavalink/server/Launcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 71169a7

Please sign in to comment.