From 2fa5456136de15ce3c8bec7fc465a01f4fbf4ce1 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Wed, 30 Oct 2024 07:53:53 +0800 Subject: [PATCH 01/21] Add a KDoc for `coroutineHandler` referring to the "vertx-lang-kotlin-coroutines" updates and fix some deprecated calls --- .../kotlin/coroutines/ext/web/CoroutineHandlers.kt | 14 ++++++++++++++ .../ext/web/ExtendedWebCoroutineVerticle.kt | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/CoroutineHandlers.kt b/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/CoroutineHandlers.kt index 8114448..e8a34d0 100644 --- a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/CoroutineHandlers.kt +++ b/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/CoroutineHandlers.kt @@ -5,11 +5,22 @@ import com.huanshankeji.vertx.kotlin.coroutines.ext.web.CoroutineHandlerLaunchMo import com.huanshankeji.vertx.kotlin.coroutines.ext.web.CoroutineHandlerLaunchMode.Unconfined import io.vertx.ext.web.Route import io.vertx.ext.web.RoutingContext +import io.vertx.kotlin.coroutines.CoroutineRouterSupport import io.vertx.kotlin.coroutines.CoroutineVerticle +import io.vertx.kotlin.coroutines.coroutineRouter import kotlinx.coroutines.* import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext +/** + * This function can be replaced by [coroutineRouter] and [CoroutineRouterSupport.coHandler] + * which is newly introduced to the official "vertx-lang-kotlin-coroutines" library. + * However, note that [CoroutineRouterSupport.coHandler] handles exceptions and is equivalent to [Route.checkedCoroutineHandler]. + * See the [official docs](https://vertx.io/docs/vertx-lang-kotlin-coroutines/kotlin/#_vert_x_web) for more details. + * + * This function is not deprecated yet and can still serve its purpose in some scenarios + * because the approach above is still a bit ugly for the lack of [context parameters](https://github.com/Kotlin/KEEP/issues/367). + */ fun Route.coroutineHandler( coroutineScope: CoroutineScope, context: CoroutineContext, start: CoroutineStart, @@ -73,6 +84,9 @@ fun coroutineHandler( ): Route = route.coroutineHandler(coroutineScope, launchMode, requestHandler) +/** + * @see coroutineHandler + */ // workaround for context receivers fun Route.checkedCoroutineHandler( coroutineScope: CoroutineScope, diff --git a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/ExtendedWebCoroutineVerticle.kt b/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/ExtendedWebCoroutineVerticle.kt index ecfa171..abea665 100644 --- a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/ExtendedWebCoroutineVerticle.kt +++ b/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/ExtendedWebCoroutineVerticle.kt @@ -16,7 +16,7 @@ interface ExtendedWebCoroutineVerticleI : CoroutineVerticleI { launchMode: CoroutineHandlerLaunchMode = DefaultOnVertxEventLoop, requestHandler: suspend (RoutingContext) -> Unit ): Route = - coroutineHandler(this@ExtendedWebCoroutineVerticleI, this, launchMode, requestHandler) + coroutineHandler(this@ExtendedWebCoroutineVerticleI, launchMode, requestHandler) /** * Like [coroutineHandler] and calls [RoutingContext.fail] if a [Throwable] is thrown in [requestHandler]. @@ -25,7 +25,7 @@ interface ExtendedWebCoroutineVerticleI : CoroutineVerticleI { launchMode: CoroutineHandlerLaunchMode = DefaultOnVertxEventLoop, requestHandler: suspend (RoutingContext) -> Unit ): Route = - checkedCoroutineHandler(this@ExtendedWebCoroutineVerticleI, this, launchMode, requestHandler) + checkedCoroutineHandler(this@ExtendedWebCoroutineVerticleI, launchMode, requestHandler) } abstract class ExtendedWebCoroutineVerticle : CoroutineVerticle(), ExtendedWebCoroutineVerticleI { From 9821bd2391fa54dd0641383c63515bc8121226c7 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Wed, 30 Oct 2024 22:22:10 +0800 Subject: [PATCH 02/21] Add kotlinx-io and Okio feature variants in the Vert.x module, and copy and adapt the Vert.x `Buffer` kotlinx-io `RawSink` conversion code and Vert.x `Buffer` Okio `Sink` conversion code here Fix the deprecation warning in `wrappedBuffer` BTW, though I am not sure whether `BufferImpl.buffer` will also be deprecated or made private in the future. The source commits: https://github.com/huanshankeji/FrameworkBenchmarks/commit/40ee72b748f56789826c4c2cbacded6476936254, https://github.com/huanshankeji/FrameworkBenchmarks/commit/43cc3180aaeb7191f5bed35ed4861577f4c57a7d --- README.md | 2 +- .../main/kotlin/VersionsAndDependencies.kt | 2 ++ settings.gradle.kts | 4 +++ vertx/build.gradle.kts | 9 +++++ .../com/huanshankeji/vertx/core/Buffer.kt | 3 +- .../vertx/kotlinx/io/Primitives.kt | 7 ++++ .../vertx/kotlinx/io/VertxBufferRawSink.kt | 25 ++++++++++++++ .../io/VertxBufferWriteStreamRawSink.kt | 30 ++++++++++++++++ .../vertx/okio/VertxBufferSink.kt | 27 +++++++++++++++ .../vertx/okio/VertxBufferWriteStreamSink.kt | 34 +++++++++++++++++++ 10 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/Primitives.kt create mode 100644 vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/VertxBufferRawSink.kt create mode 100644 vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/VertxBufferWriteStreamRawSink.kt create mode 100644 vertx/src/main/kotlin/com/huanshankeji/vertx/okio/VertxBufferSink.kt create mode 100644 vertx/src/main/kotlin/com/huanshankeji/vertx/okio/VertxBufferWriteStreamSink.kt diff --git a/README.md b/README.md index a83703f..4fd12f2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Huanshankeji's common code libraries in Kotlin -These include a core library to extend the Kotlin language and its standard library, and extension libraries for various Kotlin and Java libraries such as [Λrrow](https://arrow-kt.io/), Coroutines ([docs here](https://kotlinlang.org/docs/coroutines-overview.html) and [repository here](https://github.com/Kotlin/kotlinx.coroutines)), [Exposed](https://github.com/JetBrains/Exposed), [Ktor](https://ktor.io/), [reflection](https://kotlinlang.org/docs/reflection.html), Serialization ([docs here](https://kotlinlang.org/docs/serialization.html) and [repository here](https://github.com/Kotlin/kotlinx.serialization)), [Vert.x](https://vertx.io/), etc. For common extensions for Compose Multiplatform, check out [compose-multiplatform-common](https://github.com/huanshankeji/compose-multiplatform-material/tree/main/compose-multiplatform-common). +These include a core library to extend the Kotlin language and its standard library, and extension libraries for various Kotlin and Java libraries such as [Λrrow](https://arrow-kt.io/), Coroutines ([docs here](https://kotlinlang.org/docs/coroutines-overview.html) and [repository here](https://github.com/Kotlin/kotlinx.coroutines)), [Exposed](https://github.com/JetBrains/Exposed), [Ktor](https://ktor.io/), [reflection](https://kotlinlang.org/docs/reflection.html), Serialization ([docs here](https://kotlinlang.org/docs/serialization.html) and [repository here](https://github.com/Kotlin/kotlinx.serialization)), [Vert.x](https://vertx.io/) (along with extensions for [kotlinx-io](https://github.com/Kotlin/kotlinx-io) and [OKio](https://square.github.io/okio/)), etc. For common extensions for Compose Multiplatform, check out [compose-multiplatform-common](https://github.com/huanshankeji/compose-multiplatform-material/tree/main/compose-multiplatform-common). Currently supported targets by multiplatform libraries: JVM, JS (browser), iOS (`iosX64`, `iosArm64`, and `iosSimulatorArm64`) (except for the Coroutines module), and Wasm JS. diff --git a/buildSrc/src/main/kotlin/VersionsAndDependencies.kt b/buildSrc/src/main/kotlin/VersionsAndDependencies.kt index df828dd..d53e564 100644 --- a/buildSrc/src/main/kotlin/VersionsAndDependencies.kt +++ b/buildSrc/src/main/kotlin/VersionsAndDependencies.kt @@ -11,4 +11,6 @@ val commonGradleClasspathDependencies = CommonGradleClasspathDependencies(common object DependencyVersions { val protobufPlugin = "0.9.4" val protobuf = "3.25.2" // Not bumped. The version is a bit chaotic. + val kotlinxIo = "0.5.4" + val okio = "3.9.1" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 8cb783c..3c1558f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,6 +15,10 @@ include( "serialization:benchmark:jvm-only", "vertx", "vertx:with-context-receivers", + /* + "vertx:kotlinx-io", + "vertx:okio", + */ ) fun ProjectDescriptor.setProjectConcatenatedNames(prefix: String) { diff --git a/vertx/build.gradle.kts b/vertx/build.gradle.kts index b10093d..66dc2ca 100644 --- a/vertx/build.gradle.kts +++ b/vertx/build.gradle.kts @@ -11,6 +11,12 @@ java { registerFeature("vertxSqlClient") { usingSourceSet(sourceSets["main"]) } + registerFeature("kotlinxIo") { + usingSourceSet(sourceSets["main"]) + } + registerFeature("okio") { + usingSourceSet(sourceSets["main"]) + } } dependencies { @@ -23,6 +29,9 @@ dependencies { implementation(moduleWithoutVersion("lang-kotlin-coroutines")) } + "kotlinxIoImplementation"("org.jetbrains.kotlinx:kotlinx-io-core:${DependencyVersions.kotlinxIo}") + "okioImplementation"("com.squareup.okio:okio:${DependencyVersions.okio}") + implementation(cpnProject(project, ":core")) implementation(cpnProject(project, ":coroutines")) diff --git a/vertx/src/main/kotlin/com/huanshankeji/vertx/core/Buffer.kt b/vertx/src/main/kotlin/com/huanshankeji/vertx/core/Buffer.kt index 4733581..00f9b18 100644 --- a/vertx/src/main/kotlin/com/huanshankeji/vertx/core/Buffer.kt +++ b/vertx/src/main/kotlin/com/huanshankeji/vertx/core/Buffer.kt @@ -2,10 +2,11 @@ package com.huanshankeji.vertx.core import io.netty.buffer.Unpooled import io.vertx.core.buffer.Buffer +import io.vertx.core.buffer.impl.BufferImpl /** * Creates a wrapped [Buffer] so that unnecessary copy is avoided. * Also see https://github.com/eclipse-vertx/vert.x/issues/4407. */ fun wrappedBuffer(byteArray: ByteArray): Buffer = - Buffer.buffer(Unpooled.wrappedBuffer(byteArray)) + BufferImpl.buffer(Unpooled.wrappedBuffer(byteArray)) diff --git a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/Primitives.kt b/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/Primitives.kt new file mode 100644 index 0000000..93ce801 --- /dev/null +++ b/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/Primitives.kt @@ -0,0 +1,7 @@ +package com.huanshankeji.vertx.kotlinx.io + +@Suppress("NOTHING_TO_INLINE") +internal inline fun Long.toIntOrThrow(): Int { + require(this in Int.MIN_VALUE.toLong()..Int.MAX_VALUE.toLong()) + return toInt() +} diff --git a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/VertxBufferRawSink.kt b/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/VertxBufferRawSink.kt new file mode 100644 index 0000000..b8b60a9 --- /dev/null +++ b/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/VertxBufferRawSink.kt @@ -0,0 +1,25 @@ +package com.huanshankeji.vertx.kotlinx.io + +import kotlinx.io.RawSink +import kotlinx.io.Sink +import kotlinx.io.buffered +import kotlinx.io.readByteArray +import io.vertx.core.buffer.Buffer as VertxBuffer +import kotlinx.io.Buffer as KotlinxIoBuffer + +@JvmInline +value class VertxBufferRawSink(val vertxBuffer: VertxBuffer) : RawSink { + override fun write(source: KotlinxIoBuffer, byteCount: Long) { + vertxBuffer.appendBytes(source.readByteArray(byteCount.toIntOrThrow())) + } + + override fun flush() {} + + override fun close() {} +} + +fun VertxBuffer.toRawSink(): RawSink = + VertxBufferRawSink(this) + +fun VertxBuffer.toSink(): Sink = + toRawSink().buffered() diff --git a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/VertxBufferWriteStreamRawSink.kt b/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/VertxBufferWriteStreamRawSink.kt new file mode 100644 index 0000000..dc0e721 --- /dev/null +++ b/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/VertxBufferWriteStreamRawSink.kt @@ -0,0 +1,30 @@ +package com.huanshankeji.vertx.kotlinx.io + +import io.vertx.core.buffer.Buffer +import io.vertx.core.streams.WriteStream +import io.vertx.kotlin.coroutines.coAwait +import kotlinx.coroutines.runBlocking +import kotlinx.io.RawSink +import kotlinx.io.buffered +import kotlinx.io.readByteArray + +@JvmInline +value class VertxBufferWriteStreamRawSink(val writeStream: WriteStream) : RawSink { + override fun write(source: kotlinx.io.Buffer, byteCount: Long) { + runBlocking { + writeStream.write(Buffer.buffer(source.readByteArray(byteCount.toIntOrThrow()))).coAwait() + } + } + + override fun flush() {} + + override fun close() { + writeStream.end() + } +} + +fun WriteStream.toRawSink(): RawSink = + VertxBufferWriteStreamRawSink(this) + +fun WriteStream.toSink() = + toRawSink().buffered() diff --git a/vertx/src/main/kotlin/com/huanshankeji/vertx/okio/VertxBufferSink.kt b/vertx/src/main/kotlin/com/huanshankeji/vertx/okio/VertxBufferSink.kt new file mode 100644 index 0000000..1e72c88 --- /dev/null +++ b/vertx/src/main/kotlin/com/huanshankeji/vertx/okio/VertxBufferSink.kt @@ -0,0 +1,27 @@ +package com.huanshankeji.vertx.okio + +import okio.Buffer +import okio.Sink +import okio.Timeout +import okio.buffer +import io.vertx.core.buffer.Buffer as VertxBuffer + +@JvmInline +value class VertxBufferSink(val vertxBuffer: VertxBuffer) : Sink { + override fun write(source: Buffer, byteCount: Long) { + vertxBuffer.appendBytes(source.readByteArray(byteCount)) + } + + override fun flush() {} + + override fun timeout(): Timeout = + Timeout.NONE //timeout + + override fun close() {} +} + +fun VertxBuffer.toSink(): Sink = + VertxBufferSink(this) + +fun VertxBuffer.toBufferedSink() = + toSink().buffer() diff --git a/vertx/src/main/kotlin/com/huanshankeji/vertx/okio/VertxBufferWriteStreamSink.kt b/vertx/src/main/kotlin/com/huanshankeji/vertx/okio/VertxBufferWriteStreamSink.kt new file mode 100644 index 0000000..491de01 --- /dev/null +++ b/vertx/src/main/kotlin/com/huanshankeji/vertx/okio/VertxBufferWriteStreamSink.kt @@ -0,0 +1,34 @@ +package com.huanshankeji.vertx.okio + +import io.vertx.core.buffer.Buffer +import io.vertx.core.streams.WriteStream +import io.vertx.kotlin.coroutines.coAwait +import kotlinx.coroutines.runBlocking +import okio.Sink +import okio.Timeout +import okio.buffer + +@JvmInline +value class VertxBufferWriteStreamSink(val writeStream: WriteStream) : Sink { + override fun write(source: okio.Buffer, byteCount: Long) { + runBlocking { + writeStream.write(Buffer.buffer(source.readByteArray(byteCount))).coAwait() + } + } + + override fun flush() {} + + //private val timeout = Timeout() + override fun timeout(): Timeout = + Timeout.NONE //timeout + + override fun close() { + writeStream.end() + } +} + +fun WriteStream.toSink(): Sink = + VertxBufferWriteStreamSink(this) + +fun WriteStream.toBufferedSink(): Sink = + toSink().buffer() From da7bcd56e930fa94d1467584ad5f3904a75273e9 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Wed, 30 Oct 2024 22:45:01 +0800 Subject: [PATCH 03/21] Try also wrapping Vert.x `Buffer`s as `Source`s but give up because `Buffer` doesn't provide reading methods (by wrapping the underlying Netty `ByteBuf` methods) From 327af12f8259d87889f1e479f29e8126b599f294 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Wed, 30 Oct 2024 23:19:29 +0800 Subject: [PATCH 04/21] Move the code added in commit 9821bd2391fa54dd0641383c63515bc8121226c7 into the `com.huanshankeji.vertx.core` package --- .../com/huanshankeji/vertx/{ => core}/kotlinx/io/Primitives.kt | 2 +- .../vertx/{ => core}/kotlinx/io/VertxBufferRawSink.kt | 2 +- .../{ => core}/kotlinx/io/VertxBufferWriteStreamRawSink.kt | 2 +- .../com/huanshankeji/vertx/{ => core}/okio/VertxBufferSink.kt | 2 +- .../vertx/{ => core}/okio/VertxBufferWriteStreamSink.kt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename vertx/src/main/kotlin/com/huanshankeji/vertx/{ => core}/kotlinx/io/Primitives.kt (78%) rename vertx/src/main/kotlin/com/huanshankeji/vertx/{ => core}/kotlinx/io/VertxBufferRawSink.kt (93%) rename vertx/src/main/kotlin/com/huanshankeji/vertx/{ => core}/kotlinx/io/VertxBufferWriteStreamRawSink.kt (94%) rename vertx/src/main/kotlin/com/huanshankeji/vertx/{ => core}/okio/VertxBufferSink.kt (93%) rename vertx/src/main/kotlin/com/huanshankeji/vertx/{ => core}/okio/VertxBufferWriteStreamSink.kt (95%) diff --git a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/Primitives.kt b/vertx/src/main/kotlin/com/huanshankeji/vertx/core/kotlinx/io/Primitives.kt similarity index 78% rename from vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/Primitives.kt rename to vertx/src/main/kotlin/com/huanshankeji/vertx/core/kotlinx/io/Primitives.kt index 93ce801..6b03528 100644 --- a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/Primitives.kt +++ b/vertx/src/main/kotlin/com/huanshankeji/vertx/core/kotlinx/io/Primitives.kt @@ -1,4 +1,4 @@ -package com.huanshankeji.vertx.kotlinx.io +package com.huanshankeji.vertx.core.kotlinx.io @Suppress("NOTHING_TO_INLINE") internal inline fun Long.toIntOrThrow(): Int { diff --git a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/VertxBufferRawSink.kt b/vertx/src/main/kotlin/com/huanshankeji/vertx/core/kotlinx/io/VertxBufferRawSink.kt similarity index 93% rename from vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/VertxBufferRawSink.kt rename to vertx/src/main/kotlin/com/huanshankeji/vertx/core/kotlinx/io/VertxBufferRawSink.kt index b8b60a9..617ee85 100644 --- a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/VertxBufferRawSink.kt +++ b/vertx/src/main/kotlin/com/huanshankeji/vertx/core/kotlinx/io/VertxBufferRawSink.kt @@ -1,4 +1,4 @@ -package com.huanshankeji.vertx.kotlinx.io +package com.huanshankeji.vertx.core.kotlinx.io import kotlinx.io.RawSink import kotlinx.io.Sink diff --git a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/VertxBufferWriteStreamRawSink.kt b/vertx/src/main/kotlin/com/huanshankeji/vertx/core/kotlinx/io/VertxBufferWriteStreamRawSink.kt similarity index 94% rename from vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/VertxBufferWriteStreamRawSink.kt rename to vertx/src/main/kotlin/com/huanshankeji/vertx/core/kotlinx/io/VertxBufferWriteStreamRawSink.kt index dc0e721..2e42231 100644 --- a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlinx/io/VertxBufferWriteStreamRawSink.kt +++ b/vertx/src/main/kotlin/com/huanshankeji/vertx/core/kotlinx/io/VertxBufferWriteStreamRawSink.kt @@ -1,4 +1,4 @@ -package com.huanshankeji.vertx.kotlinx.io +package com.huanshankeji.vertx.core.kotlinx.io import io.vertx.core.buffer.Buffer import io.vertx.core.streams.WriteStream diff --git a/vertx/src/main/kotlin/com/huanshankeji/vertx/okio/VertxBufferSink.kt b/vertx/src/main/kotlin/com/huanshankeji/vertx/core/okio/VertxBufferSink.kt similarity index 93% rename from vertx/src/main/kotlin/com/huanshankeji/vertx/okio/VertxBufferSink.kt rename to vertx/src/main/kotlin/com/huanshankeji/vertx/core/okio/VertxBufferSink.kt index 1e72c88..8dd69e6 100644 --- a/vertx/src/main/kotlin/com/huanshankeji/vertx/okio/VertxBufferSink.kt +++ b/vertx/src/main/kotlin/com/huanshankeji/vertx/core/okio/VertxBufferSink.kt @@ -1,4 +1,4 @@ -package com.huanshankeji.vertx.okio +package com.huanshankeji.vertx.core.okio import okio.Buffer import okio.Sink diff --git a/vertx/src/main/kotlin/com/huanshankeji/vertx/okio/VertxBufferWriteStreamSink.kt b/vertx/src/main/kotlin/com/huanshankeji/vertx/core/okio/VertxBufferWriteStreamSink.kt similarity index 95% rename from vertx/src/main/kotlin/com/huanshankeji/vertx/okio/VertxBufferWriteStreamSink.kt rename to vertx/src/main/kotlin/com/huanshankeji/vertx/core/okio/VertxBufferWriteStreamSink.kt index 491de01..fffac8d 100644 --- a/vertx/src/main/kotlin/com/huanshankeji/vertx/okio/VertxBufferWriteStreamSink.kt +++ b/vertx/src/main/kotlin/com/huanshankeji/vertx/core/okio/VertxBufferWriteStreamSink.kt @@ -1,4 +1,4 @@ -package com.huanshankeji.vertx.okio +package com.huanshankeji.vertx.core.okio import io.vertx.core.buffer.Buffer import io.vertx.core.streams.WriteStream From 2853332d0b0a5a428241ba4839b6059193f82888 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Thu, 31 Oct 2024 22:03:31 +0800 Subject: [PATCH 05/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4fd12f2..2271091 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Huanshankeji's common code libraries in Kotlin These include a core library to extend the Kotlin language and its standard library, and extension libraries for various Kotlin and Java libraries such as [Λrrow](https://arrow-kt.io/), Coroutines ([docs here](https://kotlinlang.org/docs/coroutines-overview.html) and [repository here](https://github.com/Kotlin/kotlinx.coroutines)), [Exposed](https://github.com/JetBrains/Exposed), [Ktor](https://ktor.io/), [reflection](https://kotlinlang.org/docs/reflection.html), Serialization ([docs here](https://kotlinlang.org/docs/serialization.html) and [repository here](https://github.com/Kotlin/kotlinx.serialization)), [Vert.x](https://vertx.io/) (along with extensions for [kotlinx-io](https://github.com/Kotlin/kotlinx-io) and [OKio](https://square.github.io/okio/)), etc. For common extensions for Compose Multiplatform, check out [compose-multiplatform-common](https://github.com/huanshankeji/compose-multiplatform-material/tree/main/compose-multiplatform-common). -Currently supported targets by multiplatform libraries: JVM, JS (browser), iOS (`iosX64`, `iosArm64`, and `iosSimulatorArm64`) (except for the Coroutines module), and Wasm JS. +Currently supported targets by multiplatform libraries: JVM, JS (browser), iOS (`iosX64`, `iosArm64`, and `iosSimulatorArm64`), and Wasm JS. ## Maven coordinates From 1f1c12732eaf5d8a05a55b9ed08334e49851fc8b Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Fri, 1 Nov 2024 11:57:53 +0800 Subject: [PATCH 06/21] Run IntelliJ IDEA Code Cleanup, review the changes, revert some, and manually update some code --- .../kotlin/reflect/ConcreteTypeTest.kt | 8 ++++---- .../kotlin/reflect/KTypeUnification.kt | 2 +- .../vertx/kotlin/coroutines/VertxCoroutine.kt | 10 +++++----- .../vertx/kotlin/sqlclient/PreparedQuery.kt | 4 ++-- .../vertx/ext/web/RoutingContextBaseTest.kt | 8 ++++---- .../vertx/kotlin/coroutines/VertxCoroutineTest.kt | 10 +++++----- .../coroutines/ext/web/CoroutineHandlersTest.kt | 12 ++++++------ .../ext/web/ExtendedWebCoroutineVerticleTest.kt | 14 +++++++------- 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/reflect/src/commonTest/kotlin/com/huanshankeji/kotlin/reflect/ConcreteTypeTest.kt b/reflect/src/commonTest/kotlin/com/huanshankeji/kotlin/reflect/ConcreteTypeTest.kt index ee8cdad..226338e 100644 --- a/reflect/src/commonTest/kotlin/com/huanshankeji/kotlin/reflect/ConcreteTypeTest.kt +++ b/reflect/src/commonTest/kotlin/com/huanshankeji/kotlin/reflect/ConcreteTypeTest.kt @@ -7,9 +7,9 @@ import kotlin.test.assertTrue class ConcreteTypeTest { @Test - fun testIsConcreteType() { - assertTrue(typeOf().isConcreteType()) - assertTrue(typeOf>().isConcreteType()) - assertFalse(typeOf>().isConcreteType()) + fun testIsConcreteTypeWithAllActualKClasses() { + assertTrue(typeOf().isConcreteTypeWithAllActualKClasses()) + assertTrue(typeOf>().isConcreteTypeWithAllActualKClasses()) + assertFalse(typeOf>().isConcreteTypeWithAllActualKClasses()) } } \ No newline at end of file diff --git a/reflect/src/jvmMain/kotlin/com/huanshankeji/kotlin/reflect/KTypeUnification.kt b/reflect/src/jvmMain/kotlin/com/huanshankeji/kotlin/reflect/KTypeUnification.kt index 307a904..b940db2 100644 --- a/reflect/src/jvmMain/kotlin/com/huanshankeji/kotlin/reflect/KTypeUnification.kt +++ b/reflect/src/jvmMain/kotlin/com/huanshankeji/kotlin/reflect/KTypeUnification.kt @@ -9,7 +9,7 @@ import kotlin.reflect.KTypeParameter * @return `null` when it fails */ fun concreteTypeUnify(knowConcreteType: KType, typeWithVariables: KType): Substitution? { - require(knowConcreteType.isConcreteType()) + require(knowConcreteType.isConcreteTypeWithAllActualKClasses()) val result = mutableMapOf() return if (doConcreteTypeUnify(knowConcreteType, typeWithVariables, result)) result else null diff --git a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/coroutines/VertxCoroutine.kt b/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/coroutines/VertxCoroutine.kt index 43fba0d..c76c041 100644 --- a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/coroutines/VertxCoroutine.kt +++ b/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/coroutines/VertxCoroutine.kt @@ -5,7 +5,7 @@ import io.vertx.core.Future import io.vertx.core.Handler import io.vertx.core.Promise import io.vertx.core.Vertx -import io.vertx.kotlin.coroutines.await +import io.vertx.kotlin.coroutines.coAwait import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.coroutineScope @@ -19,7 +19,7 @@ import kotlin.coroutines.EmptyCoroutineContext */ suspend inline fun Vertx.use(block: (Vertx) -> R): R = @Suppress("MoveLambdaOutsideParentheses") - use(block, { close().await() }) + use(block, { close().coAwait() }) /** * Execute [blockingCode] that returns the a [T] instance with [Vertx.executeBlocking] @@ -31,7 +31,7 @@ suspend inline fun Vertx.use(block: (Vertx) -> R): R = suspend fun Vertx.awaitExecuteBlocking(blockingCode: () -> T): T = executeBlocking(Callable { blockingCode() - }).await() + }).coAwait() // TODO: this should probably be removed /** @@ -43,7 +43,7 @@ suspend fun Vertx.awaitSuspendExecuteBlocking(blockingCode: suspend () -> T) coroutineScope { executeBlocking(Handler> { launch { it.complete(blockingCode()) } - }).await() + }).coAwait() } /** @@ -73,4 +73,4 @@ fun CoroutineScope.coroutineToFuture( * @see kotlinx.coroutines.awaitAll */ suspend fun List>.awaitAll(): List = - Future.all(this).await().list() + Future.all(this).coAwait().list() diff --git a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/sqlclient/PreparedQuery.kt b/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/sqlclient/PreparedQuery.kt index 8494f72..c2fb485 100644 --- a/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/sqlclient/PreparedQuery.kt +++ b/vertx/src/main/kotlin/com/huanshankeji/vertx/kotlin/sqlclient/PreparedQuery.kt @@ -1,9 +1,9 @@ package com.huanshankeji.vertx.kotlin.sqlclient -import io.vertx.kotlin.coroutines.await +import io.vertx.kotlin.coroutines.coAwait import io.vertx.sqlclient.PreparedQuery import io.vertx.sqlclient.SqlResult import io.vertx.sqlclient.Tuple suspend fun > PreparedQuery.executeBatchAwaitForSqlResultSequence(batch: List) = - executeBatch(batch).await().batchSqlResultSequence() + executeBatch(batch).coAwait().batchSqlResultSequence() diff --git a/vertx/src/test/kotlin/com/huanshankeji/vertx/ext/web/RoutingContextBaseTest.kt b/vertx/src/test/kotlin/com/huanshankeji/vertx/ext/web/RoutingContextBaseTest.kt index 2896542..54200a2 100644 --- a/vertx/src/test/kotlin/com/huanshankeji/vertx/ext/web/RoutingContextBaseTest.kt +++ b/vertx/src/test/kotlin/com/huanshankeji/vertx/ext/web/RoutingContextBaseTest.kt @@ -7,7 +7,7 @@ import io.vertx.ext.web.Router import io.vertx.ext.web.RoutingContext import io.vertx.ext.web.client.WebClient import io.vertx.junit5.VertxTestContext -import io.vertx.kotlin.coroutines.await +import io.vertx.kotlin.coroutines.coAwait import kotlin.test.assertEquals import kotlin.test.assertTrue @@ -33,13 +33,13 @@ abstract class RoutingContextBaseTest : VertxBaseTest() { it.next() } - }).listen(0).await() + }).listen(0).coAwait() httpServer.use({ val port = httpServer.actualPort() WebClient.create(vertx).use({ - assertEquals(500, it.get(port, LOCALHOST, "").send().await().statusCode()) + assertEquals(500, it.get(port, LOCALHOST, "").send().coAwait().statusCode()) }, { close() }) - }, { close().await() }) + }, { close().coAwait() }) } } \ No newline at end of file diff --git a/vertx/src/test/kotlin/com/huanshankeji/vertx/kotlin/coroutines/VertxCoroutineTest.kt b/vertx/src/test/kotlin/com/huanshankeji/vertx/kotlin/coroutines/VertxCoroutineTest.kt index c04bdad..618516c 100644 --- a/vertx/src/test/kotlin/com/huanshankeji/vertx/kotlin/coroutines/VertxCoroutineTest.kt +++ b/vertx/src/test/kotlin/com/huanshankeji/vertx/kotlin/coroutines/VertxCoroutineTest.kt @@ -7,7 +7,7 @@ import io.vertx.core.AbstractVerticle import io.vertx.core.Promise import io.vertx.core.Vertx import io.vertx.core.impl.NoStackTraceThrowable -import io.vertx.kotlin.coroutines.await +import io.vertx.kotlin.coroutines.coAwait import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.delay @@ -26,7 +26,7 @@ class VertxCoroutineTest : VertxBaseTest() { suspend fun assertClosed(vertx: Vertx) = assertThrows { - vertx.deployVerticle(DummyVerticle()).await() + vertx.deployVerticle(DummyVerticle()).coAwait() } @Test @@ -34,7 +34,7 @@ class VertxCoroutineTest : VertxBaseTest() { val vertx = Vertx.vertx() vertx.use { assertDoesNotThrow { - vertx.deployVerticle(DummyVerticle()).await() + vertx.deployVerticle(DummyVerticle()).coAwait() } } assertClosed(vertx) @@ -82,14 +82,14 @@ class VertxCoroutineTest : VertxBaseTest() { assertTrue(measureVirtualTime { coroutineToFuture { delay(DEFAULT_SLEEP_OR_DELAY_DURATION) - }.await() + }.coAwait() } >= DEFAULT_SLEEP_OR_DELAY_DURATION) assertTrue(measureTimeMillis { coroutineToFuture { @Suppress("BlockingMethodInNonBlockingContext") Thread.sleep(DEFAULT_SLEEP_OR_DELAY_DURATION) - }.await() + }.coAwait() } >= DEFAULT_SLEEP_OR_DELAY_DURATION) } diff --git a/vertx/src/test/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/CoroutineHandlersTest.kt b/vertx/src/test/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/CoroutineHandlersTest.kt index a96cd36..16148d1 100644 --- a/vertx/src/test/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/CoroutineHandlersTest.kt +++ b/vertx/src/test/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/CoroutineHandlersTest.kt @@ -6,7 +6,7 @@ import com.huanshankeji.vertx.kotlin.coroutines.ext.web.CoroutineHandlerLaunchMo import com.huanshankeji.vertx.kotlin.coroutines.ext.web.CoroutineHandlerLaunchMode.Unconfined import io.vertx.ext.web.Router import io.vertx.ext.web.client.WebClient -import io.vertx.kotlin.coroutines.await +import io.vertx.kotlin.coroutines.coAwait import io.vertx.kotlin.coroutines.dispatcher import io.vertx.kotlin.ext.web.client.webClientOptionsOf import kotlinx.coroutines.delay @@ -32,23 +32,23 @@ class CoroutineHandlersTest : VertxBaseTest() { fun isOnDefaultExecutor() = Thread.currentThread().name.contains("kotlinx.coroutines.DefaultExecutor") - coroutineHandler(this@withContext, get(DEFAULT_PATH), DefaultOnVertxEventLoop) { + get(DEFAULT_PATH).coroutineHandler(this@withContext, DefaultOnVertxEventLoop) { assertTrue(isOnVertxEventLoop()) delay(1) assertTrue(isOnVertxEventLoop()) it.response().end() } - coroutineHandler(this@withContext, get(UNCONFINED_PATH), Unconfined) { + get(UNCONFINED_PATH).coroutineHandler(this@withContext, Unconfined) { assertTrue(isOnVertxEventLoop()) delay(1) assertTrue(isOnDefaultExecutor()) it.response().end() } - }).listen(0).await() + }).listen(0).coAwait() WebClient.create(vertx, webClientOptionsOf(defaultPort = httpServer.actualPort())).use({ webClient -> - webClient.get(DEFAULT_PATH).send().await() - webClient.get(UNCONFINED_PATH).send().await() + webClient.get(DEFAULT_PATH).send().coAwait() + webClient.get(UNCONFINED_PATH).send().coAwait() }, { close() }) } } diff --git a/vertx/src/test/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/ExtendedWebCoroutineVerticleTest.kt b/vertx/src/test/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/ExtendedWebCoroutineVerticleTest.kt index a6f8ca7..26957f9 100644 --- a/vertx/src/test/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/ExtendedWebCoroutineVerticleTest.kt +++ b/vertx/src/test/kotlin/com/huanshankeji/vertx/kotlin/coroutines/ext/web/ExtendedWebCoroutineVerticleTest.kt @@ -6,7 +6,7 @@ import io.vertx.core.http.HttpServer import io.vertx.ext.web.Router import io.vertx.ext.web.RoutingContext import io.vertx.ext.web.client.WebClient -import io.vertx.kotlin.coroutines.await +import io.vertx.kotlin.coroutines.coAwait import io.vertx.kotlin.ext.web.client.webClientOptionsOf import kotlinx.coroutines.test.runTest import kotlin.test.Test @@ -41,27 +41,27 @@ class ExtendedWebCoroutineVerticleTest : VertxBaseTest() { get("/$checkedCoroutineHandlerInline").checkedCoroutineHandlerInline(requestHandler = handler) } }) - .listen(0).await() + .listen(0).coAwait() } override suspend fun stop() { - httpServer.close().await() + httpServer.close().coAwait() } } @Test fun `test ExtendedCoroutineVerticle`() = runTest { val verticle = Verticle() - val deploymentId = vertx.deployVerticle(verticle).await() + val deploymentId = vertx.deployVerticle(verticle).coAwait() WebClient.create(vertx, webClientOptionsOf(defaultPort = verticle.httpServer.actualPort())).use({ webClient -> suspend fun testOk(methodName: String) { - assertEquals(200, webClient.get("/$methodName").send().await().statusCode()) + assertEquals(200, webClient.get("/$methodName").send().coAwait().statusCode()) } suspend fun testThrowable(methodName: String) { testOk(methodName) - assertEquals(500, webClient.get("/$methodName?throws=true").send().await().statusCode()) + assertEquals(500, webClient.get("/$methodName?throws=true").send().coAwait().statusCode()) } with(MemberFunctionNames) { @@ -71,6 +71,6 @@ class ExtendedWebCoroutineVerticleTest : VertxBaseTest() { } }, { close() }) - vertx.undeploy(deploymentId).await() + vertx.undeploy(deploymentId).coAwait() } } \ No newline at end of file From cc30d2c7ef72b3ef14d4074c4999b7798e57e6aa Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Fri, 1 Nov 2024 14:51:58 +0800 Subject: [PATCH 07/21] Adapt to the Exposed SELECT DSL design changes and bump the project version --- .../main/kotlin/VersionsAndDependencies.kt | 2 +- exposed/build.gradle.kts | 4 +++ .../kotlin/com/huanshankeji/exposed/Slice.kt | 5 +++ .../com/huanshankeji/exposed/Statements.kt | 33 +++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/VersionsAndDependencies.kt b/buildSrc/src/main/kotlin/VersionsAndDependencies.kt index d53e564..5c1775c 100644 --- a/buildSrc/src/main/kotlin/VersionsAndDependencies.kt +++ b/buildSrc/src/main/kotlin/VersionsAndDependencies.kt @@ -2,7 +2,7 @@ import com.huanshankeji.CommonDependencies import com.huanshankeji.CommonGradleClasspathDependencies import com.huanshankeji.CommonVersions -val projectVersion = "0.5.2-SNAPSHOT" +val projectVersion = "0.6.0-SNAPSHOT" val commonVersions = CommonVersions(arrow = "2.0.0-alpha.4") // for Wasm JS val commonDependencies = CommonDependencies(commonVersions) diff --git a/exposed/build.gradle.kts b/exposed/build.gradle.kts index b8cf5d6..1be3561 100644 --- a/exposed/build.gradle.kts +++ b/exposed/build.gradle.kts @@ -1,8 +1,12 @@ +import com.huanshankeji.cpnProject + plugins { id("jvm-conventions") } dependencies { + implementation(cpnProject(project, ":core")) // for the `@Untested` annotation + implementation(commonDependencies.exposed.core()) testImplementation(kotlin("test")) } diff --git a/exposed/src/main/kotlin/com/huanshankeji/exposed/Slice.kt b/exposed/src/main/kotlin/com/huanshankeji/exposed/Slice.kt index 5a27441..2f92bf4 100644 --- a/exposed/src/main/kotlin/com/huanshankeji/exposed/Slice.kt +++ b/exposed/src/main/kotlin/com/huanshankeji/exposed/Slice.kt @@ -1,5 +1,6 @@ package com.huanshankeji.exposed +import com.huanshankeji.Untested import org.jetbrains.exposed.sql.ColumnSet /** @@ -9,3 +10,7 @@ import org.jetbrains.exposed.sql.ColumnSet @Deprecated("This causes \"java.lang.IllegalArgumentException: Can't prepare SELECT statement without columns or expressions to retrieve\" in the latest version of Exposed.") fun ColumnSet.emptySlice() = slice(emptyList()) + +@Untested +fun ColumnSet.selectEmpty() = + select(emptyList()) diff --git a/exposed/src/main/kotlin/com/huanshankeji/exposed/Statements.kt b/exposed/src/main/kotlin/com/huanshankeji/exposed/Statements.kt index 73b4f8e..d32e687 100644 --- a/exposed/src/main/kotlin/com/huanshankeji/exposed/Statements.kt +++ b/exposed/src/main/kotlin/com/huanshankeji/exposed/Statements.kt @@ -3,22 +3,55 @@ package com.huanshankeji.exposed import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.statements.* +private const val SELECT_DSL_DEPRECATION_MESSAGE = + "As part of Exposed SELECT DSL design changes, this will be removed in future releases." + // The select queries are not executed eagerly so just use them directly. /** * Adapted from [org.jetbrains.exposed.sql.select]. */ +@Deprecated( + SELECT_DSL_DEPRECATION_MESSAGE, + ReplaceWith("selectAllStatement().where(where)") +) fun FieldSet.selectStatement(where: WhereOp): Query = select(where) /** * Adapted from [org.jetbrains.exposed.sql.select]. */ +@Deprecated( + SELECT_DSL_DEPRECATION_MESSAGE, + ReplaceWith("selectAllStatement().where(where)") +) fun FieldSet.selectStatement(where: BuildWhere): Query = select(where) +@Deprecated( + SELECT_DSL_DEPRECATION_MESSAGE, + ReplaceWith("selectAllStatement().where(where)") +) fun T.selectStatementTableAware(where: TableAwareBuildWhere): Query = selectStatement(where()) +/** + * You can also just use [selectAll]. + */ +fun FieldSet.selectAllStatement() = + selectAll() + +/** + * You can also just use [select]. + */ +fun ColumnSet.selectStatement(columns: List>) = + select(columns) + +/** + * You can also just use [select]. + */ +fun ColumnSet.selectStatement(column: Expression<*>, vararg columns: Expression<*>): Query = + select(column, *columns) + /** * @see org.jetbrains.exposed.sql.deleteAll */ From 589f86d0a417bb65cf78720bcfcd7c90f78e35de Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Mon, 4 Nov 2024 11:25:55 +0800 Subject: [PATCH 08/21] Add kotlin-multiplatform-ci.yml from our workflow template --- .github/workflows/kotlin-multiplatform-ci.yml | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/kotlin-multiplatform-ci.yml diff --git a/.github/workflows/kotlin-multiplatform-ci.yml b/.github/workflows/kotlin-multiplatform-ci.yml new file mode 100644 index 0000000..89008e6 --- /dev/null +++ b/.github/workflows/kotlin-multiplatform-ci.yml @@ -0,0 +1,45 @@ +name: CI + +on: + push: + branches: [ "*" ] +# pull_request: +# branches: [ "*" ] + +jobs: + check: + + runs-on: macos-latest + permissions: + contents: read + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 8 + uses: actions/setup-java@v4 + with: + java-version: '8' + distribution: 'zulu' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Check with Gradle Wrapper + run: ./gradlew check + + dependency-submission: + + runs-on: macos-latest + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 8 + uses: actions/setup-java@v4 + with: + java-version: '8' + distribution: 'zulu' + + - name: Generate and submit dependency graph + uses: gradle/actions/dependency-submission@v4 From 3aa728bdf01d6b92304a831b9b4b29f9f32b93db Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Mon, 4 Nov 2024 12:37:22 +0800 Subject: [PATCH 09/21] Increase the Gradle JVM heap space because it's not enough for the CI The messages from the CI workflow: ```text The Daemon will expire after the build after running out of JVM heap space. The project memory settings are likely not configured or are configured to an insufficient value. The daemon will restart for the next build, which may increase subsequent build times. These settings can be adjusted by setting 'org.gradle.jvmargs' in 'gradle.properties'. The currently configured max heap space is '341.5 MiB' and the configured max metaspace is '384 MiB'. For more information on how to set these values, please refer to https://docs.gradle.org/8.10.2/userguide/build_environment.html#sec:configuring_jvm_memory in the Gradle documentation. To disable this warning, set 'org.gradle.daemon.performance.disable-logging=true'. Daemon will be stopped at the end of the build after running out of JVM heap space ``` ```text > Task :kotlin-common-core:linkDebugTestIosSimulatorArm64 w: Failed to build cache: GC overhead limit exceeded java.lang.OutOfMemoryError: GC overhead limit exceeded ``` --- gradle.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle.properties b/gradle.properties index 2dcadc5..bb314b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,2 @@ kotlin.mpp.stability.nowarn=true +org.gradle.jvmargs=-Xmx4G From d3a0146eb9edf91a1be9999ef06027c007e023a0 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Mon, 4 Nov 2024 12:42:56 +0800 Subject: [PATCH 10/21] Execute Gradle tasks in parallel by default --- gradle.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle.properties b/gradle.properties index bb314b4..f20353f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,3 @@ kotlin.mpp.stability.nowarn=true org.gradle.jvmargs=-Xmx4G +org.gradle.parallel=true From bf1615fa7ffebb8084b0d840abf6e7a457d7edf0 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Mon, 4 Nov 2024 12:43:38 +0800 Subject: [PATCH 11/21] Add a comment --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index f20353f..d5e6fdb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ kotlin.mpp.stability.nowarn=true -org.gradle.jvmargs=-Xmx4G +org.gradle.jvmargs=-Xmx4G # needed for the GitHub Actions CI org.gradle.parallel=true From c99f86b5f1780c9c22d4f50fde81ecbe186ac63e Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Mon, 4 Nov 2024 13:20:33 +0800 Subject: [PATCH 12/21] Fix the comment in the previous commit --- gradle.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index d5e6fdb..930bb54 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,4 @@ kotlin.mpp.stability.nowarn=true -org.gradle.jvmargs=-Xmx4G # needed for the GitHub Actions CI +# needed for the GitHub Actions CI +org.gradle.jvmargs=-Xmx4G org.gradle.parallel=true From 142225da80d4ce85a8fb739f6b38bb7ad29374ed Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Mon, 4 Nov 2024 13:35:25 +0800 Subject: [PATCH 13/21] Revert "Execute Gradle tasks in parallel by default" This reverts commit d3a0146eb9edf91a1be9999ef06027c007e023a0. Running in parallel makes GitHub Actions CI run longer so this change is reverted. --- gradle.properties | 1 - 1 file changed, 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 930bb54..29f9702 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,3 @@ kotlin.mpp.stability.nowarn=true # needed for the GitHub Actions CI org.gradle.jvmargs=-Xmx4G -org.gradle.parallel=true From 1f6c6dbe67a9600baf28f665a572e2599e0403c8 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Mon, 4 Nov 2024 14:00:21 +0800 Subject: [PATCH 14/21] Fix a typo in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2271091..3e51254 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Huanshankeji's common code libraries in Kotlin -These include a core library to extend the Kotlin language and its standard library, and extension libraries for various Kotlin and Java libraries such as [Λrrow](https://arrow-kt.io/), Coroutines ([docs here](https://kotlinlang.org/docs/coroutines-overview.html) and [repository here](https://github.com/Kotlin/kotlinx.coroutines)), [Exposed](https://github.com/JetBrains/Exposed), [Ktor](https://ktor.io/), [reflection](https://kotlinlang.org/docs/reflection.html), Serialization ([docs here](https://kotlinlang.org/docs/serialization.html) and [repository here](https://github.com/Kotlin/kotlinx.serialization)), [Vert.x](https://vertx.io/) (along with extensions for [kotlinx-io](https://github.com/Kotlin/kotlinx-io) and [OKio](https://square.github.io/okio/)), etc. For common extensions for Compose Multiplatform, check out [compose-multiplatform-common](https://github.com/huanshankeji/compose-multiplatform-material/tree/main/compose-multiplatform-common). +These include a core library to extend the Kotlin language and its standard library, and extension libraries for various Kotlin and Java libraries such as [Λrrow](https://arrow-kt.io/), Coroutines ([docs here](https://kotlinlang.org/docs/coroutines-overview.html) and [repository here](https://github.com/Kotlin/kotlinx.coroutines)), [Exposed](https://github.com/JetBrains/Exposed), [Ktor](https://ktor.io/), [reflection](https://kotlinlang.org/docs/reflection.html), Serialization ([docs here](https://kotlinlang.org/docs/serialization.html) and [repository here](https://github.com/Kotlin/kotlinx.serialization)), [Vert.x](https://vertx.io/) (along with extensions for [kotlinx-io](https://github.com/Kotlin/kotlinx-io) and [Okio](https://square.github.io/okio/)), etc. For common extensions for Compose Multiplatform, check out [compose-multiplatform-common](https://github.com/huanshankeji/compose-multiplatform-material/tree/main/compose-multiplatform-common). Currently supported targets by multiplatform libraries: JVM, JS (browser), iOS (`iosX64`, `iosArm64`, and `iosSimulatorArm64`), and Wasm JS. From 39fb14c48df950e10371b6daaf75bcba2d72b1ba Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Tue, 5 Nov 2024 12:19:33 +0800 Subject: [PATCH 15/21] Initially add code to generate KDoc HTML with Dokka --- build.gradle.kts | 25 +++++++++++++++++++ buildSrc/build.gradle.kts | 1 + .../main/kotlin/common-conventions.gradle.kts | 1 + .../main/kotlin/dokka-convention.gradle.kts | 21 ++++++++++++++++ gradle.properties | 2 ++ 5 files changed, 50 insertions(+) create mode 100644 buildSrc/src/main/kotlin/dokka-convention.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts index 1241019..67bc02e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,28 @@ +import com.huanshankeji.cpnProject + tasks.wrapper { distributionType = Wrapper.DistributionType.ALL } + +plugins { + id("org.jetbrains.dokka") +} + +dependencies { + listOf( + "core", + "net", + "web", + + "arrow", + "coroutines", + "exposed", + "ktor:client", + "reflect", + "serialization", + "vertx", + "vertx:with-context-receivers", + ).forEach { + dokka(cpnProject(project, ":$it")) + } +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index bf8774c..6a6f9e2 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -19,4 +19,5 @@ dependencies { implementation(kotlin("gradle-plugin", "2.0.10")) implementation("com.huanshankeji:common-gradle-dependencies:0.8.0-20241016") // don't use a snapshot version in a main branch implementation("com.huanshankeji.team:gradle-plugins:0.6.0") // don't use a snapshot version in a main branch + implementation("org.jetbrains.dokka:dokka-gradle-plugin:2.0.0-Beta") } diff --git a/buildSrc/src/main/kotlin/common-conventions.gradle.kts b/buildSrc/src/main/kotlin/common-conventions.gradle.kts index 4241d0e..4d9114e 100644 --- a/buildSrc/src/main/kotlin/common-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/common-conventions.gradle.kts @@ -5,6 +5,7 @@ plugins { id("com.huanshankeji.team.with-group") id("maven-central") id("com.huanshankeji.team.default-github-packages-maven-publish") + id("dokka-convention") } version = projectVersion diff --git a/buildSrc/src/main/kotlin/dokka-convention.gradle.kts b/buildSrc/src/main/kotlin/dokka-convention.gradle.kts new file mode 100644 index 0000000..0ae0853 --- /dev/null +++ b/buildSrc/src/main/kotlin/dokka-convention.gradle.kts @@ -0,0 +1,21 @@ +plugins { + id("org.jetbrains.dokka") +} + +dokka { + // TODO + /* + moduleName.set("Huanshankeji Kotlin Common") + dokkaSourceSets.named("main") { + includes.from("README.md") + sourceLink { + localDirectory.set(file("src/main/kotlin")) + remoteUrl("https://github.com/huanshankeji/kotlin-common/tree/v${version}") + remoteLineSuffix.set("#L") + } + pluginsConfiguration.html { + footerMessage.set("(c) Yongshun Ye") + } + } + */ +} diff --git a/gradle.properties b/gradle.properties index 29f9702..5fc7d29 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,5 @@ kotlin.mpp.stability.nowarn=true # needed for the GitHub Actions CI org.gradle.jvmargs=-Xmx4G +# for Dokka +org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled From 29055458c1967fe325b023269410541b307b561d Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Tue, 5 Nov 2024 15:48:37 +0800 Subject: [PATCH 16/21] Adjust configuration options and correct the source URL There is a problem that when I open the generated root "index.html" from IntelliJ IDEA, it shows the "kotlin-common-serialization" module. This may be a bug of IntelliJ IDEA, or a bug of Dokka, or the result of my misconfiguration. --- .../main/kotlin/dokka-convention.gradle.kts | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/buildSrc/src/main/kotlin/dokka-convention.gradle.kts b/buildSrc/src/main/kotlin/dokka-convention.gradle.kts index 0ae0853..d214a55 100644 --- a/buildSrc/src/main/kotlin/dokka-convention.gradle.kts +++ b/buildSrc/src/main/kotlin/dokka-convention.gradle.kts @@ -3,19 +3,22 @@ plugins { } dokka { - // TODO - /* - moduleName.set("Huanshankeji Kotlin Common") - dokkaSourceSets.named("main") { - includes.from("README.md") + //moduleName.set("Huanshankeji Kotlin Common") + dokkaSourceSets.all { + //includes.from("README.md") sourceLink { - localDirectory.set(file("src/main/kotlin")) - remoteUrl("https://github.com/huanshankeji/kotlin-common/tree/v${version}") + //localDirectory.set(file("src/main/kotlin")) + remoteUrl( + "https://github.com/huanshankeji/kotlin-common/tree/v${version}/${ + with(project) { + name.removePrefix(parent!!.name + '-') + } + }" + ) remoteLineSuffix.set("#L") } - pluginsConfiguration.html { + /*pluginsConfiguration.html { footerMessage.set("(c) Yongshun Ye") - } + }*/ } - */ } From b06299af90a13ab54cd56ce00104723536f80117 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Tue, 5 Nov 2024 16:09:37 +0800 Subject: [PATCH 17/21] Add a GitHub Actions workflow file to deploy the API documentation to GitHub Pages with Dokka, copied and adapted from https://github.com/huanshankeji/compose-multiplatform-material/blob/main/.github/workflows/demo-gh-pages.yml --- .github/workflows/dokka-gh-pages.yml | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/dokka-gh-pages.yml diff --git a/.github/workflows/dokka-gh-pages.yml b/.github/workflows/dokka-gh-pages.yml new file mode 100644 index 0000000..bf93269 --- /dev/null +++ b/.github/workflows/dokka-gh-pages.yml @@ -0,0 +1,61 @@ +name: Deploy the API documentation to GitHub Pages with Dokka + +on: + push: + branches: [ "release" ] + pull_request: + branches: [ "release" ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # Build job + build: + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Pages + uses: actions/configure-pages@v5 + + - name: Set up JDK 8 + uses: actions/setup-java@v4 + with: + java-version: "8" + distribution: "zulu" + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Build the distribution with Gradle Wrapper + run: ./gradlew :dokkaGeneratePublicationHtml + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: demo/build/dist/sideBySide/productionExecutable/ + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 From 101bc0ca48181e42663772ffeea297bacc4c2fd8 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Tue, 5 Nov 2024 16:48:17 +0800 Subject: [PATCH 18/21] Update the deployment upload path which was neglected --- .github/workflows/dokka-gh-pages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dokka-gh-pages.yml b/.github/workflows/dokka-gh-pages.yml index bf93269..5cae7a8 100644 --- a/.github/workflows/dokka-gh-pages.yml +++ b/.github/workflows/dokka-gh-pages.yml @@ -46,7 +46,7 @@ jobs: - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: - path: demo/build/dist/sideBySide/productionExecutable/ + path: build/dokka/html/ # Deployment job deploy: From 157159b4d63117bddba2f3d4e763a43943d2f76d Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Tue, 5 Nov 2024 17:14:08 +0800 Subject: [PATCH 19/21] Update README.md about the API documentation --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3e51254..dee015e 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ These include a core library to extend the Kotlin language and its standard libr Currently supported targets by multiplatform libraries: JVM, JS (browser), iOS (`iosX64`, `iosArm64`, and `iosSimulatorArm64`), and Wasm JS. +[Check out the API documentation here.](https://huanshankeji.github.io/kotlin-common/.) + ## Maven coordinates ```kotlin From a1c94c26e68299e4c7bdee1649976d8a959b1653 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Tue, 5 Nov 2024 18:09:03 +0800 Subject: [PATCH 20/21] Comment out a project whose Dokka remote URL is incorrect from Dokka generation --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 67bc02e..89f2b89 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,7 +21,7 @@ dependencies { "reflect", "serialization", "vertx", - "vertx:with-context-receivers", + //"vertx:with-context-receivers", ).forEach { dokka(cpnProject(project, ":$it")) } From 3446818300525a89f0f78c942256163ef369c9fa Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Wed, 6 Nov 2024 09:50:22 +0800 Subject: [PATCH 21/21] Update a comment --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 3c1558f..1b9f161 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -28,7 +28,7 @@ fun ProjectDescriptor.setProjectConcatenatedNames(prefix: String) { } rootProject.setProjectConcatenatedNames("") -// This is needed for Kotlin Native. +// This is needed for Kotlin Native and Dokka. dependencyResolutionManagement { @Suppress("UnstableApiUsage") repositories {