Is there someone here who publishes MPP projects u...
# multiplatform
a
Is there someone here who publishes MPP projects using the Gradle Kotlin DSL to Maven Central?
i
a
wow, this is great!!
and how are you doing the deploy?
do you close/release on sonatype by hand?
i
yes, I dont release my libs often enough to have any desire to look into automating that side of things
a
so you only release the
generator
module?
I guess this setup would work with multiple modules as well
c
https://github.com/open-jumpco/kfsm I do the sonatype close and deploy by hand. Upload seem to fail at random times. I have a script for building artifacts on linux
The normal build runs on windows
a
Thanks!
e
Another example: https://github.com/erikc5000/island-time I'm using precompiled script plugins that can be shared between different artifacts.
๐Ÿ‘ 1
a
Thanks! ๐Ÿ‘
@corneil I think the upload fails because of a timeout. It was doing that years ago as well when I was deploying regular Java projects ๐Ÿ‘
btw I really like your state machine implementation!
c
Thanks. I'm working on a collection of examples. I would appreciate any feedback or questions
a
i'll PM you if something comes up
๐Ÿ‘
c
Oh yes, I had to choose which features I added and which not. My model is very similar to this.
a
๐Ÿ‘
to be honest I never had to use most of these
c
I've implemented my first FSM for a serial line protocol. One of the examples illustrate that one.
a
nice
i've implemented FSMs 3 times
my first time was a mess ๐Ÿ˜‚
by the 3rd try I arrived to something which is very similar to what you have in your lib
every road leads to Rome as it seems
c
I use the SMC tool to generate C++ in one case and then modified it to generate Java for another case. When I reached out to use it and it didn't support Kotlin I immediately thought that a DSL should do the job.
a
๐Ÿ‘
that DSL looks great
c
Thanks, I tried.
I'm work on a visualisation module.
I'm parsing the code to obtain the content of the actions and guard expressions
a
why do you need to parse it?
c
How else am I going to shown the content of a lambda?
a
maybe you could do a "dry run" with your dsl:
Copy code
private val definition = stateMachine(
            TurnstileStates.values().toSet(),
            TurnstileEvents::class,
            Turnstile::class
        ) {
            initialState {
            if (locked)
                TurnstileStates.LOCKED
            else
                TurnstileStates.UNLOCKED
            }
            default {
                onEntry { startState, targetState, _ ->
                    println("entering:$startState -> $targetState for $this")
                }
                // default transition will invoke alarm
                action { state, event, _ ->
                    println("Default action for state($state) -> event($event) for $this")
                    alarm()
                }
                onExit { startState, targetState, _ ->
                    println("exiting:$startState -> $targetState for $this")
                }
            }
            // when current state is LOCKED
            whenState(TurnstileStates.LOCKED) {
                // external transition on COIN to UNLOCKED state
                onEvent(TurnstileEvents.COIN to TurnstileStates.UNLOCKED) {
                    unlock()
                }
            }
            // when current state is UNLOCKED
            whenState(TurnstileStates.UNLOCKED) {
                // internal transition on COIN
                onEvent(TurnstileEvents.COIN) {
                    returnCoin()
                }
                // external transition on PASS to LOCKED state
                onEvent(TurnstileEvents.PASS to TurnstileStates.LOCKED) {
                    lock()
                }
            }
        }.build()
so it not only builds the FSM but also a meta model of it
c
The lamba just gives a call signature, look at this diagram https://open.jumpco.io/projects/kfsm/index.html#packet-reader-example
I want to include the action lambdas and guard expressions in the output.
I can already generate the following from the current model without parsing that code: https://github.com/open-jumpco/kfsm-viz
a
oh I see
that makes sense
indeed
c
I've update the kfsm-viz implementation to generate a plantuml model and state table in asciidoc. I've implemented that parser and now can represent the guards and actions. Still have some issues with nested statemaps. The outputs are here: https://github.com/open-jumpco/kfsm-viz/tree/master/generated-parsed
The state diagrams are still ugly because it only works with everything on one line. In a tool like Rational Rose it would properly provide for placing guards and actions below event.
a
hmm
where can I see the diagrams?
c
View those file in Intellij with plantuml plugin or pastr the content into an online editor like: https://www.planttext.com/
I plant to look into some examples that leverage docToolChain to generate a site
a
oh, that's great
c
a
@corneil I'm looking at kfsm and I'm wondering whether it is possible to use it in a stateless mode for simple FSMs
my use case is that I want to store the state of my users in a state machine (ANONYMOUS, REGISTERING, LOGGED_IN) and their context info is in a session
so on each request I just want to use the state machine as a function to determine from the session whether the action they are trying to perform is valid
do you think that kfsm can be used for this?
c
That is exactly how I use it in the backend. I create an instance using a directly stored state or derive it from the Context class. Look at the spring demos.
You can create an instance with the context class and a state argument or just context class in which cases you need to use the
initialState
in the DSL
This example shows different ways of create an instance
a
this is great'
!
i'm gonna try it this week, thanks!