From 1800097e131747398646539c1ab4ad9c7a8a5f18 Mon Sep 17 00:00:00 2001 From: "t.momose" Date: Sun, 22 Sep 2024 05:58:57 +0900 Subject: [PATCH] Improving logging --- .../KotlinCompiledLiquibaseChangeLogParser.kt | 14 ++++---- script-parser/build.gradle.kts | 3 ++ .../KotlinScriptLiquibaseChangeLogParser.kt | 32 ++++++++++++------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/compiled-parser/src/main/kotlin/momosetkn/liquibase/kotlin/parser/KotlinCompiledLiquibaseChangeLogParser.kt b/compiled-parser/src/main/kotlin/momosetkn/liquibase/kotlin/parser/KotlinCompiledLiquibaseChangeLogParser.kt index b7581ff0..bb405f03 100644 --- a/compiled-parser/src/main/kotlin/momosetkn/liquibase/kotlin/parser/KotlinCompiledLiquibaseChangeLogParser.kt +++ b/compiled-parser/src/main/kotlin/momosetkn/liquibase/kotlin/parser/KotlinCompiledLiquibaseChangeLogParser.kt @@ -18,17 +18,19 @@ class KotlinCompiledLiquibaseChangeLogParser : ChangeLogParser { resourceAccessor: ResourceAccessor, ): DatabaseChangeLog { val databaseChangeLog = DatabaseChangeLog(physicalChangeLogLocation) - runCatching { + return runCatching { updateChangeLog( databaseChangeLog = databaseChangeLog, changeLogParameters = changeLogParameters, resourceAccessor = resourceAccessor, ) - }.onFailure { - log.error("error in KotlinCompiledLiquibaseChangeLogParser", it) - throw it - } - return databaseChangeLog + }.fold( + onSuccess = { databaseChangeLog }, + onFailure = { + log.error("error in KotlinCompiledLiquibaseChangeLogParser", it) + throw it + } + ) } private fun updateChangeLog( diff --git a/script-parser/build.gradle.kts b/script-parser/build.gradle.kts index e820e2a8..dd55c980 100644 --- a/script-parser/build.gradle.kts +++ b/script-parser/build.gradle.kts @@ -2,6 +2,7 @@ val liquibaseVersion = rootProject.properties["liquibaseVersion"] as String val kotestVersion = rootProject.properties["kotestVersion"] as String val kotlinVersion = rootProject.properties["kotlinVersion"] as String val liquibaseKotlinVersion = rootProject.properties["liquibaseKotlinVersion"] as String +val slf4jVersion = rootProject.properties["slf4jVersion"] as String dependencies { // liquibase-kotlin @@ -15,6 +16,8 @@ dependencies { api("org.jetbrains.kotlin:kotlin-scripting-dependencies:$kotlinVersion") api("org.jetbrains.kotlin:kotlin-scripting-dependencies-maven:$kotlinVersion") api("org.jetbrains.kotlin:kotlin-script-util:1.8.22") + // log + api("org.slf4j:slf4j-api:$slf4jVersion") // test testImplementation("io.kotest:kotest-framework-engine-jvm:$kotestVersion") diff --git a/script-parser/src/main/kotlin/momosetkn/liquibase/kotlin/parser/KotlinScriptLiquibaseChangeLogParser.kt b/script-parser/src/main/kotlin/momosetkn/liquibase/kotlin/parser/KotlinScriptLiquibaseChangeLogParser.kt index e1bef3ba..8a54e2fc 100644 --- a/script-parser/src/main/kotlin/momosetkn/liquibase/kotlin/parser/KotlinScriptLiquibaseChangeLogParser.kt +++ b/script-parser/src/main/kotlin/momosetkn/liquibase/kotlin/parser/KotlinScriptLiquibaseChangeLogParser.kt @@ -11,6 +11,8 @@ import java.io.InputStreamReader import java.util.ServiceLoader class KotlinScriptLiquibaseChangeLogParser : ChangeLogParser { + private val log = org.slf4j.LoggerFactory.getLogger(this::class.java) + private val imports = ServiceLoader.load(KotlinScriptParserImports::class.java) .flatMap { it.imports() } @@ -21,21 +23,27 @@ class KotlinScriptLiquibaseChangeLogParser : ChangeLogParser { ): DatabaseChangeLog { // windows path to a multi-platform path val fixedPhysicalChangeLogLocation = physicalChangeLogLocation.replace("\\\\", "/") - val changeLogScript = - getChangeLogKotlinScriptCode( + val databaseChangeLog = DatabaseChangeLog(fixedPhysicalChangeLogLocation) + return runCatching { + val changeLogScript = + getChangeLogKotlinScriptCode( + resourceAccessor = resourceAccessor, + physicalChangeLogLocation = fixedPhysicalChangeLogLocation, + ) + updateChangeLog( + filePath = fixedPhysicalChangeLogLocation, + databaseChangeLog = databaseChangeLog, + changeLogParameters = changeLogParameters, resourceAccessor = resourceAccessor, - physicalChangeLogLocation = fixedPhysicalChangeLogLocation, + changeLogScript = changeLogScript, ) - - val databaseChangeLog = DatabaseChangeLog(fixedPhysicalChangeLogLocation) - updateChangeLog( - filePath = fixedPhysicalChangeLogLocation, - databaseChangeLog = databaseChangeLog, - changeLogParameters = changeLogParameters, - resourceAccessor = resourceAccessor, - changeLogScript = changeLogScript, + }.fold( + onSuccess = { databaseChangeLog }, + onFailure = { + log.error("error in KotlinScriptLiquibaseChangeLogParser", it) + throw it + } ) - return databaseChangeLog } private fun updateChangeLog(