From a63f3e5d6e26d1ab4042dbdb841e30b648aaf76a Mon Sep 17 00:00:00 2001 From: Niels van Velzen Date: Tue, 9 May 2023 10:34:38 +0200 Subject: [PATCH] Split KtorClient to separate module --- gradle/libs.versions.toml | 5 +- jellyfin-api-ktor/build.gradle.kts | 53 +++++++++++++++++++ .../org/jellyfin/sdk/api/ktor}/KtorClient.kt | 6 ++- .../org/jellyfin/sdk/api/ktor}/KtorClient.kt | 6 ++- jellyfin-api/build.gradle.kts | 4 +- .../sdk/api/sockets/SocketInstance.kt | 2 +- jellyfin-core/build.gradle.kts | 1 + .../org/jellyfin/sdk/JellyfinOptions.kt | 2 +- .../org/jellyfin/sdk/JellyfinOptions.kt | 2 +- settings.gradle.kts | 1 + 10 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 jellyfin-api-ktor/build.gradle.kts rename {jellyfin-api/src/commonMain/kotlin/org/jellyfin/sdk/api/client => jellyfin-api-ktor/src/commonMain/kotlin/org/jellyfin/sdk/api/ktor}/KtorClient.kt (77%) rename {jellyfin-api/src/jvmMain/kotlin/org/jellyfin/sdk/api/client => jellyfin-api-ktor/src/jvmMain/kotlin/org/jellyfin/sdk/api/ktor}/KtorClient.kt (96%) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c3b7af38..f68bd198 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,6 +16,7 @@ kotlinx-coroutines = "1.7.0" kotlinx-serialization = "1.5.0" ktor = "1.6.8" nexuspublish = "1.3.0" +okhttp = "4.10.0" slf4j = "2.0.7" swagger-parser = "2.1.13" @@ -33,17 +34,19 @@ android-gradle = { module = "com.android.tools.build:gradle", version.ref = "and clikt = { module = "com.github.ajalt.clikt:clikt", version.ref = "clikt" } kasechange = { module = "net.pearx.kasechange:kasechange", version.ref = "kasechange" } koin = { module = "io.insert-koin:koin-core", version.ref = "koin" } -kotest-framework-engine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" } kotest-assertions = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" } +kotest-framework-engine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" } kotest-runner-junit5 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" } kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } kotlin-logging = { module = "io.github.microutils:kotlin-logging", version.ref = "kotlin-logging" } kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoet" } kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" } +kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinx-serialization" } kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" } ktor-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" } ktor-http = { module = "io.ktor:ktor-http", version.ref = "ktor" } ktor-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" } +okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" } slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" } swagger-parser = { module = "io.swagger.parser.v3:swagger-parser", version.ref = "swagger-parser" } diff --git a/jellyfin-api-ktor/build.gradle.kts b/jellyfin-api-ktor/build.gradle.kts new file mode 100644 index 00000000..920347de --- /dev/null +++ b/jellyfin-api-ktor/build.gradle.kts @@ -0,0 +1,53 @@ +plugins { + kotlin("multiplatform") +} + +kotlin { + explicitApi() + + jvm() + + sourceSets { + all { + languageSettings { + progressiveMode = true + } + } + + val commonMain by getting { + dependencies { + implementation(projects.jellyfinApi) + implementation(projects.jellyfinModel) + + implementation(libs.kotlinx.serialization.core) + implementation(libs.ktor.core) + + implementation(libs.kotlin.logging) + } + } + + val jvmMain by getting { + dependencies { + implementation(libs.ktor.okhttp) + } + } + + val commonTest by getting { + dependencies { + implementation(projects.testutils) + } + } + } +} + +enablePublishing { + val javadocJar by tasks.creating(Jar::class) { + dependsOn(tasks.getByName("dokkaHtml")) + archiveClassifier.set("javadoc") + from("$buildDir/dokka/html") + } + + publications.withType { + artifact(javadocJar) + } +} diff --git a/jellyfin-api/src/commonMain/kotlin/org/jellyfin/sdk/api/client/KtorClient.kt b/jellyfin-api-ktor/src/commonMain/kotlin/org/jellyfin/sdk/api/ktor/KtorClient.kt similarity index 77% rename from jellyfin-api/src/commonMain/kotlin/org/jellyfin/sdk/api/client/KtorClient.kt rename to jellyfin-api-ktor/src/commonMain/kotlin/org/jellyfin/sdk/api/ktor/KtorClient.kt index 9a4a98f7..07759673 100644 --- a/jellyfin-api/src/commonMain/kotlin/org/jellyfin/sdk/api/client/KtorClient.kt +++ b/jellyfin-api-ktor/src/commonMain/kotlin/org/jellyfin/sdk/api/ktor/KtorClient.kt @@ -1,5 +1,9 @@ -package org.jellyfin.sdk.api.client +package org.jellyfin.sdk.api.ktor +import org.jellyfin.sdk.api.client.ApiClient +import org.jellyfin.sdk.api.client.HttpClientOptions +import org.jellyfin.sdk.api.client.HttpMethod +import org.jellyfin.sdk.api.client.RawResponse import org.jellyfin.sdk.api.sockets.SocketConnectionFactory import org.jellyfin.sdk.api.sockets.SocketInstance import org.jellyfin.sdk.model.ClientInfo diff --git a/jellyfin-api/src/jvmMain/kotlin/org/jellyfin/sdk/api/client/KtorClient.kt b/jellyfin-api-ktor/src/jvmMain/kotlin/org/jellyfin/sdk/api/ktor/KtorClient.kt similarity index 96% rename from jellyfin-api/src/jvmMain/kotlin/org/jellyfin/sdk/api/client/KtorClient.kt rename to jellyfin-api-ktor/src/jvmMain/kotlin/org/jellyfin/sdk/api/ktor/KtorClient.kt index ce80ade7..1d7273eb 100644 --- a/jellyfin-api/src/jvmMain/kotlin/org/jellyfin/sdk/api/client/KtorClient.kt +++ b/jellyfin-api-ktor/src/jvmMain/kotlin/org/jellyfin/sdk/api/ktor/KtorClient.kt @@ -1,4 +1,4 @@ -package org.jellyfin.sdk.api.client +package org.jellyfin.sdk.api.ktor import io.ktor.client.HttpClient import io.ktor.client.call.NoTransformationFoundException @@ -17,6 +17,10 @@ import io.ktor.network.sockets.SocketTimeoutException import io.ktor.util.toMap import kotlinx.serialization.SerializationException import mu.KotlinLogging +import org.jellyfin.sdk.api.client.ApiClient +import org.jellyfin.sdk.api.client.HttpClientOptions +import org.jellyfin.sdk.api.client.HttpMethod +import org.jellyfin.sdk.api.client.RawResponse import org.jellyfin.sdk.api.client.exception.ApiClientException import org.jellyfin.sdk.api.client.exception.InvalidContentException import org.jellyfin.sdk.api.client.exception.InvalidStatusException diff --git a/jellyfin-api/build.gradle.kts b/jellyfin-api/build.gradle.kts index a92ed30f..4ca725f9 100644 --- a/jellyfin-api/build.gradle.kts +++ b/jellyfin-api/build.gradle.kts @@ -22,7 +22,7 @@ kotlin { implementation(libs.kotlinx.coroutines) implementation(libs.kotlinx.serialization.json) - implementation(libs.ktor.core) + implementation(libs.ktor.http) implementation(libs.kotlin.logging) } @@ -30,7 +30,7 @@ kotlin { val jvmMain by getting { dependencies { - implementation(libs.ktor.okhttp) + implementation(libs.okhttp) } } diff --git a/jellyfin-api/src/commonMain/kotlin/org/jellyfin/sdk/api/sockets/SocketInstance.kt b/jellyfin-api/src/commonMain/kotlin/org/jellyfin/sdk/api/sockets/SocketInstance.kt index bfc5f349..8eed0194 100644 --- a/jellyfin-api/src/commonMain/kotlin/org/jellyfin/sdk/api/sockets/SocketInstance.kt +++ b/jellyfin-api/src/commonMain/kotlin/org/jellyfin/sdk/api/sockets/SocketInstance.kt @@ -32,7 +32,7 @@ import kotlin.time.Duration.Companion.seconds private val logger = KotlinLogging.logger {} -public class SocketInstance internal constructor( +public class SocketInstance( private val api: ApiClient, private val socketConnectionFactory: SocketConnectionFactory, context: CoroutineContext = Dispatchers.Default, diff --git a/jellyfin-core/build.gradle.kts b/jellyfin-core/build.gradle.kts index b855034a..4f2eddf0 100644 --- a/jellyfin-core/build.gradle.kts +++ b/jellyfin-core/build.gradle.kts @@ -21,6 +21,7 @@ kotlin { val commonMain by getting { dependencies { api(projects.jellyfinApi) + api(projects.jellyfinApiKtor) api(projects.jellyfinModel) implementation(libs.kotlinx.coroutines) diff --git a/jellyfin-core/src/androidMain/kotlin/org/jellyfin/sdk/JellyfinOptions.kt b/jellyfin-core/src/androidMain/kotlin/org/jellyfin/sdk/JellyfinOptions.kt index b98a891b..28072f00 100644 --- a/jellyfin-core/src/androidMain/kotlin/org/jellyfin/sdk/JellyfinOptions.kt +++ b/jellyfin-core/src/androidMain/kotlin/org/jellyfin/sdk/JellyfinOptions.kt @@ -2,7 +2,7 @@ package org.jellyfin.sdk import android.content.Context import org.jellyfin.sdk.android.androidDevice -import org.jellyfin.sdk.api.client.KtorClient +import org.jellyfin.sdk.api.ktor.KtorClient import org.jellyfin.sdk.api.sockets.OkHttpWebsocketSession import org.jellyfin.sdk.api.sockets.SocketConnectionFactory import org.jellyfin.sdk.model.ClientInfo diff --git a/jellyfin-core/src/jvmMain/kotlin/org/jellyfin/sdk/JellyfinOptions.kt b/jellyfin-core/src/jvmMain/kotlin/org/jellyfin/sdk/JellyfinOptions.kt index 345dfff3..e7ecaab8 100644 --- a/jellyfin-core/src/jvmMain/kotlin/org/jellyfin/sdk/JellyfinOptions.kt +++ b/jellyfin-core/src/jvmMain/kotlin/org/jellyfin/sdk/JellyfinOptions.kt @@ -1,6 +1,6 @@ package org.jellyfin.sdk -import org.jellyfin.sdk.api.client.KtorClient +import org.jellyfin.sdk.api.ktor.KtorClient import org.jellyfin.sdk.api.sockets.OkHttpWebsocketSession import org.jellyfin.sdk.api.sockets.SocketConnectionFactory import org.jellyfin.sdk.model.ClientInfo diff --git a/settings.gradle.kts b/settings.gradle.kts index c02b6973..2309fb8d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -6,6 +6,7 @@ rootProject.name = "jellyfin-sdk-kotlin" include(":jellyfin-core") include(":jellyfin-model") include(":jellyfin-api") +include(":jellyfin-api-ktor") // Code generation include(":openapi-generator")