Skip to content

Commit a3c0707

Browse files
authored
- upgraded versions - fixed kotlin logging dependency (#4)
* - upgraded versions - fixed kotlin logging dependency * - upgraded versions - fixed kotlin logging dependency
1 parent 41754d4 commit a3c0707

7 files changed

Lines changed: 95 additions & 101 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ jobs:
3030
- name: Run code quality checks (detekt)
3131
run: ./gradlew detekt
3232

33-
- name: Run code formatting checks (kotlinter)
34-
run: ./gradlew lintKotlinMain lintKotlinTest
35-
3633
- name: Build project
3734
run: ./gradlew build -x test
3835

build.gradle.kts

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
33

44
plugins {
55
// Kotlin version bumped to be compatible with the Maven Publish plugin and Gradle 8.10
6-
kotlin("jvm") version "1.9.25"
7-
id("io.gitlab.arturbosch.detekt") version "1.23.7"
8-
id("org.jmailen.kotlinter") version "3.6.0"
6+
kotlin("jvm") version "2.2.0"
7+
id("io.gitlab.arturbosch.detekt") version "1.23.8"
98
id("maven-publish")
109
id("signing")
1110
id("com.vanniktech.maven.publish") version "0.34.0"
12-
id("net.researchgate.release") version "3.0.2"
11+
id("net.researchgate.release") version "3.1.0"
1312
jacoco
1413
}
1514

@@ -21,21 +20,18 @@ repositories {
2120
}
2221

2322
dependencies {
24-
// Logging dependencies are compileOnly (provided) to avoid transitive vulnerabilities
25-
// Updated to 1.5.20 to fix CVE-2024-12798 (JaninoEventEvaluator vulnerability fixed in 1.5.13+)
26-
// Available at runtime for local testing via testImplementation
27-
compileOnly("io.github.microutils:kotlin-logging-jvm:3.0.5")
28-
compileOnly("ch.qos.logback:logback-classic:1.5.20")
29-
testImplementation("io.github.microutils:kotlin-logging-jvm:3.0.5")
30-
testImplementation("ch.qos.logback:logback-classic:1.5.20")
31-
testImplementation("org.mockito.kotlin:mockito-kotlin:5.3.1")
32-
testImplementation("io.mockk:mockk:1.13.11")
33-
testImplementation("org.junit.jupiter", "junit-jupiter-params", "5.11.0")
23+
// SLF4J API only — consumers choose their own logging implementation
24+
implementation("org.slf4j:slf4j-api:2.0.17")
25+
compileOnly("ch.qos.logback:logback-classic:1.5.32")
26+
testImplementation("ch.qos.logback:logback-classic:1.5.32")
27+
testImplementation("org.mockito.kotlin:mockito-kotlin:5.4.0")
28+
testImplementation("io.mockk:mockk:1.14.3")
29+
testImplementation("org.junit.jupiter", "junit-jupiter-params", "5.12.2")
3430
testImplementation(kotlin("test"))
3531

3632
// Jackson for JSON serialization
37-
api("com.fasterxml.jackson.core:jackson-databind:2.17.2")
38-
api("com.fasterxml.jackson.module:jackson-module-kotlin:2.17.2")
33+
api("com.fasterxml.jackson.core:jackson-databind:2.19.0")
34+
api("com.fasterxml.jackson.module:jackson-module-kotlin:2.19.0")
3935
}
4036

4137
java {
@@ -98,32 +94,8 @@ signing {
9894
}
9995
}
10096

101-
kotlinter {
102-
ignoreFailures = false
103-
reporters = arrayOf("html")
104-
experimentalRules = false
105-
disabledRules = arrayOf(
106-
"no-wildcard-imports",
107-
"import-ordering",
108-
"indent",
109-
"final-newline",
110-
"no-multi-spaces",
111-
"no-trailing-spaces",
112-
"string-template"
113-
)
114-
}
115-
116-
// Automatic formatting before checking
117-
tasks.named("lintKotlinMain") {
118-
dependsOn("formatKotlinMain")
119-
}
120-
tasks.named("lintKotlinTest") {
121-
dependsOn("formatKotlinTest")
122-
}
123-
12497
detekt {
125-
config =
126-
files("$projectDir/detekt.yml") // point to your custom config defining rules to run, overwriting default behavior
98+
config.setFrom("$projectDir/detekt.yml") // point to your custom config defining rules to run, overwriting default behavior
12799
}
128100

129101
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
@@ -179,7 +151,9 @@ tasks.check {
179151
}
180152

181153
tasks.withType<KotlinCompile> {
182-
kotlinOptions.jvmTarget = "11"
154+
compilerOptions {
155+
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11)
156+
}
183157
}
184158

