Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit 57d27a6

Browse files
committed
Update Ktor and kotlinx-serialization versions; enhance Ktor version detection logic; make tests rerunnable
1 parent 93f49d6 commit 57d27a6

File tree

8 files changed

+62
-25
lines changed

8 files changed

+62
-25
lines changed

‎build.gradle.kts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ allprojects{
1616
repositories{
1717
mavenCentral()
1818
}
19+
20+
tasks.withType<Test>{
21+
useJUnitPlatform()
22+
outputs.upToDateWhen{false }
23+
}
1924
}
2025

2126
kotlinPublications{

‎gradle/libs.versions.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[versions]
22
kotlin = "2.2.20"
3-
ktor = "2.3.13"
4-
kotlinx-serialization = "1.6.2"
3+
ktor = "3.3.1"
4+
kotlinx-serialization = "1.9.0"
55
jvm-toolchain = "11"
66
kotlin-jupyter = "0.15.1-659"
77
kotlinpoet = "2.1.0"

‎json2kt/build.gradle.kts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ dependencies{
1111
testImplementation(libs.kotlinx.serialization.json)
1212
}
1313

14-
tasks.test{
15-
useJUnitPlatform()
16-
}
1714
kotlin{
1815
jvmToolchain(libs.versions.jvm.toolchain.get().toInt())
1916
explicitApi()

‎ktor-client-core/build.gradle.kts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ dependencies{
2222
api(libs.ktor.serialization.kotlinx.json)
2323
}
2424

25-
tasks.test{
26-
useJUnitPlatform()
27-
}
2825
kotlin{
2926
jvmToolchain(libs.versions.jvm.toolchain.get().toInt())
3027
explicitApi()

‎ktor-client-core/src/main/kotlin/KtorClientCoreIntegration.kt‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import io.ktor.serialization.kotlinx.json.json
55
importkotlinx.serialization.json.Json
66
importorg.jetbrains.kotlinx.jupyter.api.declare
77
importorg.jetbrains.kotlinx.jupyter.api.libraries.JupyterIntegration
8+
importjava.util.jar.Attributes
9+
importjava.util.jar.Manifest
810

911
/**
1012
* Usage:
@@ -29,7 +31,7 @@ import org.jetbrains.kotlinx.jupyter.api.libraries.JupyterIntegration
2931
*/
3032
publicclassKtorClientCoreIntegration : JupyterIntegration(){
3133
overridefun Builder.onLoaded(){
32-
val ktorVersion ="2.3.7"
34+
val ktorVersion =findKtorVersion(Thread.currentThread().contextClassLoader)
3335

3436
fun MutableList<String>.ktorClient(artifactName:String){
3537
add("io.ktor:ktor-client-$artifactName-jvm:$ktorVersion")
@@ -71,3 +73,30 @@ public class KtorClientCoreIntegration : JupyterIntegration(){
7173
}
7274
}
7375
}
76+
77+
privatefunfindKtorVersion(classLoader:ClassLoader) =
78+
requireNotNull(findModuleVersion("io.ktor.client.core", classLoader)){
79+
"Failed to find Ktor version for Ktor integration"
80+
}
81+
82+
/**
83+
* Attempts to find the implementation version of a given module by inspecting the manifest files
84+
* available in the provided class loader's resources.
85+
*/
86+
privatefunfindModuleVersion(
87+
moduleName:String,
88+
classLoader:ClassLoader,
89+
): String?{
90+
val autoModuleKey =Attributes.Name("Automatic-Module-Name")
91+
val implVersionKey =Attributes.Name.IMPLEMENTATION_VERSION
92+
93+
return classLoader.getResources("META-INF/MANIFEST.MF")
94+
.asSequence()
95+
.mapNotNull{url ->
96+
runCatching{
97+
url.openStream().use{Manifest(it) }
98+
}.getOrNull()?.mainAttributes
99+
}
100+
.firstOrNull{it.getValue(autoModuleKey) == moduleName }
101+
?.getValue(implVersionKey)
102+
}

‎ktor-client-core/src/main/kotlin/NotebookHttpResponse.kt‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
packageorg.jetbrains.kotlinx.jupyter.ktor.client.core
22

3-
importio.ktor.client.call.*
4-
importio.ktor.client.statement.*
5-
importio.ktor.http.*
6-
importio.ktor.util.*
7-
importio.ktor.util.date.*
8-
importio.ktor.util.reflect.*
9-
importio.ktor.utils.io.*
3+
importio.ktor.client.call.DoubleReceiveException
4+
importio.ktor.client.call.HttpClientCall
5+
importio.ktor.client.call.NoTransformationFoundException
6+
importio.ktor.client.call.body
7+
importio.ktor.client.statement.HttpResponse
8+
importio.ktor.client.statement.bodyAsText
9+
importio.ktor.client.statement.content
10+
importio.ktor.client.statement.readBytes
11+
importio.ktor.client.statement.readRawBytes
12+
importio.ktor.http.Headers
13+
importio.ktor.http.HttpProtocolVersion
14+
importio.ktor.http.HttpStatusCode
15+
importio.ktor.util.date.GMTDate
16+
importio.ktor.util.reflect.TypeInfo
17+
importio.ktor.utils.io.ByteReadChannel
18+
importio.ktor.utils.io.InternalAPI
1019
importkotlinx.coroutines.runBlocking
1120
importjava.nio.charset.Charset
1221
importkotlin.coroutines.CoroutineContext
@@ -18,7 +27,7 @@ import kotlin.coroutines.CoroutineContext
1827
publicclassNotebookHttpResponse(publicvalktorResponse:HttpResponse) : HttpResponse(){
1928
overrideval call:HttpClientCall get() = ktorResponse.call
2029
@InternalAPI
21-
overridevalcontent:ByteReadChannel get() = ktorResponse.content
30+
overridevalrawContent:ByteReadChannel get() = ktorResponse.rawContent
2231
overrideval coroutineContext:CoroutineContext get() = ktorResponse.coroutineContext
2332
overrideval headers:Headers get() = ktorResponse.headers
2433
overrideval requestTime:GMTDate get() = ktorResponse.requestTime
@@ -58,7 +67,14 @@ public class NotebookHttpResponse(public val ktorResponse: HttpResponse) : HttpR
5867
* Reads the whole [HttpResponse.content] if `Content-Length` is specified.
5968
* Otherwise, it just reads one byte.
6069
*/
61-
publicfunreadBytes(): ByteArray= runBlocking{ktorResponse.readBytes() }
70+
@Deprecated("Use readRawBytes() instead", ReplaceWith("readRawBytes()"))
71+
publicfunreadBytes(): ByteArray= readRawBytes()
72+
73+
/**
74+
* Reads the whole [HttpResponse.content] if `Content-Length` is specified.
75+
* Otherwise, it just reads one byte.
76+
*/
77+
publicfunreadRawBytes(): ByteArray= runBlocking{ktorResponse.readRawBytes() }
6278

6379
/**
6480
* Reads exactly [count] bytes of the [HttpResponse.content].

‎ktor-client/build.gradle.kts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ dependencies{
2727
}
2828
}
2929

30-
tasks.test{
31-
useJUnitPlatform()
32-
}
3330
kotlin{
3431
jvmToolchain(libs.versions.jvm.toolchain.get().toInt())
3532
explicitApi()

‎serialization/build.gradle.kts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ tasks.processJupyterApiResources{
2323
)
2424
}
2525

26-
tasks.test{
27-
useJUnitPlatform()
28-
}
29-
3026
kotlin{
3127
jvmToolchain(libs.versions.jvm.toolchain.get().toInt())
3228
explicitApi()

0 commit comments

Comments
(0)