Skip to content

Commit

Permalink
Improving logging
Browse files Browse the repository at this point in the history
  • Loading branch information
momosetkn committed Sep 21, 2024
1 parent 48bffd7 commit 1800097
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions script-parser/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() }

Expand All @@ -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(
Expand Down

0 comments on commit 1800097

Please sign in to comment.