commit 22/01/2026
This commit is contained in:
@@ -5,6 +5,7 @@ import java.io.FileInputStream
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.FileOutputStream
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import java.time.LocalDateTime
|
||||
import java.util.Properties
|
||||
import kotlin.io.path.Path
|
||||
@@ -12,7 +13,8 @@ import kotlin.io.path.Path
|
||||
@Suppress("unused")
|
||||
class Config {
|
||||
private val prop = Properties()
|
||||
private val filename = "config.properties"
|
||||
// config.properties is saved in current working directory
|
||||
private val filename = Paths.get(System.getProperty("user.dir"), "config.properties")
|
||||
var WebPort : Int
|
||||
get() = prop.getProperty("webport").toInt()
|
||||
set(value) {prop.setProperty("webport", value.toString())}
|
||||
@@ -64,24 +66,24 @@ class Config {
|
||||
|
||||
fun Load(){
|
||||
try{
|
||||
if (Files.isRegularFile(Path(filename))){
|
||||
prop.load(FileInputStream(filename))
|
||||
if (!prop.contains("webport")) throw Exception("Invalid config file: missing 'webport'")
|
||||
if (!prop.contains("webusername")) throw Exception("Invalid config file: missing 'webusername'")
|
||||
if (!prop.contains("webpassword")) throw Exception("Invalid config file: missing 'webpassword'")
|
||||
if (!prop.contains("activemq_brokerurl")) throw Exception("Invalid config file: missing 'activemq_brokerurl'")
|
||||
if (!prop.contains("activemq_username")) throw Exception("Invalid config file: missing 'activemq_username'")
|
||||
if (!prop.contains("activemq_password")) throw Exception("Invalid config file: missing 'activemq_password'")
|
||||
if (!prop.contains("activemq_queuename")) throw Exception("Invalid config file: missing 'activemq_queuename'")
|
||||
if (!prop.contains("mysql_aas1")) throw Exception("Invalid config file: missing 'mysql_aas1'")
|
||||
if (!prop.contains("mysql_aas2")) throw Exception("Invalid config file: missing 'mysql_aas2'")
|
||||
if (!prop.contains("mysql_aas3")) throw Exception("Invalid config file: missing 'mysql_aas3'")
|
||||
if (!prop.contains("mysql_aas1_username")) throw Exception("Invalid config file: missing 'mysql_aas1_username'")
|
||||
if (!prop.contains("mysql_aas1_password")) throw Exception("Invalid config file: missing 'mysql_aas1_password'")
|
||||
if (!prop.contains("mysql_aas2_username")) throw Exception("Invalid config file: missing 'mysql_aas2_username'")
|
||||
if (!prop.contains("mysql_aas2_password")) throw Exception("Invalid config file: missing 'mysql_aas2_password'")
|
||||
if (!prop.contains("mysql_aas3_username")) throw Exception("Invalid config file: missing 'mysql_aas3_username'")
|
||||
if (!prop.contains("mysql_aas3_password")) throw Exception("Invalid config file: missing 'mysql_aas3_password'")
|
||||
if (Files.isRegularFile(filename)){
|
||||
prop.load(FileInputStream(filename.toString()))
|
||||
if (!prop.containsKey("webport")) throw Exception("Invalid config file: missing 'webport'")
|
||||
if (!prop.containsKey("webusername")) throw Exception("Invalid config file: missing 'webusername'")
|
||||
if (!prop.containsKey("webpassword")) throw Exception("Invalid config file: missing 'webpassword'")
|
||||
if (!prop.containsKey("activemq_brokerurl")) throw Exception("Invalid config file: missing 'activemq_brokerurl'")
|
||||
if (!prop.containsKey("activemq_username")) throw Exception("Invalid config file: missing 'activemq_username'")
|
||||
if (!prop.containsKey("activemq_password")) throw Exception("Invalid config file: missing 'activemq_password'")
|
||||
if (!prop.containsKey("activemq_queuename")) throw Exception("Invalid config file: missing 'activemq_queuename'")
|
||||
if (!prop.containsKey("mysql_aas1")) throw Exception("Invalid config file: missing 'mysql_aas1'")
|
||||
if (!prop.containsKey("mysql_aas2")) throw Exception("Invalid config file: missing 'mysql_aas2'")
|
||||
if (!prop.containsKey("mysql_aas3")) throw Exception("Invalid config file: missing 'mysql_aas3'")
|
||||
if (!prop.containsKey("mysql_aas1_username")) throw Exception("Invalid config file: missing 'mysql_aas1_username'")
|
||||
if (!prop.containsKey("mysql_aas1_password")) throw Exception("Invalid config file: missing 'mysql_aas1_password'")
|
||||
if (!prop.containsKey("mysql_aas2_username")) throw Exception("Invalid config file: missing 'mysql_aas2_username'")
|
||||
if (!prop.containsKey("mysql_aas2_password")) throw Exception("Invalid config file: missing 'mysql_aas2_password'")
|
||||
if (!prop.containsKey("mysql_aas3_username")) throw Exception("Invalid config file: missing 'mysql_aas3_username'")
|
||||
if (!prop.containsKey("mysql_aas3_password")) throw Exception("Invalid config file: missing 'mysql_aas3_password'")
|
||||
Logger.info { "Configuration loaded from config.properties" }
|
||||
} else throw FileNotFoundException("Config file not found")
|
||||
} catch (e: FileNotFoundException){
|
||||
@@ -102,7 +104,7 @@ class Config {
|
||||
// comment is save date and time
|
||||
val comment = "Configuration saved on ${LocalDateTime.now()}"
|
||||
try{
|
||||
prop.store(FileOutputStream(filename), comment)
|
||||
prop.store(FileOutputStream(filename.toString()), comment)
|
||||
Logger.info { "Configuration saved to config.properties" }
|
||||
} catch (ex: Exception){
|
||||
Logger.error(ex) { "Error while saving config, Message : ${ex.message}" }
|
||||
|
||||
2
src/simplelogger.properties
Normal file
2
src/simplelogger.properties
Normal file
@@ -0,0 +1,2 @@
|
||||
# gak mau lihat log javalin
|
||||
org.slf4j.simpleLogger.defaultLogLevel=error
|
||||
Reference in New Issue
Block a user