Skip to content

Commit ee5ab90

Browse files
authored
Update leftover sources from jvm-only to kmp (#300)
* Move krpc-ktor-server to commonMain * Move krpc-test to commonMain * Move krpc-test tests to commonTest * detekt * PR comments
1 parent 7bfdb56 commit ee5ab90

File tree

45 files changed

+978
-879
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+978
-879
lines changed

core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ public class RpcParameter(public val name: String, public val type: RpcType)
8888
@ExperimentalRpcApi
8989
public class RpcType(public val kType: KType) {
9090
override fun toString(): String {
91-
return return kType.toString()
91+
return kType.toString()
9292
}
9393
}

gradle-conventions/common/src/main/kotlin/util/JsTarget.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package util
@@ -40,7 +40,7 @@ fun KotlinJsTargetDsl.configureJsAndWasmJsTasks() {
4040
nodejs {
4141
testTask {
4242
useMocha {
43-
timeout = "10000"
43+
timeout = "100s"
4444
}
4545
}
4646
}

gradle-conventions/common/src/main/kotlin/util/ProjectKotlinConfig.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package util
@@ -38,6 +38,7 @@ class ProjectKotlinConfig(
3838
jvm: Boolean = true,
3939
js: Boolean = true,
4040
wasmJs: Boolean = true,
41+
wasmJsD8: Boolean = true,
4142
wasmWasi: Boolean = true,
4243
val native: Boolean = true,
4344
) : Project by project {
@@ -48,18 +49,18 @@ class ProjectKotlinConfig(
4849

4950
private fun isIncluded(
5051
targetName: String,
51-
kotlinVersion: KotlinVersion,
52-
lookupTable: Map<String, String>,
52+
lookupTable: Map<String, String> = targetsLookup,
5353
): Boolean {
5454
return lookupTable[targetName]?.let { sinceKotlin ->
5555
sinceKotlin == FULLY_SUPPORTED_TARGET || sinceKotlin.kotlinVersionParsed() <= kotlinVersion
5656
} ?: false
5757
}
5858

59-
val jvm: Boolean by lazy { jvm && isIncluded("jvm", kotlinVersion, targetsLookup) }
60-
val js: Boolean by lazy { js && isIncluded("js", kotlinVersion, targetsLookup) }
61-
val wasmJs: Boolean by lazy { wasmJs && isIncluded("wasmJs", kotlinVersion, targetsLookup) }
62-
val wasmWasi: Boolean by lazy { wasmWasi && isIncluded("wasmWasi", kotlinVersion, targetsLookup) }
59+
val jvm: Boolean by lazy { jvm && isIncluded("jvm") }
60+
val js: Boolean by lazy { js && isIncluded("js") }
61+
val wasmJs: Boolean by lazy { wasmJs && isIncluded("wasmJs") }
62+
val wasmJsD8: Boolean by lazy { wasmJsD8 && wasmJs }
63+
val wasmWasi: Boolean by lazy { wasmWasi && isIncluded("wasmWasi") }
6364

6465
private val nativeLookup by lazy {
6566
targetsLookup.filterKeys { key ->
@@ -71,7 +72,6 @@ class ProjectKotlinConfig(
7172
.filter { targetFunction ->
7273
targetFunction.parameters.size == 1 && isIncluded(
7374
targetName = targetFunction.name,
74-
kotlinVersion = kotlinVersion,
7575
lookupTable = nativeLookup,
7676
)
7777
}.map { function ->
@@ -84,6 +84,7 @@ fun Project.withKotlinConfig(configure: ProjectKotlinConfig.() -> Unit) {
8484
val excludeJvm: Boolean by optionalProperty()
8585
val excludeJs: Boolean by optionalProperty()
8686
val excludeWasmJs: Boolean by optionalProperty()
87+
val excludeWasmJsD8: Boolean by optionalProperty()
8788
val excludeWasmWasi: Boolean by optionalProperty()
8889
val excludeNative: Boolean by optionalProperty()
8990

@@ -93,6 +94,7 @@ fun Project.withKotlinConfig(configure: ProjectKotlinConfig.() -> Unit) {
9394
jvm = !excludeJvm,
9495
js = !excludeJs,
9596
wasmJs = !excludeWasmJs,
97+
wasmJsD8 = !excludeWasmJsD8,
9698
wasmWasi = !excludeWasmWasi,
9799
native = !excludeNative,
98100
).configure()

gradle-conventions/src/main/kotlin/util/wasm.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package util
@@ -23,7 +23,9 @@ fun ProjectKotlinConfig.configureWasm() {
2323

2424
browser()
2525
nodejs()
26-
d8()
26+
if (wasmJsD8) {
27+
d8()
28+
}
2729

2830
binaries.library()
2931
}.configurePublication()

krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/KrpcClient.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package kotlinx.rpc.krpc.client
77
import kotlinx.atomicfu.atomic
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.channels.Channel
10-
import kotlinx.coroutines.channels.ClosedReceiveChannelException
1110
import kotlinx.coroutines.flow.Flow
1211
import kotlinx.coroutines.flow.flow
1312
import kotlinx.rpc.RpcCall
@@ -258,9 +257,7 @@ public abstract class KrpcClient(
258257

259258
val id = callCounter.incrementAndGet()
260259

261-
val dataTypeString = callable.dataType.toString()
262-
263-
val callId = "$connectionId:$dataTypeString:$id"
260+
val callId = "$connectionId:${callable.name}:$id"
264261

265262
logger.trace { "start a call[$callId] ${callable.name}" }
266263

@@ -325,9 +322,7 @@ public abstract class KrpcClient(
325322
val callable = call.descriptor.getCallable(call.callableName)
326323
?: error("Unexpected callable '${call.callableName}' for ${call.descriptor.fqName} service")
327324

328-
val dataTypeString = callable.dataType.toString()
329-
330-
val callId = "$connectionId:$dataTypeString:$id"
325+
val callId = "$connectionId:${callable.name}:$id"
331326

332327
val channel = Channel<T>()
333328

krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcConnector.kt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.krpc.internal
@@ -154,9 +154,25 @@ public class KrpcConnector<SubscriptionKey>(
154154
if (waitForSubscribers) {
155155
waiting.getOrPut(message.getKey()) { mutableListOf() }.add(message)
156156

157-
logger.warn {
157+
val reason = when (result) {
158+
is HandlerResult.Failure -> {
159+
"Unhandled exception while processing ${result.cause?.message}"
160+
}
161+
162+
is HandlerResult.NoSubscription -> {
163+
"No service with key '${message.getKey()}' and '${message.serviceType}' type was registered." +
164+
"Available: keys: [${subscriptions.keys.joinToString()}]"
165+
}
166+
167+
else -> {
168+
"Unknown"
169+
}
170+
}
171+
172+
logger.warn((result as? HandlerResult.Failure)?.cause) {
158173
"No registered service of ${message.serviceType} service type " +
159-
"was able to process message at the moment. Waiting for new services."
174+
"was able to process message at the moment. Waiting for new services." +
175+
"Reason: $reason"
160176
}
161177

162178
return

krpc/krpc-ktor/krpc-ktor-core/src/jvmTest/kotlin/kotlinx/rpc/krpc/ktor/KtorTransportTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
@file:Suppress("ExtractKtorModule")
@@ -31,6 +31,7 @@ class NewServiceImpl(
3131
override val coroutineContext: CoroutineContext,
3232
private val call: ApplicationCall,
3333
) : NewService {
34+
@Suppress("UastIncorrectHttpHeaderInspection")
3435
override suspend fun echo(value: String): String {
3536
assertEquals("test-header", call.request.headers["TestHeader"])
3637
return value

krpc/krpc-ktor/krpc-ktor-server/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
plugins {
@@ -9,7 +9,7 @@ plugins {
99

1010
kotlin {
1111
sourceSets {
12-
jvmMain {
12+
commonMain {
1313
dependencies {
1414
api(projects.krpc.krpcServer)
1515
api(projects.krpc.krpcKtor.krpcKtorCore)

krpc/krpc-ktor/krpc-ktor-server/gradle.properties

Lines changed: 0 additions & 6 deletions
This file was deleted.

krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/Krpc.kt renamed to krpc/krpc-ktor/krpc-ktor-server/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/server/Krpc.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.krpc.ktor.server

krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KrpcRoute.kt renamed to krpc/krpc-ktor/krpc-ktor-server/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/server/KrpcRoute.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.krpc.ktor.server

krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KtorKrpcServer.kt renamed to krpc/krpc-ktor/krpc-ktor-server/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/server/KtorKrpcServer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.krpc.ktor.server

krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KtorServerDsl.kt renamed to krpc/krpc-ktor/krpc-ktor-server/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/server/KtorServerDsl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.krpc.ktor.server

krpc/krpc-test/build.gradle.kts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
import com.osacky.doctor.internal.sysProperty
56
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
7+
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
68
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
79
import util.applyAtomicfuPlugin
810
import java.nio.file.Files
@@ -22,11 +24,7 @@ kotlin {
2224
// Workaround for
2325
// KLIB resolver: Could not find "org.jetbrains.kotlinx:atomicfu"
2426
api(libs.atomicfu)
25-
}
26-
}
2727

28-
jvmMain {
29-
dependencies {
3028
api(projects.krpc.krpcCore)
3129
api(projects.krpc.krpcServer)
3230
api(projects.krpc.krpcClient)
@@ -35,24 +33,34 @@ kotlin {
3533

3634
implementation(libs.serialization.core)
3735
implementation(libs.kotlin.test)
36+
implementation(libs.coroutines.test)
37+
}
38+
}
39+
40+
jvmMain {
41+
dependencies {
3842
implementation(libs.kotlin.test.junit)
3943
}
4044
}
4145

42-
jvmTest {
46+
commonTest {
4347
dependencies {
4448
implementation(projects.krpc.krpcTest)
4549
implementation(projects.krpc.krpcSerialization.krpcSerializationJson)
4650
implementation(projects.krpc.krpcSerialization.krpcSerializationCbor)
4751
implementation(projects.krpc.krpcSerialization.krpcSerializationProtobuf)
4852
implementation(projects.krpc.krpcLogging)
4953

54+
implementation(libs.coroutines.test)
55+
implementation(libs.kotlin.reflect)
56+
}
57+
}
58+
59+
jvmTest {
60+
dependencies {
5061
implementation(libs.slf4j.api)
5162
implementation(libs.logback.classic)
52-
53-
implementation(libs.coroutines.test)
5463
implementation(libs.coroutines.debug)
55-
implementation(libs.kotlin.reflect)
5664
}
5765
}
5866
}
@@ -72,7 +80,15 @@ tasks.named<Delete>("clean") {
7280
delete(resourcesPath.walk().filter { it.isFile && it.extension == tmpExt }.toList())
7381
}
7482

75-
tasks.create("moveToGold") {
83+
tasks.withType<KotlinJsTest> {
84+
onlyIf {
85+
// for some reason browser tests don't wait for the test to complete and end immediately
86+
// KRPC-166
87+
!targetName.orEmpty().endsWith("browser")
88+
}
89+
}
90+
91+
tasks.register("moveToGold") {
7692
doLast {
7793
resourcesPath.walk().forEach {
7894
if (it.isFile && it.extension == tmpExt) {

krpc/krpc-test/gradle.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
#
4+
5+
# tests fail with some obscure reason
6+
kotlinx.rpc.excludeWasmJsD8=true

krpc/krpc-test/src/commonMain/kotlin/Stub.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestClient.kt renamed to krpc/krpc-test/src/commonMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.krpc.test

krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestServer.kt renamed to krpc/krpc-test/src/commonMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestServer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.krpc.test

krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestService.kt renamed to krpc/krpc-test/src/commonMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestService.kt

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,37 @@ import kotlinx.rpc.RemoteService
1111
import kotlinx.rpc.annotations.Rpc
1212
import kotlinx.serialization.Contextual
1313
import kotlinx.serialization.Serializable
14-
import java.time.LocalDate
15-
import java.time.LocalDateTime
14+
15+
data class LocalDate(
16+
val year: Int,
17+
val month: Int,
18+
val day: Int,
19+
) {
20+
override fun toString(): String {
21+
return "$year-$month-$day"
22+
}
23+
24+
companion object {
25+
fun parse(str: String): LocalDate = str.split('-').let {
26+
LocalDate(it[0].toInt(), it[1].toInt(), it[2].toInt())
27+
}
28+
}
29+
}
30+
31+
data class LocalDateTime(
32+
val date: LocalDate,
33+
val time: String,
34+
) {
35+
override fun toString(): String {
36+
return "$date $time"
37+
}
38+
39+
companion object {
40+
fun parse(str: String): LocalDateTime = str.split(' ').let {
41+
LocalDateTime(LocalDate.parse(it[0]), it[1])
42+
}
43+
}
44+
}
1645

1746
@Suppress("detekt.TooManyFunctions")
1847
@Rpc

0 commit comments

Comments
 (0)