Skip to content

Commit

Permalink
Merge pull request #1121 from rahulsom/renovate/org.jlleitschuh.gradl…
Browse files Browse the repository at this point in the history
…e.ktlint-12.x

chore(deps): update plugin org.jlleitschuh.gradle.ktlint to v12
  • Loading branch information
rahulsom authored Apr 22, 2024
2 parents 5292c58 + 1e6a73a commit 5c4d9e6
Show file tree
Hide file tree
Showing 51 changed files with 534 additions and 406 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id("com.github.rahulsom.waena.root").version("0.6.1")
id("org.jetbrains.kotlin.jvm").version("1.8.22").apply(false)
id("org.jetbrains.kotlin.plugin.allopen").version("1.8.22").apply(false)
id("org.jlleitschuh.gradle.ktlint").version("11.6.1").apply(false)
id("org.jlleitschuh.gradle.ktlint").version("12.1.0").apply(false)
id("org.springframework.boot").version("3.0.4").apply(false)
id("io.spring.dependency-management").version("1.1.4").apply(false)
id("org.sonarqube").version("5.0.0.4638")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ package com.github.rahulsom.grooves
* The outcome of applying an event to a snapshot.
*/
enum class EventApplyOutcome {
RETURN, CONTINUE
RETURN,
CONTINUE,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.github.rahulsom.grooves

enum class EventType {
Normal, Revert, Deprecates, DeprecatedBy
Normal,
Revert,
Deprecates,
DeprecatedBy,
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.github.rahulsom.grooves

interface GroovesQuery<Aggregate, VersionOrTimestamp, Snapshot, Event, EventId> {
fun computeSnapshot(aggregate: Aggregate, at: VersionOrTimestamp?, redirect: Boolean):
GroovesResult<Snapshot, Aggregate, VersionOrTimestamp>
fun computeSnapshot(
aggregate: Aggregate,
at: VersionOrTimestamp?,
redirect: Boolean,
): GroovesResult<Snapshot, Aggregate, VersionOrTimestamp>

fun computeSnapshot(aggregate: Aggregate, at: VersionOrTimestamp?) =
(
computeSnapshot(aggregate, at, true)
as GroovesResult.Success<Snapshot, Aggregate, VersionOrTimestamp>
).snapshot
fun computeSnapshot(
aggregate: Aggregate,
at: VersionOrTimestamp?,
) = (
computeSnapshot(aggregate, at, true)
as GroovesResult.Success<Snapshot, Aggregate, VersionOrTimestamp>
).snapshot
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ import com.github.rahulsom.grooves.logging.Trace
*/
interface Deprecator<Snapshot, Aggregate> {
@Trace
fun invoke(snapshot: Snapshot, deprecatingAggregate: Aggregate)
fun invoke(
snapshot: Snapshot,
deprecatingAggregate: Aggregate,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ import com.github.rahulsom.grooves.logging.Trace
*/
interface EventHandler<Event, Snapshot> {
@Trace
fun invoke(event: Event, snapshot: Snapshot): EventApplyOutcome
fun invoke(
event: Event,
snapshot: Snapshot,
): EventApplyOutcome
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ interface EventsProvider<Aggregate, VersionOrTimestamp, Snapshot, Event> {
fun invoke(
aggregates: List<Aggregate>,
versionOrTimestamp: VersionOrTimestamp?,
lastSnapshot: Snapshot
lastSnapshot: Snapshot,
): Stream<Event>
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ import com.github.rahulsom.grooves.logging.Trace
*/
interface ExceptionHandler<Snapshot, Event> {
@Trace
fun invoke(exception: Exception, snapshot: Snapshot, event: Event): EventApplyOutcome
fun invoke(
exception: Exception,
snapshot: Snapshot,
event: Event,
): EventApplyOutcome
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ import com.github.rahulsom.grooves.logging.Trace
*/
interface SnapshotProvider<Aggregate, VersionOrTimestamp, Snapshot> {
@Trace
fun invoke(aggregate: Aggregate, versionOrTimestamp: VersionOrTimestamp?): Snapshot?
fun invoke(
aggregate: Aggregate,
versionOrTimestamp: VersionOrTimestamp?,
): Snapshot?
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ import com.github.rahulsom.grooves.logging.Trace
*/
interface SnapshotVersioner<Snapshot, VersionOrTimestamp> {
@Trace
fun invoke(snapshot: Snapshot, versionOrTimestamp: VersionOrTimestamp)
fun invoke(
snapshot: Snapshot,
versionOrTimestamp: VersionOrTimestamp,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ class GroovesQueryImpl<VersionOrTimestamp, Snapshot, Aggregate, Event, EventId>(
private val snapshotVersioner: SnapshotVersioner<Snapshot, VersionOrTimestamp>,
private val deprecatedByProvider: DeprecatedByProvider<Event, Aggregate, EventId>,
private val revertedEventProvider: RevertedEventProvider<Event>,
private val eventIdProvider: EventIdProvider<Event, EventId>
private val eventIdProvider: EventIdProvider<Event, EventId>,
) : GroovesQuery<Aggregate, VersionOrTimestamp, Snapshot, Event, EventId> {

private val log = LoggerFactory.getLogger(javaClass)

@Trace
override fun computeSnapshot(aggregate: Aggregate, at: VersionOrTimestamp?, redirect: Boolean): GroovesResult<Snapshot, Aggregate, VersionOrTimestamp> {
override fun computeSnapshot(
aggregate: Aggregate,
at: VersionOrTimestamp?,
redirect: Boolean,
): GroovesResult<Snapshot, Aggregate, VersionOrTimestamp> {
val providedSnapshot = snapshotProvider.invoke(aggregate, at)
val snapshot = providedSnapshot ?: emptySnapshotProvider.invoke(aggregate)
val events = eventsProvider.invoke(listOf(aggregate), at, snapshot).collect(Collectors.toList())
Expand All @@ -67,18 +70,20 @@ class GroovesQueryImpl<VersionOrTimestamp, Snapshot, Aggregate, Event, EventId>(
aggregates: List<Aggregate>,
at: VersionOrTimestamp?,
redirect: Boolean,
beforeReturn: (CallIdentifier, Snapshot?) -> Unit
beforeReturn: (CallIdentifier, Snapshot?) -> Unit,
): GroovesResult<Snapshot, Aggregate, VersionOrTimestamp> {
val indent = IndentedLogging.indent()

val callIdentifier = CallIdentifier(
"${indent}computeSnapshotImpl(<... ${events.size} items>, $snapshot, $aggregates, $at)"
)
val callIdentifier =
CallIdentifier(
"${indent}computeSnapshotImpl(<... ${events.size} items>, $snapshot, $aggregates, $at)",
)
log.trace(callIdentifier.data)
IndentedLogging.stepIn()
val (revertEvents, forwardEvents) = events
.partition { eventClassifier.invoke(it) == Revert }
.let { it.first.toMutableList() to it.second.toMutableList() }
val (revertEvents, forwardEvents) =
events
.partition { eventClassifier.invoke(it) == Revert }
.let { it.first.toMutableList() to it.second.toMutableList() }

if (revertsExistOutsideEvents(revertEvents, indent, forwardEvents)) {
val snapshot1 = emptySnapshotProvider.invoke(aggregates[0])
Expand Down Expand Up @@ -110,14 +115,16 @@ class GroovesQueryImpl<VersionOrTimestamp, Snapshot, Aggregate, Event, EventId>(
DeprecatedBy -> {
val ret = deprecatedByProvider.invoke(event)
log.debug("$indent ...The aggregate was deprecated by ${ret.aggregate}. Recursing to compute snapshot for it...")
val refEvent = eventsProvider.invoke(listOf(ret.aggregate), null, emptySnapshotProvider.invoke(ret.aggregate))
.collect(Collectors.toList())
.find { eventIdProvider.invoke(it) == ret.eventId }
val refEvent =
eventsProvider.invoke(listOf(ret.aggregate), null, emptySnapshotProvider.invoke(ret.aggregate))
.collect(Collectors.toList())
.find { eventIdProvider.invoke(it) == ret.eventId }

val redirectVersion = eventVersioner.invoke(refEvent!!)
val otherSnapshot = snapshotProvider.invoke(ret.aggregate, redirectVersion) ?: emptySnapshotProvider.invoke(ret.aggregate)
val newEvents = eventsProvider.invoke(listOf(ret.aggregate) + aggregates, redirectVersion, otherSnapshot)
.collect(Collectors.toList())
val newEvents =
eventsProvider.invoke(listOf(ret.aggregate) + aggregates, redirectVersion, otherSnapshot)
.collect(Collectors.toList())
@Suppress("LiftReturnOrAssignment")
if (redirect) {
return computeSnapshotImpl(newEvents, otherSnapshot, aggregates + listOf(ret.aggregate), at, redirect) { c, s ->
Expand Down Expand Up @@ -152,7 +159,11 @@ class GroovesQueryImpl<VersionOrTimestamp, Snapshot, Aggregate, Event, EventId>(
return GroovesResult.Success(snapshot)
}

private fun revertsExistOutsideEvents(revertEvents: MutableList<Event>, indent: String, forwardEvents: MutableList<Event>): Boolean {
private fun revertsExistOutsideEvents(
revertEvents: MutableList<Event>,
indent: String,
forwardEvents: MutableList<Event>,
): Boolean {
while (revertEvents.isNotEmpty()) {
val mostRecentRevert = revertEvents.removeLast()
val revertedEvent = revertedEventProvider.invoke(mostRecentRevert)
Expand All @@ -172,10 +183,13 @@ class GroovesQueryImpl<VersionOrTimestamp, Snapshot, Aggregate, Event, EventId>(
return false
}

private inline fun tryRunning(snapshot: Snapshot, it: Event, code: () -> EventApplyOutcome) =
try {
code()
} catch (e: Exception) {
exceptionHandler.invoke(e, snapshot, it)
}
private inline fun tryRunning(
snapshot: Snapshot,
it: Event,
code: () -> EventApplyOutcome,
) = try {
code()
} catch (e: Exception) {
exceptionHandler.invoke(e, snapshot, it)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ class IndentedLogging {
companion object {
private val indentLevel = ThreadLocal<Int>()
private const val INITIAL_INDENT = 1

fun stepIn() = indentLevel.set(indentLevel.getOrSet { INITIAL_INDENT } + 1)

fun stepOut() = indentLevel.set(indentLevel.getOrSet { INITIAL_INDENT } - 1)

@JvmStatic
fun indent() = "".padStart(indentLevel.getOrSet { INITIAL_INDENT } * 2)

private fun eventsToString(it: List<*>): Any = "<... ${it.size} item(s)>"
}

@Suppress("unused", "UNUSED_PARAMETER")
@Around(value = "@annotation(trace)", argNames = "trace")
@ExperimentalStdlibApi
fun around(joinPoint: ProceedingJoinPoint, trace: Trace): Any? {
fun around(
joinPoint: ProceedingJoinPoint,
trace: Trace,
): Any? {
val signature = joinPoint.signature
val classWithFunction = joinPoint.target.javaClass
val loggerName = classWithFunction.name.replace(Regex("\\\$\\\$Lambda.*$"), "")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.rahulsom.grooves.asciidoctor

import com.github.rahulsom.grooves.asciidoctor.Constants.aggregateHeight
import com.github.rahulsom.grooves.asciidoctor.Constants.aggregateWidth
import com.github.rahulsom.grooves.asciidoctor.Constants.eventLineHeight
import com.github.rahulsom.grooves.asciidoctor.Constants.eventSpace
import com.github.rahulsom.grooves.asciidoctor.Constants.offset
import com.github.rahulsom.grooves.asciidoctor.Constants.textLineHeight
import com.github.rahulsom.grooves.asciidoctor.Constants.AGGREGATE_HEIGHT
import com.github.rahulsom.grooves.asciidoctor.Constants.AGGREGATE_WIDTH
import com.github.rahulsom.grooves.asciidoctor.Constants.EVENT_LINE_HEIGHT
import com.github.rahulsom.grooves.asciidoctor.Constants.EVENT_SPACE
import com.github.rahulsom.grooves.asciidoctor.Constants.OFFSET
import com.github.rahulsom.grooves.asciidoctor.Constants.TEXT_LINE_HEIGHT
import com.github.rahulsom.svg.G
import com.github.rahulsom.svg.ObjectFactory
import java.util.Date
Expand All @@ -25,39 +25,40 @@ class Aggregate(private val counter: Int, var type: String, var id: String, var
}

fun buildSvg(dates: Map<Date, Double>): G {
val y = index * eventLineHeight + offset
val yMid = index * eventLineHeight + offset + aggregateHeight / 2
val y = index * EVENT_LINE_HEIGHT + OFFSET
val yMid = index * EVENT_LINE_HEIGHT + OFFSET + AGGREGATE_HEIGHT / 2

val objectFactory = ObjectFactory()
val g = objectFactory.createG()
.withId("aggregate_$counter")
.withClazz("aggregate")
val g =
objectFactory.createG()
.withId("aggregate_$counter")
.withClazz("aggregate")
return g.withSVGDescriptionClassOrSVGAnimationClassOrSVGStructureClass(
objectFactory.createRect(
objectFactory.createRect().withX("10").withY(y.toString())
.withWidth("$aggregateWidth").withHeight("$aggregateHeight")
.withWidth("$AGGREGATE_WIDTH").withHeight("$AGGREGATE_HEIGHT"),
),
objectFactory.createText(
objectFactory.createText().withX("15").withY("${y + textLineHeight}")
objectFactory.createText().withX("15").withY("${y + TEXT_LINE_HEIGHT}")
.withClazz("type")
.withContent(type)
.withContent(type),
),
objectFactory.createText(
objectFactory.createText().withX("15").withY("${y + textLineHeight * 2}")
objectFactory.createText().withX("15").withY("${y + TEXT_LINE_HEIGHT * 2}")
.withClazz("id")
.withContent(id)
.withContent(id),
),
objectFactory.createText(
objectFactory.createText().withX("10").withY("${y - 5}")
.withClazz("description")
.withContent(description)
.withContent(description),
),
objectFactory.createLine(
objectFactory.createLine().withX1("${10 + aggregateWidth}").withY1("$yMid")
.withX2("${dates.values.maxOrNull()!! * eventSpace + 3 * aggregateWidth}")
objectFactory.createLine().withX1("${10 + AGGREGATE_WIDTH}").withY1("$yMid")
.withX2("${dates.values.maxOrNull()!! * EVENT_SPACE + 3 * AGGREGATE_WIDTH}")
.withY2("$yMid")
.withClazz("eventLine").withMarkerEnd("url(#triangle)")
)
.withClazz("eventLine").withMarkerEnd("url(#triangle)"),
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ package com.github.rahulsom.grooves.asciidoctor
* @author Rahul Somasunderam
*/
object Constants {
const val eventLineHeight: Int = 100
const val aggregateHeight: Int = 40
const val aggregateWidth: Int = 100
const val eventSpace: Int = 50
const val offset: Int = 45
const val textLineHeight: Int = 18
const val EVENT_LINE_HEIGHT: Int = 100
const val AGGREGATE_HEIGHT: Int = 40
const val AGGREGATE_WIDTH: Int = 100
const val EVENT_SPACE: Int = 50
const val OFFSET: Int = 45
const val TEXT_LINE_HEIGHT: Int = 18

val CSS: String by lazy {
Constants::class.java.getResourceAsStream("/esdiag.css").reader().readText()
Expand Down
Loading

0 comments on commit 5c4d9e6

Please sign in to comment.