Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Call converter to own module #433

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> {
companion object {
const val GRADLE_TASKNAME = "ktorfit"
Expand All @@ -24,16 +22,20 @@ class KtorfitGradlePlugin : Plugin<Project> {
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)
}
}

Expand Down
6 changes: 4 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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" }
Expand Down Expand Up @@ -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" }
2 changes: 1 addition & 1 deletion ktorfit-annotations/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
21 changes: 21 additions & 0 deletions ktorfit-converters/call/api/android/call.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public final class de/jensklingenberg/ktorfit/converter/builtin/CallConverterFactory : de/jensklingenberg/ktorfit/converter/Converter$Factory {
public fun <init> ()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 <init> ()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 <init> ()V
}

14 changes: 14 additions & 0 deletions ktorfit-converters/call/api/jvm/call.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public final class de/jensklingenberg/ktorfit/converter/builtin/CallConverterFactory : de/jensklingenberg/ktorfit/converter/Converter$Factory {
public fun <init> ()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 <init> ()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;
}

174 changes: 174 additions & 0 deletions ktorfit-converters/call/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
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<MavenPublication>("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"
}
2 changes: 2 additions & 0 deletions ktorfit-converters/call/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest />
2 changes: 1 addition & 1 deletion ktorfit-converters/flow/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
14 changes: 0 additions & 14 deletions ktorfit-lib-common/api/android/ktorfit-lib-common.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> ()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 <init> ()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
}
Expand Down
14 changes: 0 additions & 14 deletions ktorfit-lib-common/api/jvm/ktorfit-lib-common.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> ()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 <init> ()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
}
Expand Down
3 changes: 1 addition & 2 deletions ktorfit-lib-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

}
Expand Down
2 changes: 1 addition & 1 deletion ktorfit-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
1 change: 1 addition & 0 deletions sandbox/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExampleApi>().getUser()
val user = userKtorfit.create<ExampleApi>().getUser()

if(user.isSuccessful){
if (user.isSuccessful) {
println(user.body())
}else{
} else {
user.errorBody()
}
delay(3000)
Expand Down
Loading