185159
// Kotlin DSL

src/main/kotlin/io/github/ngirchev/fsm/impl/AbstractFsm.kt

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package io.github.ngirchev.fsm.impl
22

3-
import mu.KLogging
43
import io.github.ngirchev.fsm.*
54
import io.github.ngirchev.fsm.exception.FsmException
65
import io.github.ngirchev.fsm.exception.FsmTransitionFailedException
6+
import org.slf4j.LoggerFactory
77
import java.util.concurrent.CopyOnWriteArrayList
88

99
/**
@@ -12,20 +12,24 @@ import java.util.concurrent.CopyOnWriteArrayList
1212
abstract class AbstractFsm<STATE, TRANSITION : AbstractTransition<STATE>, TRANSITION_TABLE : AbstractTransitionTable<STATE, TRANSITION>>(
1313
context: StateContext<STATE>,
1414
open val transitionTable: TRANSITION_TABLE,
15-
autoTransitionEnabled: Boolean? = null
16-
) : StateSupport<STATE>, TransitionSupport<STATE, TRANSITION>, Notifiable<STATE> {
17-
18-
companion object : KLogging()
15+
autoTransitionEnabled: Boolean? = null,
16+
) : StateSupport<STATE>,
17+
TransitionSupport<STATE, TRANSITION>,
18+
Notifiable<STATE> {
19+
companion object {
20+
private val logger = LoggerFactory.getLogger(AbstractFsm::class.java)
21+
}
1922

2023
/**
2124
* Enable auto transitions based on transition table.
2225
*/
2326
val autoTransitionEnabled: Boolean
2427

2528
init {
26-
val overrideAutoTransition = autoTransitionEnabled ?: run {
27-
transitionTable.autoTransitionEnabled
28-
}
29+
val overrideAutoTransition =
30+
autoTransitionEnabled ?: run {
31+
transitionTable.autoTransitionEnabled
32+
}
2933
this.autoTransitionEnabled = overrideAutoTransition
3034
}
3135

@@ -36,14 +40,12 @@ abstract class AbstractFsm<STATE, TRANSITION : AbstractTransition<STATE>, TRANSI
3640
) : this(
3741
DefaultStateContext(state),
3842
transitionTable,
39-
autoTransitionEnabled
43+
autoTransitionEnabled,
4044
)
4145

4246
internal val context: StateContext<STATE> = context
4347

44-
override fun getState(): STATE {
45-
return this.context.state
46-
}
48+
override fun getState(): STATE = this.context.state
4749

4850
private val stateChangeListeners = CopyOnWriteArrayList<StateChangeListener<STATE>>()
4951

@@ -55,13 +57,17 @@ abstract class AbstractFsm<STATE, TRANSITION : AbstractTransition<STATE>, TRANSI
5557
stateChangeListeners.remove(listener)
5658
}
5759

