Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
feat: read config.properties from local files
Browse files Browse the repository at this point in the history
  • Loading branch information
AH-dark committed Dec 8, 2023
1 parent 780e174 commit c332f55
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jreleaser {
authors = listOf("AHdark")
maintainers = listOf("AH-dark")
inceptionYear = "2023"
website = "https://github.com/aH-dark/ahdark-blog-releaser"
website = "https://github.com/AH-dark/ahdark-blog-releaser"
docsUrl = "https://github.com/AH-dark/ahdark-blog-releaser/wiki"

java {
Expand Down
16 changes: 14 additions & 2 deletions src/main/kotlin/com/ahdark/code/utils/ConfigUtils.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
package com.ahdark.code.utils

import java.io.File
import java.io.InputStream
import java.util.*

class ConfigUtils {
private val configFileName = "config.properties"

private val props = Properties()
private val inputStream: InputStream? = javaClass.classLoader.getResourceAsStream("config.properties")
private val resourceStream: InputStream? = javaClass.classLoader.getResourceAsStream(configFileName)

init {
inputStream.use { props.load(it) }
resourceStream?.use { props.load(it) }

initFromLocal()
}

private fun initFromLocal() {
val configFile = File(configFileName)
if (configFile.exists()) {
configFile.inputStream().use { props.load(it) }
}
}

fun getProperty(key: String): String? {
Expand Down

0 comments on commit c332f55

Please sign in to comment.