From d695f2820b5077ef3b9d13ebb45730fa6182cf81 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 14 Feb 2023 08:06:04 +0100 Subject: [PATCH] Moved config --- .../kotlin/de/sh_edraft/OntimeHandlerPlugin.kt | 6 +++--- src/main/kotlin/de/sh_edraft/config/Config.kt | 18 ++++++++++++++---- .../resources/config.development.properties | 2 -- .../resources/config.edrafts-pc.properties | 2 -- src/main/resources/config.properties | 2 -- src/main/resources/config.staging.properties | 2 -- 6 files changed, 17 insertions(+), 15 deletions(-) delete mode 100644 src/main/resources/config.development.properties delete mode 100644 src/main/resources/config.edrafts-pc.properties delete mode 100644 src/main/resources/config.properties delete mode 100644 src/main/resources/config.staging.properties diff --git a/src/main/kotlin/de/sh_edraft/OntimeHandlerPlugin.kt b/src/main/kotlin/de/sh_edraft/OntimeHandlerPlugin.kt index 2ce6ff9..f72537d 100644 --- a/src/main/kotlin/de/sh_edraft/OntimeHandlerPlugin.kt +++ b/src/main/kotlin/de/sh_edraft/OntimeHandlerPlugin.kt @@ -14,9 +14,9 @@ open class OntimeHandlerPlugin() : JavaPlugin() { override fun onEnable() { this.config = Config(logger) - this.config.read("/config.properties", false) - this.config.read("/config.${this.config.environment}.properties", true) - this.config.read("/config.${this.config.hostName}.properties", true) + this.config.read("plugins/kd_ontime/config.properties", false) + this.config.read("plugins/kd_ontime/config.${this.config.environment}.properties", true) + this.config.read("plugins/kd_ontime/config.${this.config.hostName}.properties", true) this.dataService = DataService(logger, this.config) diff --git a/src/main/kotlin/de/sh_edraft/config/Config.kt b/src/main/kotlin/de/sh_edraft/config/Config.kt index 9ea089b..51e37e4 100644 --- a/src/main/kotlin/de/sh_edraft/config/Config.kt +++ b/src/main/kotlin/de/sh_edraft/config/Config.kt @@ -1,5 +1,6 @@ package de.sh_edraft.config +import java.io.File import java.net.InetAddress import java.net.UnknownHostException import java.util.* @@ -40,12 +41,21 @@ class Config(private var logger: Logger) { logger.config("Try to read config ${filename}") var foundFile = false try { - val file = this::class.java.getResourceAsStream(filename) - if (file == null && optional) { - logger.config("${filename} not found") + val file = File(filename); + if (!file.exists()) { + if (!optional) { + file.parentFile.mkdirs(); + logger.config("${filename} not found") + file.writeText( + """ + apiURL: http://localhost/api/graphql + apiKey: abcd + """.trimIndent() + ) + } return } - this.properties.load(file) + this.properties.load(file.reader()) logger.info("Found config ${filename}") foundFile = true } catch (e: Exception) { diff --git a/src/main/resources/config.development.properties b/src/main/resources/config.development.properties deleted file mode 100644 index 6359af7..0000000 --- a/src/main/resources/config.development.properties +++ /dev/null @@ -1,2 +0,0 @@ -apiURL: http://localhost/api/ -apiKey: abcd \ No newline at end of file diff --git a/src/main/resources/config.edrafts-pc.properties b/src/main/resources/config.edrafts-pc.properties deleted file mode 100644 index de8cbc9..0000000 --- a/src/main/resources/config.edrafts-pc.properties +++ /dev/null @@ -1,2 +0,0 @@ -apiURL: http://localhost:8044/api/graphql -apiKey: 7b93e3b46bbfbdafc7b1e7a9d3fc05ebf68c0ead3093bda8802fa241081c7173 \ No newline at end of file diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties deleted file mode 100644 index adc8eac..0000000 --- a/src/main/resources/config.properties +++ /dev/null @@ -1,2 +0,0 @@ -apiURL=https://kdb.keksdose-gaming.de/api/ -apiKey=abcd \ No newline at end of file diff --git a/src/main/resources/config.staging.properties b/src/main/resources/config.staging.properties deleted file mode 100644 index b8f03e4..0000000 --- a/src/main/resources/config.staging.properties +++ /dev/null @@ -1,2 +0,0 @@ -apiURL: https://kdb-test.keksdose-gaming.de/api/ -apiKey: abcd \ No newline at end of file