58-
override fun notify(context: StateContext<STATE>, oldState: STATE, newState: STATE) {
59-
logger.info { "Changed status $oldState -> $newState" }
60+
override fun notify(
61+
context: StateContext<STATE>,
62+
oldState: STATE,
63+
newState: STATE,
64+
) {
65+
logger.info("Changed status {} -> {}", oldState, newState)
6066
stateChangeListeners.forEach { listener ->
6167
try {
6268
listener.onStateChanged(context, oldState, newState)
6369
} catch (e: Exception) {
64-
logger.error(e) { "Error in state change listener" }
70+
logger.error("Error in state change listener", e)
6571
}
6672
}
6773
}
@@ -82,10 +88,12 @@ abstract class AbstractFsm<STATE, TRANSITION : AbstractTransition<STATE>, TRANSI
8288

8389
private fun executeSingleTransition(transition: TRANSITION) {
8490
val oldState = context.state
85-
if (transition.from != oldState) throw FsmException(
86-
"Current state $oldState doesn't fit " +
87-
"to change, because transition from=[${transition.from}]"
88-
)
91+
if (transition.from != oldState) {
92+
throw FsmException(
93+
"Current state $oldState doesn't fit " +
94+
"to change, because transition from=[${transition.from}]",
95+
)
96+
}
8997
transition.to.timeout?.value?.also {
9098
Thread.sleep(it * 1000)
9199
}
@@ -104,7 +112,7 @@ abstract class AbstractFsm<STATE, TRANSITION : AbstractTransition<STATE>, TRANSI
104112
val newState = transition.to.state
105113

106114
context.currentTransition = transition
107-
logger.info { "Try to change status $oldState -> $newState" }
115+
logger.info("Try to change status {} -> {}", oldState, newState)
108116

109117
transition.to.actions.forEach { it.invoke(context) }
110118
context.state = newState
@@ -114,6 +122,6 @@ abstract class AbstractFsm<STATE, TRANSITION : AbstractTransition<STATE>, TRANSI
114122

115123
private class DefaultStateContext<STATE>(
116124
override var state: STATE,
117-
override var currentTransition: Transition<STATE>? = null
125+
override var currentTransition: Transition<STATE>? = null,
118126
) : StateContext<STATE>
119127
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
package io.github.ngirchev.fsm.impl.basic
22

3-
import mu.KLogging
43
import io.github.ngirchev.fsm.StateContext
54
import io.github.ngirchev.fsm.impl.AbstractDomainFsm
65

76
open class BDomainFsm<DOMAIN : StateContext<STATE>, STATE>(
87
override val transitionTable: BTransitionTable<STATE>,
9-
private val autoTransitionEnabled: Boolean? = null
8+
private val autoTransitionEnabled: Boolean? = null,
109
) : AbstractDomainFsm<DOMAIN, STATE, BTransition<STATE>, BTransitionTable<STATE>>(
11-
transitionTable
12-
) {
13-
14-
companion object : KLogging()
15-
16-
override fun changeState(domain: DOMAIN, newState: STATE) {
17-
val overrideAutoTransition = autoTransitionEnabled ?: run {
18-
transitionTable.autoTransitionEnabled
19-
}
10+
transitionTable,
11+
) {
12+
override fun changeState(
13+
domain: DOMAIN,
14+
newState: STATE,
15+
) {
16+
val overrideAutoTransition =
17+
autoTransitionEnabled ?: run {
18+
transitionTable.autoTransitionEnabled
19+
}
2020
BFsm(domain, transitionTable, overrideAutoTransition).toState(newState)
2121
}
2222
}

src/main/kotlin/io/github/ngirchev/fsm/impl/extended/ExDomainFsm.kt

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
package io.github.ngirchev.fsm.impl.extended
22

3-
import mu.KLogging
4-
import io.github.ngirchev.fsm.impl.AbstractDomainFsm
5-
import io.github.ngirchev.fsm.StateContext
63
import io.github.ngirchev.fsm.StateChangeListener
4+
import io.github.ngirchev.fsm.StateContext
5+
import io.github.ngirchev.fsm.impl.AbstractDomainFsm
76
import java.util.concurrent.CopyOnWriteArrayList
87

98
open class ExDomainFsm<DOMAIN : StateContext<STATE>, STATE, EVENT>(
109
override val transitionTable: ExTransitionTable<STATE, EVENT>,
11-
private val autoTransitionEnabled: Boolean? = null
12-
) : AbstractDomainFsm<DOMAIN, STATE, ExTransition<STATE, EVENT>, ExTransitionTable<STATE, EVENT>>(transitionTable), StateChangeListener<STATE> {
13-
14-
companion object : KLogging()
15-
10+
private val autoTransitionEnabled: Boolean? = null,
11+
) : AbstractDomainFsm<DOMAIN, STATE, ExTransition<STATE, EVENT>, ExTransitionTable<STATE, EVENT>>(transitionTable),
12+
StateChangeListener<STATE> {
1613
private val stateChangeListeners = CopyOnWriteArrayList<StateChangeListener<STATE>>()
1714

1815
fun addStateChangeListener(listener: StateChangeListener<STATE>) {
@@ -30,24 +27,34 @@ open class ExDomainFsm<DOMAIN : StateContext<STATE>, STATE, EVENT>(
3027
* The returned instance does not have any listeners attached.
3128
*/
3229
fun getFsmForDomain(domain: DOMAIN): ExFsm<STATE, EVENT> {
33-
val overrideAutoTransition = autoTransitionEnabled ?: run {
34-
transitionTable.autoTransitionEnabled
35-
}
30+
val overrideAutoTransition =
31+
autoTransitionEnabled ?: run {
32+
transitionTable.autoTransitionEnabled
33+
}
3634
return ExFsm(domain, transitionTable, overrideAutoTransition)
3735
}
3836

3937
/**
4038
* handle event for passed document.
4139
*/
42-
fun handle(domain: DOMAIN, event: EVENT) {
40+
fun handle(
41+
domain: DOMAIN,
42+
event: EVENT,
43+
) {
4344
handleWithListeners(domain) { fsm -> fsm.onEvent(event) }
4445
}
4546

46-
override fun changeState(domain: DOMAIN, newState: STATE) {
47+
override fun changeState(
48+
domain: DOMAIN,
49+
newState: STATE,
50+
) {
4751
handleWithListeners(domain) { fsm -> fsm.toState(newState) }
4852
}
4953

50-
fun handleWithListeners(domain: DOMAIN, action: (ExFsm<STATE, EVENT>) -> Unit) {
54+
fun handleWithListeners(
55+
domain: DOMAIN,
56+
action: (ExFsm<STATE, EVENT>) -> Unit,
57+
) {
5158
val fsm = getFsmForDomain(domain)
5259
fsm.addStateChangeListener(this)
5360
try {
@@ -57,7 +64,11 @@ open class ExDomainFsm<DOMAIN : StateContext<STATE>, STATE, EVENT>(
5764
}
5865
}
5966

60-
override fun onStateChanged(context: StateContext<STATE>, oldState: STATE, newState: STATE) {
67+
override fun onStateChanged(
68+
context: StateContext<STATE>,
69+
oldState: STATE,
70+
newState: STATE,
71+
) {
6172
stateChangeListeners.forEach { listener ->
6273
listener.onStateChanged(context, oldState, newState)
6374
}

src/test/kotlin/io/github/ngirchev/fsm/it/BFsmIT.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.ngirchev.fsm.it
22

3-
import mu.KLogging
3+
import org.slf4j.LoggerFactory
44
import org.junit.jupiter.api.Assertions
55
import org.junit.jupiter.api.Test
66
import org.junit.jupiter.api.TestInstance
@@ -20,7 +20,9 @@ import kotlin.test.assertFailsWith
2020

2121
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
2222
internal class BFsmIT {
23-
companion object : KLogging()
23+
companion object {
24+
private val logger = LoggerFactory.getLogger(BFsmIT::class.java)
25+
}
2426

2527
private var autoSendEnabled: Boolean = true
2628
private var successfullySent: Boolean = false
@@ -36,7 +38,7 @@ internal class BFsmIT {
3638
To(
3739
"SIGNED",
3840
condition = { true },
39-
action = { logger.info { "SIGNED SUCCESSFUL" } }),
41+
action = { logger.info("SIGNED SUCCESSFUL") }),
4042
To("CANCELLED")
4143
)
4244
.add(
@@ -45,7 +47,7 @@ internal class BFsmIT {
4547
To(
4648
state = "AUTO_SENT",
4749
condition = { autoSendEnabled },
48-
action = { successfullySent = true; logger.info { "AUTO SENT ACTION" } }
50+
action = { successfullySent = true; logger.info("AUTO SENT ACTION") }
4951
)
5052
))
5153
.add(from = "SIGNED", "DONE", "CANCELED")
@@ -56,11 +58,11 @@ internal class BFsmIT {
5658
.autoTransitionEnabled(false)
5759
.from("NEW").to("READY_FOR_SIGN").end()
5860
.from("READY_FOR_SIGN").toMultiple()
59-
.to("SIGNED").condition { true }.action { logger.info { "SIGNED SUCCESSFUL" } }.end()
61+
.to("SIGNED").condition { true }.action { logger.info("SIGNED SUCCESSFUL") }.end()
6062
.to("CANCELED").end().endMultiple()
6163
.from("SIGNED").to("AUTO_SENT")
6264
.condition { autoSendEnabled }
63-
.action { successfullySent = true; logger.info { "AUTO SENT ACTION" } }.end()
65+
.action { successfullySent = true; logger.info("AUTO SENT ACTION") }.end()
6466
.from("SIGNED").toMultiple().to("DONE").end().to("CANCELED").end().endMultiple()
6567
.from("AUTO_SENT").toMultiple().to("DONE").end().to("CANCELED").end().endMultiple()
6668
.build()

0 commit comments

Comments
 (0)