diff --git a/gradle-plugin/src/main/java/de/jensklingenberg/ktorfit/gradle/KtorfitGradlePlugin.kt b/gradle-plugin/src/main/java/de/jensklingenberg/ktorfit/gradle/KtorfitGradlePlugin.kt index 3c2ac5916..ffb1e46a4 100644 --- a/gradle-plugin/src/main/java/de/jensklingenberg/ktorfit/gradle/KtorfitGradlePlugin.kt +++ b/gradle-plugin/src/main/java/de/jensklingenberg/ktorfit/gradle/KtorfitGradlePlugin.kt @@ -8,8 +8,6 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension - - class KtorfitGradlePlugin : Plugin { companion object { const val GRADLE_TASKNAME = "ktorfit" @@ -24,16 +22,20 @@ class KtorfitGradlePlugin : Plugin { extensions.create(GRADLE_TASKNAME, KtorfitGradleConfiguration::class.java) val flowConverterDependencyNotation = "de.jensklingenberg.ktorfit:ktorfit-converters-flow:1.7.0" + val callConverterDependencyNotation = "de.jensklingenberg.ktorfit:ktorfit-converters-call:1.7.0" + when (kotlinExtension) { is KotlinSingleTargetExtension<*> -> { dependencies { add("implementation", flowConverterDependencyNotation) + add("implementation", callConverterDependencyNotation) } } is KotlinMultiplatformExtension -> { dependencies { add("commonMainImplementation", flowConverterDependencyNotation) + add("commonMainImplementation", callConverterDependencyNotation) } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3fab81e33..c858a8113 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,7 @@ [versions] autoService = "1.1.1" autoServiceKsp = "1.10" +binaryCompatibilityValidator = "0.13.2" coroutines = "1.7.3" detekt = "1.23.1" gradlePlugin = "1.7.0" @@ -21,8 +22,8 @@ autoService = { module = "com.google.auto.service:auto-service", version.ref = " gradle-maven-publish-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "gradleMavenPublishPlugin" } gradle-plugin = { module = "de.jensklingenberg.ktorfit:gradle-plugin", version.ref = "gradlePlugin" } junit = "junit:junit:4.13.2" -kctfork-core = { module = "dev.zacsweers.kctfork:core", version.ref = "kctfork" } -kctfork-ksp = { module = "dev.zacsweers.kctfork:ksp", version.ref = "kctfork" } +kctfork-core = { module = "dev.zacsweers.kctfork:core", version.ref = "kctfork" } +kctfork-ksp = { module = "dev.zacsweers.kctfork:ksp", version.ref = "kctfork" } kotlin-compiler-embeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlin" } kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" } kotlinPoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinPoet" } @@ -59,5 +60,6 @@ rxjava3 = "io.reactivex.rxjava3:rxjava:3.1.6" truth = "com.google.truth:truth:1.1.5" [plugins] +binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binaryCompatibilityValidator" } detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } kspPlugin = { id = "com.google.devtools.ksp", version.ref = "kspVersion" } diff --git a/ktorfit-annotations/build.gradle.kts b/ktorfit-annotations/build.gradle.kts index a94b35de0..e861405d7 100644 --- a/ktorfit-annotations/build.gradle.kts +++ b/ktorfit-annotations/build.gradle.kts @@ -4,7 +4,7 @@ plugins { id("signing") id("com.vanniktech.maven.publish") id("com.android.library") - id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2" + alias(libs.plugins.binaryCompatibilityValidator) id("app.cash.licensee") } diff --git a/ktorfit-converters/call/api/android/call.api b/ktorfit-converters/call/api/android/call.api new file mode 100644 index 000000000..b20b67048 --- /dev/null +++ b/ktorfit-converters/call/api/android/call.api @@ -0,0 +1,21 @@ +public final class de/jensklingenberg/ktorfit/converter/builtin/CallConverterFactory : de/jensklingenberg/ktorfit/converter/Converter$Factory { + public fun ()V + public fun requestParameterConverter (Lkotlin/reflect/KClass;Lkotlin/reflect/KClass;)Lde/jensklingenberg/ktorfit/converter/Converter$RequestParameterConverter; + public fun responseConverter (Lde/jensklingenberg/ktorfit/internal/TypeData;Lde/jensklingenberg/ktorfit/Ktorfit;)Lde/jensklingenberg/ktorfit/converter/Converter$ResponseConverter; + public fun suspendResponseConverter (Lde/jensklingenberg/ktorfit/internal/TypeData;Lde/jensklingenberg/ktorfit/Ktorfit;)Lde/jensklingenberg/ktorfit/converter/Converter$SuspendResponseConverter; +} + +public final class de/jensklingenberg/ktorfit/converter/builtin/CallResponseConverter : de/jensklingenberg/ktorfit/converter/SuspendResponseConverter, de/jensklingenberg/ktorfit/converter/request/ResponseConverter { + public fun ()V + public fun supportedType (Lde/jensklingenberg/ktorfit/internal/TypeData;Z)Z + public fun wrapResponse (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lde/jensklingenberg/ktorfit/Ktorfit;)Ljava/lang/Object; + public fun wrapSuspendResponse (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lde/jensklingenberg/ktorfit/Ktorfit;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + +public final class de/jensklingenberg/ktorfit/converters/call/BuildConfig { + public static final field BUILD_TYPE Ljava/lang/String; + public static final field DEBUG Z + public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String; + public fun ()V +} + diff --git a/ktorfit-converters/call/api/jvm/call.api b/ktorfit-converters/call/api/jvm/call.api new file mode 100644 index 000000000..d7e616272 --- /dev/null +++ b/ktorfit-converters/call/api/jvm/call.api @@ -0,0 +1,14 @@ +public final class de/jensklingenberg/ktorfit/converter/builtin/CallConverterFactory : de/jensklingenberg/ktorfit/converter/Converter$Factory { + public fun ()V + public fun requestParameterConverter (Lkotlin/reflect/KClass;Lkotlin/reflect/KClass;)Lde/jensklingenberg/ktorfit/converter/Converter$RequestParameterConverter; + public fun responseConverter (Lde/jensklingenberg/ktorfit/internal/TypeData;Lde/jensklingenberg/ktorfit/Ktorfit;)Lde/jensklingenberg/ktorfit/converter/Converter$ResponseConverter; + public fun suspendResponseConverter (Lde/jensklingenberg/ktorfit/internal/TypeData;Lde/jensklingenberg/ktorfit/Ktorfit;)Lde/jensklingenberg/ktorfit/converter/Converter$SuspendResponseConverter; +} + +public final class de/jensklingenberg/ktorfit/converter/builtin/CallResponseConverter : de/jensklingenberg/ktorfit/converter/SuspendResponseConverter, de/jensklingenberg/ktorfit/converter/request/ResponseConverter { + public fun ()V + public fun supportedType (Lde/jensklingenberg/ktorfit/internal/TypeData;Z)Z + public fun wrapResponse (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lde/jensklingenberg/ktorfit/Ktorfit;)Ljava/lang/Object; + public fun wrapSuspendResponse (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lde/jensklingenberg/ktorfit/Ktorfit;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + diff --git a/ktorfit-converters/call/build.gradle.kts b/ktorfit-converters/call/build.gradle.kts new file mode 100644 index 000000000..cc4e4938a --- /dev/null +++ b/ktorfit-converters/call/build.gradle.kts @@ -0,0 +1,174 @@ +plugins { + kotlin("multiplatform") + id("maven-publish") + id("signing") + id("com.vanniktech.maven.publish") + id("com.android.library") + alias(libs.plugins.binaryCompatibilityValidator) + id("app.cash.licensee") +} + +licensee { + allow("Apache-2.0") + allow("MIT") +} + + +val enableSigning = true + +mavenPublishing { + + coordinates( + "de.jensklingenberg.ktorfit", + "ktorfit-converters-call", + libs.versions.ktorfit.asProvider().get() + ) + publishToMavenCentral() + // publishToMavenCentral(SonatypeHost.S01) for publishing through s01.oss.sonatype.org + if (enableSigning) { + signAllPublications() + } +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + + +kotlin { + explicitApi() + jvm { + + } + js(IR) { + this.nodejs() + binaries.executable() // not applicable to BOTH, see details below + } + androidTarget { + publishLibraryVariants("release", "debug") + } + iosArm64() + iosX64() + iosSimulatorArm64() + + watchosArm32() + watchosArm64() + watchosX64() + watchosSimulatorArm64() + tvosArm64() + tvosX64() + tvosSimulatorArm64() + macosX64() + macosArm64() + linuxX64 { + binaries { + executable() + } + } + + ios("ios") { + binaries { + framework { + baseName = "library" + } + } + } + mingwX64() + sourceSets { + val commonMain by getting { + dependencies { + implementation(projects.ktorfitLibCommon) + } + } + val linuxX64Main by getting + val mingwX64Main by getting + val androidMain by getting + val jvmMain by getting + val iosX64Main by getting + val iosArm64Main by getting + val iosSimulatorArm64Main by getting + val jsMain by getting + val iosMain by getting { + dependsOn(commonMain) + iosX64Main.dependsOn(this) + iosArm64Main.dependsOn(this) + iosSimulatorArm64Main.dependsOn(this) + dependencies { + + } + } + } +} +val javadocJar by tasks.registering(Jar::class) { + archiveClassifier.set("javadoc") +} + +android { + compileSdk = 33 + sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") + defaultConfig { + minSdk = 21 + targetSdk = 33 + } + namespace = "de.jensklingenberg.ktorfit.converters.call" +} + + + +publishing { + publications { + create("default") { + artifact(tasks["sourcesJar"]) + // artifact(tasks["javadocJar"]) + + pom { + name.set(project.name) + description.set("Flow Converter for Ktorfit") + url.set("https://github.com/Foso/Ktorfit") + + licenses { + license { + name.set("Apache License 2.0") + url.set("https://github.com/Foso/Ktorfit/blob/master/LICENSE.txt") + } + } + scm { + url.set("https://github.com/Foso/Ktorfit") + connection.set("scm:git:git://github.com/Foso/Ktorfit.git") + } + developers { + developer { + name.set("Jens Klingenberg") + url.set("https://github.com/Foso") + } + } + } + } + } + + repositories { + if ( + hasProperty("sonatypeUsername") && + hasProperty("sonatypePassword") && + hasProperty("sonatypeSnapshotUrl") && + hasProperty("sonatypeReleaseUrl") + ) { + maven { + val url = when { + "SNAPSHOT" in version.toString() -> property("sonatypeSnapshotUrl") + else -> property("sonatypeReleaseUrl") + } as String + setUrl(url) + credentials { + username = property("sonatypeUsername") as String + password = property("sonatypePassword") as String + } + } + } + + } +} + +rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class) { + rootProject.the(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class).nodeVersion = "18.0.0" +} diff --git a/ktorfit-converters/call/src/androidMain/AndroidManifest.xml b/ktorfit-converters/call/src/androidMain/AndroidManifest.xml new file mode 100644 index 000000000..568741e54 --- /dev/null +++ b/ktorfit-converters/call/src/androidMain/AndroidManifest.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/ktorfit-lib-common/src/commonMain/kotlin/de/jensklingenberg/ktorfit/converter/builtin/CallConverterFactory.kt b/ktorfit-converters/call/src/commonMain/kotlin/de/jensklingenberg/ktorfit/converter/builtin/CallConverterFactory.kt similarity index 100% rename from ktorfit-lib-common/src/commonMain/kotlin/de/jensklingenberg/ktorfit/converter/builtin/CallConverterFactory.kt rename to ktorfit-converters/call/src/commonMain/kotlin/de/jensklingenberg/ktorfit/converter/builtin/CallConverterFactory.kt diff --git a/ktorfit-lib-common/src/commonMain/kotlin/de/jensklingenberg/ktorfit/converter/builtin/CallResponseConverter.kt b/ktorfit-converters/call/src/commonMain/kotlin/de/jensklingenberg/ktorfit/converter/builtin/CallResponseConverter.kt similarity index 100% rename from ktorfit-lib-common/src/commonMain/kotlin/de/jensklingenberg/ktorfit/converter/builtin/CallResponseConverter.kt rename to ktorfit-converters/call/src/commonMain/kotlin/de/jensklingenberg/ktorfit/converter/builtin/CallResponseConverter.kt diff --git a/ktorfit-converters/flow/build.gradle.kts b/ktorfit-converters/flow/build.gradle.kts index 6c1ec33d2..bc435cb72 100644 --- a/ktorfit-converters/flow/build.gradle.kts +++ b/ktorfit-converters/flow/build.gradle.kts @@ -4,7 +4,7 @@ plugins { id("signing") id("com.vanniktech.maven.publish") id("com.android.library") - id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2" + alias(libs.plugins.binaryCompatibilityValidator) id("app.cash.licensee") } diff --git a/ktorfit-lib-common/api/android/ktorfit-lib-common.api b/ktorfit-lib-common/api/android/ktorfit-lib-common.api index dd3fce3a7..d00bd450a 100644 --- a/ktorfit-lib-common/api/android/ktorfit-lib-common.api +++ b/ktorfit-lib-common/api/android/ktorfit-lib-common.api @@ -122,20 +122,6 @@ public abstract interface class de/jensklingenberg/ktorfit/converter/SuspendResp public abstract fun wrapSuspendResponse (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lde/jensklingenberg/ktorfit/Ktorfit;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public final class de/jensklingenberg/ktorfit/converter/builtin/CallConverterFactory : de/jensklingenberg/ktorfit/converter/Converter$Factory { - public fun ()V - public fun requestParameterConverter (Lkotlin/reflect/KClass;Lkotlin/reflect/KClass;)Lde/jensklingenberg/ktorfit/converter/Converter$RequestParameterConverter; - public fun responseConverter (Lde/jensklingenberg/ktorfit/internal/TypeData;Lde/jensklingenberg/ktorfit/Ktorfit;)Lde/jensklingenberg/ktorfit/converter/Converter$ResponseConverter; - public fun suspendResponseConverter (Lde/jensklingenberg/ktorfit/internal/TypeData;Lde/jensklingenberg/ktorfit/Ktorfit;)Lde/jensklingenberg/ktorfit/converter/Converter$SuspendResponseConverter; -} - -public final class de/jensklingenberg/ktorfit/converter/builtin/CallResponseConverter : de/jensklingenberg/ktorfit/converter/SuspendResponseConverter, de/jensklingenberg/ktorfit/converter/request/ResponseConverter { - public fun ()V - public fun supportedType (Lde/jensklingenberg/ktorfit/internal/TypeData;Z)Z - public fun wrapResponse (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lde/jensklingenberg/ktorfit/Ktorfit;)Ljava/lang/Object; - public fun wrapSuspendResponse (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lde/jensklingenberg/ktorfit/Ktorfit;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - public abstract interface class de/jensklingenberg/ktorfit/converter/request/CoreResponseConverter { public abstract fun supportedType (Lde/jensklingenberg/ktorfit/internal/TypeData;Z)Z } diff --git a/ktorfit-lib-common/api/jvm/ktorfit-lib-common.api b/ktorfit-lib-common/api/jvm/ktorfit-lib-common.api index f15a6ebe8..a69587f4e 100644 --- a/ktorfit-lib-common/api/jvm/ktorfit-lib-common.api +++ b/ktorfit-lib-common/api/jvm/ktorfit-lib-common.api @@ -115,20 +115,6 @@ public abstract interface class de/jensklingenberg/ktorfit/converter/SuspendResp public abstract fun wrapSuspendResponse (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lde/jensklingenberg/ktorfit/Ktorfit;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public final class de/jensklingenberg/ktorfit/converter/builtin/CallConverterFactory : de/jensklingenberg/ktorfit/converter/Converter$Factory { - public fun ()V - public fun requestParameterConverter (Lkotlin/reflect/KClass;Lkotlin/reflect/KClass;)Lde/jensklingenberg/ktorfit/converter/Converter$RequestParameterConverter; - public fun responseConverter (Lde/jensklingenberg/ktorfit/internal/TypeData;Lde/jensklingenberg/ktorfit/Ktorfit;)Lde/jensklingenberg/ktorfit/converter/Converter$ResponseConverter; - public fun suspendResponseConverter (Lde/jensklingenberg/ktorfit/internal/TypeData;Lde/jensklingenberg/ktorfit/Ktorfit;)Lde/jensklingenberg/ktorfit/converter/Converter$SuspendResponseConverter; -} - -public final class de/jensklingenberg/ktorfit/converter/builtin/CallResponseConverter : de/jensklingenberg/ktorfit/converter/SuspendResponseConverter, de/jensklingenberg/ktorfit/converter/request/ResponseConverter { - public fun ()V - public fun supportedType (Lde/jensklingenberg/ktorfit/internal/TypeData;Z)Z - public fun wrapResponse (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lde/jensklingenberg/ktorfit/Ktorfit;)Ljava/lang/Object; - public fun wrapSuspendResponse (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lde/jensklingenberg/ktorfit/Ktorfit;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - public abstract interface class de/jensklingenberg/ktorfit/converter/request/CoreResponseConverter { public abstract fun supportedType (Lde/jensklingenberg/ktorfit/internal/TypeData;Z)Z } diff --git a/ktorfit-lib-common/build.gradle.kts b/ktorfit-lib-common/build.gradle.kts index 21dbf41b5..f560ea367 100644 --- a/ktorfit-lib-common/build.gradle.kts +++ b/ktorfit-lib-common/build.gradle.kts @@ -3,13 +3,12 @@ import de.jensklingenberg.ktorfit.gradle.KtorfitGradleConfiguration plugins { kotlin("multiplatform") alias(libs.plugins.kspPlugin) - id("maven-publish") id("signing") id("com.vanniktech.maven.publish") id("com.android.library") alias(libs.plugins.detekt) - id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2" + alias(libs.plugins.binaryCompatibilityValidator) id("app.cash.licensee") } diff --git a/ktorfit-lib/build.gradle.kts b/ktorfit-lib/build.gradle.kts index 1ef0dbd5e..37b75ba0c 100644 --- a/ktorfit-lib/build.gradle.kts +++ b/ktorfit-lib/build.gradle.kts @@ -4,7 +4,7 @@ plugins { id("signing") id("com.vanniktech.maven.publish") id("com.android.library") - id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2" + alias(libs.plugins.binaryCompatibilityValidator) id("app.cash.licensee") } diff --git a/sandbox/build.gradle.kts b/sandbox/build.gradle.kts index d0fd029f7..83d711ef6 100644 --- a/sandbox/build.gradle.kts +++ b/sandbox/build.gradle.kts @@ -58,6 +58,7 @@ kotlin { dependencies { implementation(projects.ktorfitLibCommon) implementation(projects.ktorfitConverters.flow) + implementation(projects.ktorfitConverters.call) implementation(libs.kotlinx.coroutines.core) implementation(libs.ktor.client.serialization) implementation(libs.ktor.client.content.negotiation) diff --git a/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/JvMMain.kt b/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/JvMMain.kt index 3ca8577fa..877af4bb2 100644 --- a/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/JvMMain.kt +++ b/sandbox/src/jvmMain/kotlin/de/jensklingenberg/ktorfit/demo/JvMMain.kt @@ -38,25 +38,23 @@ val jvmKtorfit = ktorfit { } - val userKtorfit = ktorfit { baseUrl("https://foso.github.io/Ktorfit/") httpClient(jvmClient) - converterFactories(FlowConverterFactory(),UserFactory()) + converterFactories(FlowConverterFactory(), UserFactory()) } - fun main() { runBlocking { - val user = userKtorfit.create().getUser() + val user = userKtorfit.create().getUser() - if(user.isSuccessful){ + if (user.isSuccessful) { println(user.body()) - }else{ + } else { user.errorBody() } delay(3000) diff --git a/settings.gradle.kts b/settings.gradle.kts index 0d20b0ee3..e39f11092 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -37,5 +37,6 @@ include(":ktorfit-lib-common") include(":ktorfit-lib") include(":ktorfit-annotations") include(":ktorfit-converters:flow") +include(":ktorfit-converters:call") //./gradlew clean :ktorfit-annotations:publishToMavenLocal :ktorfit-ksp:publishToMavenLocal :ktorfit-lib:publishToMavenLocal :ktorfit-lib-common:publishToMavenLocal :compiler-plugin:publishToMavenLocal \ No newline at end of file