From 8d45e931b87caaf6702cd462843bf44583cd745d Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Thu, 23 May 2024 00:16:46 +0300 Subject: [PATCH] Actualize sample with latest versions (#275) --- samples/chat/README.md | 12 +-- samples/chat/api/build.gradle.kts | 21 ++---- .../kotlin/App.kt => build.gradle.kts} | 26 +++---- samples/chat/client/build.gradle.kts | 69 +++++++----------- .../src/{nodejsMain => jsMain}/kotlin/App.kt | 16 ++-- .../kotlin/clientTransport.kt | 2 +- .../resources/index.html | 2 +- .../src/nodejsMain/kotlin/clientTransport.kt | 32 -------- samples/chat/gradle.properties | 22 +++--- .../chat/gradle/wrapper/gradle-wrapper.jar | Bin 59536 -> 43453 bytes .../gradle/wrapper/gradle-wrapper.properties | 4 +- samples/chat/gradlew | 41 +++++++---- samples/chat/gradlew.bat | 35 +++++---- samples/chat/server/build.gradle.kts | 64 ++++++++-------- .../src/nativeMain/kotlin/expects.native.kt | 5 +- 15 files changed, 154 insertions(+), 197 deletions(-) rename samples/chat/{client/src/browserMain/kotlin/App.kt => build.gradle.kts} (51%) rename samples/chat/client/src/{nodejsMain => jsMain}/kotlin/App.kt (66%) rename samples/chat/client/src/{browserMain => jsMain}/kotlin/clientTransport.kt (94%) rename samples/chat/client/src/{browserMain => jsMain}/resources/index.html (92%) delete mode 100644 samples/chat/client/src/nodejsMain/kotlin/clientTransport.kt diff --git a/samples/chat/README.md b/samples/chat/README.md index 6d9b3fc39..f5ed8741a 100644 --- a/samples/chat/README.md +++ b/samples/chat/README.md @@ -2,16 +2,18 @@ * api - shared chat API for both client and server * client - client API implementation via requesting to RSocket with Protobuf serialization. - Works on JVM(TCP/WS), Native(TCP/WS), NodeJS(WS/TCP), Browser(WS). + Works on JVM(TCP/WS), Native(TCP/WS), Js(WS). Tasks for running clients: * JVM: `run` - * Native: `runDebugExecutableNative` / `runReleaseExecutableNative` - * NodeJs: `nodejsNodeRun` / `nodejsNodeDevelopmentRun` / `nodejsNodeProductionRun` - * Browser: `browserBrowserRun` / `browserBrowserDevelopmentRun` / `browserBrowserProductionRun` + * Native: `runDebugExecutable[TARGET]` / `runReleaseExecutable[TARGET]` + (where `[TARGET]` is one of `LinuxX64`, `MacosArm64` or `MacosX64`) + * NodeJs: `jsNodeRun` / `jsNodeDevelopmentRun` / `jsNodeProductionRun` + * Browser: `jsBrowserRun` / `jsBrowserDevelopmentRun` / `jsBrowserProductionRun` * server - server API implementation with storage in concurrent map and exposing it through RSocket with Protobuf serialization. Can be started on JVM(TCP/WS), Native(TCP/WS), NodeJS(TCP). Tasks for running servers: * JVM: `run` - * Native: `runDebugExecutableNative` / `runReleaseExecutableNative` + * Native: `runDebugExecutable[TARGET]` / `runReleaseExecutable[TARGET]` + (where `[TARGET]` is one of `LinuxX64`, `MacosArm64` or `MacosX64`) * NodeJs: `jsNodeRun` / `jsNodeDevelopmentRun` / `jsNodeProductionRun` diff --git a/samples/chat/api/build.gradle.kts b/samples/chat/api/build.gradle.kts index e0df9283c..3b53e14ac 100644 --- a/samples/chat/api/build.gradle.kts +++ b/samples/chat/api/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,6 @@ * limitations under the License. */ -import org.jetbrains.kotlin.konan.target.* - plugins { kotlin("multiplatform") kotlin("plugin.serialization") @@ -30,19 +28,14 @@ kotlin { browser() nodejs() } - when { - HostManager.hostIsLinux -> linuxX64("native") - HostManager.hostIsMingw -> null //no native support for TCP in ktor mingwX64("native") - HostManager.hostIsMac -> macosX64("native") - else -> null - } + linuxX64() + macosX64() + macosArm64() sourceSets { - commonMain { - dependencies { - api("io.rsocket.kotlin:rsocket-core:$rsocketVersion") - api("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$kotlinxSerializationVersion") - } + commonMain.dependencies { + api("io.rsocket.kotlin:rsocket-core:$rsocketVersion") + api("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$kotlinxSerializationVersion") } } } diff --git a/samples/chat/client/src/browserMain/kotlin/App.kt b/samples/chat/build.gradle.kts similarity index 51% rename from samples/chat/client/src/browserMain/kotlin/App.kt rename to samples/chat/build.gradle.kts index cd54f5fed..74b4d1daa 100644 --- a/samples/chat/client/src/browserMain/kotlin/App.kt +++ b/samples/chat/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,18 @@ * limitations under the License. */ -package io.rsocket.kotlin.samples.chat.client +import org.jetbrains.kotlin.gradle.targets.js.nodejs.* +import org.jetbrains.kotlin.gradle.targets.js.npm.* -import io.rsocket.kotlin.samples.chat.api.* -import kotlinx.coroutines.* +plugins { + kotlin("multiplatform") apply false +} -suspend fun main() { - coroutineScope { - //only WS is supported on browser JS - // native WS server is incompatible with js WS client - (Servers.WS - Servers.Native.WS).forEach { - val client = ApiClient(it, "Yuri") - launch { - client.use(it, "RSocket is awesome! (from browser)") - } - } +plugins.withType { + // ignore package lock + extensions.configure { + lockFileDirectory.set(layout.buildDirectory.dir("kotlin-js-store")) + packageLockMismatchReport.set(LockFileMismatchReport.NONE) + packageLockAutoReplace.set(true) } } diff --git a/samples/chat/client/build.gradle.kts b/samples/chat/client/build.gradle.kts index 0aef81492..db573a8dd 100644 --- a/samples/chat/client/build.gradle.kts +++ b/samples/chat/client/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -import org.jetbrains.kotlin.konan.target.* +import org.jetbrains.kotlin.gradle.plugin.mpp.* plugins { kotlin("multiplatform") @@ -33,56 +33,37 @@ kotlin { jvm { withJava() } - js("browser") { - browser { - binaries.executable() - } - } - js("nodejs") { - nodejs { - binaries.executable() - } + js { + browser() + nodejs() + binaries.executable() } - when { - HostManager.hostIsLinux -> linuxX64("native") - HostManager.hostIsMingw -> null //no native support for TCP in ktor mingwX64("clientNative") - HostManager.hostIsMac -> macosX64("native") - else -> null - }?.binaries { - executable { - entryPoint = "io.rsocket.kotlin.samples.chat.client.main" + linuxX64() + macosX64() + macosArm64() + targets.withType().configureEach { + binaries { + executable { + entryPoint = "io.rsocket.kotlin.samples.chat.client.main" + } } } sourceSets { - commonMain { - dependencies { - implementation(project(":api")) - implementation("io.rsocket.kotlin:rsocket-transport-ktor-websocket-client:$rsocketVersion") - } + commonMain.dependencies { + implementation(project(":api")) + implementation("io.rsocket.kotlin:rsocket-transport-ktor-websocket-client:$rsocketVersion") } - val jvmMain by getting { - dependencies { - implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:$rsocketVersion") - implementation("io.ktor:ktor-client-cio:$ktorVersion") - } + jvmMain.dependencies { + implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:$rsocketVersion") + implementation("io.ktor:ktor-client-cio:$ktorVersion") } - findByName("nativeMain")?.apply { - dependencies { - implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:$rsocketVersion") - implementation("io.ktor:ktor-client-cio:$ktorVersion") - } + nativeMain.dependencies { + implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:$rsocketVersion") + implementation("io.ktor:ktor-client-cio:$ktorVersion") } - val browserMain by getting { - dependencies { - implementation("io.ktor:ktor-client-js:$ktorVersion") - } - } - val nodejsMain by getting { - dependencies { - implementation("io.ktor:ktor-client-js:$ktorVersion") - implementation("io.rsocket.kotlin:rsocket-transport-nodejs-tcp:$rsocketVersion") - } + jsMain.dependencies { + implementation("io.ktor:ktor-client-js:$ktorVersion") } } } diff --git a/samples/chat/client/src/nodejsMain/kotlin/App.kt b/samples/chat/client/src/jsMain/kotlin/App.kt similarity index 66% rename from samples/chat/client/src/nodejsMain/kotlin/App.kt rename to samples/chat/client/src/jsMain/kotlin/App.kt index ebe4aa589..8592ff9d9 100644 --- a/samples/chat/client/src/nodejsMain/kotlin/App.kt +++ b/samples/chat/client/src/jsMain/kotlin/App.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,14 +19,12 @@ package io.rsocket.kotlin.samples.chat.client import io.rsocket.kotlin.samples.chat.api.* import kotlinx.coroutines.* -suspend fun main() { - coroutineScope { - // native WS server is incompatible with js WS client - (Servers.ALL - Servers.Native.WS).forEach { - val client = ApiClient(it, "Kolya") - launch { - client.use(it, "RSocket is awesome! (from nodeJS)") - } +suspend fun main(): Unit = coroutineScope { + // only WS is supported on browser JS + Servers.WS.forEach { + val client = ApiClient(it, "Kolya") + launch { + client.use(it, "RSocket is awesome! (from js)") } } } diff --git a/samples/chat/client/src/browserMain/kotlin/clientTransport.kt b/samples/chat/client/src/jsMain/kotlin/clientTransport.kt similarity index 94% rename from samples/chat/client/src/browserMain/kotlin/clientTransport.kt rename to samples/chat/client/src/jsMain/kotlin/clientTransport.kt index e18a78b7c..8fe310394 100644 --- a/samples/chat/client/src/browserMain/kotlin/clientTransport.kt +++ b/samples/chat/client/src/jsMain/kotlin/clientTransport.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/samples/chat/client/src/browserMain/resources/index.html b/samples/chat/client/src/jsMain/resources/index.html similarity index 92% rename from samples/chat/client/src/browserMain/resources/index.html rename to samples/chat/client/src/jsMain/resources/index.html index f98970589..c07fddc8e 100644 --- a/samples/chat/client/src/browserMain/resources/index.html +++ b/samples/chat/client/src/jsMain/resources/index.html @@ -1,5 +1,5 @@