Moved config

This commit is contained in:
Sven Heidemann 2023-02-14 08:06:04 +01:00
parent 8516685a51
commit d695f2820b
6 changed files with 17 additions and 15 deletions

View File

@ -14,9 +14,9 @@ open class OntimeHandlerPlugin() : JavaPlugin() {
override fun onEnable() { override fun onEnable() {
this.config = Config(logger) this.config = Config(logger)
this.config.read("/config.properties", false) this.config.read("plugins/kd_ontime/config.properties", false)
this.config.read("/config.${this.config.environment}.properties", true) this.config.read("plugins/kd_ontime/config.${this.config.environment}.properties", true)
this.config.read("/config.${this.config.hostName}.properties", true) this.config.read("plugins/kd_ontime/config.${this.config.hostName}.properties", true)
this.dataService = DataService(logger, this.config) this.dataService = DataService(logger, this.config)

View File

@ -1,5 +1,6 @@
package de.sh_edraft.config package de.sh_edraft.config
import java.io.File
import java.net.InetAddress import java.net.InetAddress
import java.net.UnknownHostException import java.net.UnknownHostException
import java.util.* import java.util.*
@ -40,12 +41,21 @@ class Config(private var logger: Logger) {
logger.config("Try to read config ${filename}") logger.config("Try to read config ${filename}")
var foundFile = false var foundFile = false
try { try {
val file = this::class.java.getResourceAsStream(filename) val file = File(filename);
if (file == null && optional) { if (!file.exists()) {
if (!optional) {
file.parentFile.mkdirs();
logger.config("${filename} not found") logger.config("${filename} not found")
file.writeText(
"""
apiURL: http://localhost/api/graphql
apiKey: abcd
""".trimIndent()
)
}
return return
} }
this.properties.load(file) this.properties.load(file.reader())
logger.info("Found config ${filename}") logger.info("Found config ${filename}")
foundFile = true foundFile = true
} catch (e: Exception) { } catch (e: Exception) {

View File

@ -1,2 +0,0 @@
apiURL: http://localhost/api/
apiKey: abcd

View File

@ -1,2 +0,0 @@
apiURL: http://localhost:8044/api/graphql
apiKey: 7b93e3b46bbfbdafc7b1e7a9d3fc05ebf68c0ead3093bda8802fa241081c7173

View File

@ -1,2 +0,0 @@
apiURL=https://kdb.keksdose-gaming.de/api/
apiKey=abcd

View File

@ -1,2 +0,0 @@
apiURL: https://kdb-test.keksdose-gaming.de/api/
apiKey: abcd