Skip to content

Commit

Permalink
Merge branch 'master' into foso/2.0.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle/libs.versions.toml
#	ktorfit-gradle-plugin/src/main/java/de/jensklingenberg/ktorfit/gradle/KtorfitGradleConfiguration.kt
#	ktorfit-ksp/src/main/kotlin/de/jensklingenberg/ktorfit/model/KtorfitClass.kt
#	ktorfit-lib-core/src/jvmTest/kotlin/de/jensklingenberg/ktorfit/converter/ConverterTest.kt
  • Loading branch information
Foso committed Dec 28, 2023
2 parents 6cd4196 + f88f3e2 commit 5170f79
Show file tree
Hide file tree
Showing 30 changed files with 148 additions and 94 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Check out code
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
Expand All @@ -39,7 +39,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 11
distribution: 'zulu'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
submodules: "recursive"
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.7'
architecture: 'x64'
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
uses: actions/checkout@v4

- name: Install JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
Expand All @@ -32,7 +32,7 @@ jobs:
uses: actions/checkout@v4

- name: Install JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
Expand All @@ -53,7 +53,7 @@ jobs:
uses: actions/checkout@v4

- name: Install JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
Expand All @@ -74,7 +74,7 @@ jobs:
uses: actions/checkout@v4

- name: Install JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
Expand All @@ -95,7 +95,7 @@ jobs:
uses: actions/checkout@v4

- name: Install JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
Expand All @@ -116,7 +116,7 @@ jobs:
uses: actions/checkout@v4

- name: Install JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,30 @@ build.gradle.kts:

```kotlin
plugins {
id("de.jensklingenberg.ktorfit") version "1.11.0"
id("de.jensklingenberg.ktorfit") version "1.11.1"
}
```

build.gradle

```kotlin
plugins {
id("de.jensklingenberg.ktorfit") version "1.11.0"
id("de.jensklingenberg.ktorfit") version "1.11.1"
}
```

KSP:

```kotlin
de.jensklingenberg.ktorfit:ktorfit-ksp:1.11.0
de.jensklingenberg.ktorfit:ktorfit-ksp:1.11.1
```

Ktorfit-lib/-light:

```kotlin
implementation("de.jensklingenberg.ktorfit:ktorfit-lib:1.11.0")
implementation("de.jensklingenberg.ktorfit:ktorfit-lib:1.11.1")
or
implementation("de.jensklingenberg.ktorfit:ktorfit-lib-light:1.11.0")
implementation("de.jensklingenberg.ktorfit:ktorfit-lib-light:1.11.1")
```

## 👷 Project Structure
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project orients towards [Semantic Versioning](http://semver.org/spec/v2
Note: This project needs KSP to work and every new Ktorfit with an update of the KSP version is technically a breaking change.
But there is no intent to bump the Ktorfit major version for every KSP update.

1.11.1 - 2023-12-21
========================================
- Fix compile errors #505 #496

1.11.0 - 2023-12-06
========================================
Compatible with KSP 1.0.15 and Kotlin 1.9.21
Expand Down
4 changes: 2 additions & 2 deletions example/AndroidOnlyExample/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
id("org.jetbrains.kotlin.android")
id("com.google.devtools.ksp") version "1.9.20-1.0.14"
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.10"
id("de.jensklingenberg.ktorfit") version "1.11.0"
id("de.jensklingenberg.ktorfit") version "1.11.1"
}


Expand Down Expand Up @@ -51,7 +51,7 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach
}
}

val ktorfit = "1.11.0"
val ktorfit = "1.11.1"
val ktor = "2.3.6"
val compose_ui_version = "1.5.1"
dependencies {
Expand Down
4 changes: 2 additions & 2 deletions example/MultiplatformExample/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ plugins {
id("com.android.library")
id("com.google.devtools.ksp") version "1.9.21-1.0.15"
id("kotlinx-serialization")
id("de.jensklingenberg.ktorfit") version "1.11.0"
id("de.jensklingenberg.ktorfit") version "1.11.1"
}

version = "1.0"
val ktorVersion = "2.3.6"
val ktorfitVersion = "1.11.0"
val ktorfitVersion = "1.11.1"

kotlin {
jvmToolchain(8)
Expand Down
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ binaryCompatibilityValidator = "0.13.2"
coroutines = "1.7.3"
detekt = "1.23.1"
junit = "4.13.2"
kctfork = "0.3.2"
kctfork = "0.4.0"
kotlin = "1.9.21"
kotlinPoet = "1.15.1"
kspVersion = "1.9.21-1.0.15"
ktorVersion = "2.3.6"
ktorfit = "2.0.0-SNAPSHOT"
ktorfitGradlePlugin = "1.11.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ class CreateFuncTransformer(
symbol = newConstructor,
0,
0,
1,
0,
null
).apply {
this.putValueArgument(0, expression.dispatchReceiver)
}
)

//Set _ExampleApiImpl() as argument for create<ExampleApi>()
irCall.putValueArgument(0, newCall)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ class FunctionTransformerTest {
"Ktorfit.kt", """
package de.jensklingenberg.ktorfit
class Ktorfit()
class Ktorfit(){
fun <T> create(ktorfitService: KtorfitService? = null): T {
return ktorfitService as T
}
}
interface KtorfitService
class Default : KtorfitService
fun <T> Ktorfit.create(ktorfitService: KtorfitService = Default()): T {
return this.create(ktorfitService)
}
"""
)
val source2 = SourceFile.kotlin(
"Main.kt", """
package com.example.api
import de.jensklingenberg.ktorfit.Ktorfit
import de.jensklingenberg.ktorfit.create
import de.jensklingenberg.ktorfit.KtorfitService
interface TestService
Expand Down
23 changes: 23 additions & 0 deletions ktorfit-converters/response/api/android/call.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public abstract interface class de/jensklingenberg/ktorfit/Call {
public abstract fun onExecute (Lde/jensklingenberg/ktorfit/Callback;)V
}

public abstract interface class de/jensklingenberg/ktorfit/Callback {
public abstract fun onError (Ljava/lang/Throwable;)V
public abstract fun onResponse (Ljava/lang/Object;Lio/ktor/client/statement/HttpResponse;)V
}

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;
}

23 changes: 23 additions & 0 deletions ktorfit-converters/response/api/jvm/call.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public abstract interface class de/jensklingenberg/ktorfit/Call {
public abstract fun onExecute (Lde/jensklingenberg/ktorfit/Callback;)V
}

public abstract interface class de/jensklingenberg/ktorfit/Callback {
public abstract fun onError (Ljava/lang/Throwable;)V
public abstract fun onResponse (Ljava/lang/Object;Lio/ktor/client/statement/HttpResponse;)V
}

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;
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSFile
import com.google.devtools.ksp.symbol.KSPropertyDeclaration
import com.google.devtools.ksp.symbol.KSTypeReference
import com.squareup.kotlinpoet.ANY
import com.squareup.kotlinpoet.AnnotationSpec
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.*
import com.squareup.kotlinpoet.ksp.toKModifier
import com.squareup.kotlinpoet.ksp.toTypeName
import de.jensklingenberg.ktorfit.model.KtorfitError.Companion.PROPERTIES_NOT_SUPPORTED
Expand Down Expand Up @@ -87,35 +79,26 @@ fun ClassData.getImplClassFileSource(resolver: Resolver): String {

val implClassName = "_${classData.name}Impl"

val ktorfitProperty = PropertySpec
.builder(
name = ktorfitClass.objectName,
type = ktorfitClass.toClassName()
)
.initializer(ktorfitClass.objectName)
.mutable(false)
.addModifiers(KModifier.PRIVATE)
.build()


val converterProperty =
PropertySpec.builder(converterHelper.objectName, converterHelper.toClassName())
.initializer("%T(${ktorfitClass.objectName})", converterHelper.toClassName())
.addModifiers(KModifier.PRIVATE)
.addModifiers(KModifier.LATEINIT, KModifier.OVERRIDE)
.mutable(true)
.build()



val implClassSpec = TypeSpec.classBuilder(implClassName)
.primaryConstructor(
FunSpec.constructorBuilder()
.addParameter(ktorfitClass.objectName, ktorfitClass.toClassName())
.build()
)

.addAnnotation(
optinAnnotation
)
.addModifiers(classData.modifiers)
.addSuperinterface(ClassName(classData.packageName, classData.name))
.addSuperinterface(ktorfitInterface.toClassName())
.addKtorfitSuperInterface(classData.superClasses)
.addProperties(listOf(converterProperty, ktorfitProperty) + properties)
.addProperties(listOf(converterProperty) + properties)
.addFunctions(classData.functions.map { it.toFunSpec(resolver) })
.build()

Expand All @@ -135,9 +118,10 @@ fun ClassData.getImplClassFileSource(resolver: Resolver): String {
private fun getCreateExtensionFunctionSpec(
classData: ClassData
): FunSpec {
return FunSpec.builder("create${classData.name}")
val functionName = "create${classData.name}"
return FunSpec.builder(functionName)
.addModifiers(classData.modifiers)
.addStatement("return this.create(_${classData.name}Impl(this))")
.addStatement("return this.create(_${classData.name}Impl().apply { ${converterHelper.objectName}= ${converterHelper.name}(this@$functionName) })")
.receiver(ktorfitClass.toClassName())
.returns(ClassName(classData.packageName, classData.name))
.build()
Expand Down Expand Up @@ -252,10 +236,9 @@ private fun TypeSpec.Builder.addKtorfitSuperInterface(superClasses: List<KSTypeR
this.addSuperinterface(
ClassName(superTypePackage, superTypeClassName),
CodeBlock.of(
"%L._%LImpl(%L)",
"%L._%LImpl()",
superTypePackage,
superTypeClassName,
ktorfitClass.objectName
superTypeClassName
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import com.squareup.kotlinpoet.ClassName
data class KtorfitClass(val name: String, val packageName: String, val objectName: String)

val ktorfitClass = KtorfitClass("Ktorfit", "de.jensklingenberg.ktorfit", "_ktorfit")
val typeDataClass = KtorfitClass("TypeData", "de.jensklingenberg.ktorfit.converter", "_typeData")
val ktorfitInterface = KtorfitClass("KtorfitInterface", "de.jensklingenberg.ktorfit.internal", "EMPTY")
val typeDataClass = KtorfitClass("TypeData", "de.jensklingenberg.ktorfit.internal", "_typeData")
val extDataClass = KtorfitClass("HttpRequestBuilder.() -> Unit", "", "_ext")
val formParameters = KtorfitClass("", "", "__formParameters")
val converterHelper = KtorfitClass("KtorfitConverterHelper","de.jensklingenberg.ktorfit.internal", "_converter")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import de.jensklingenberg.ktorfit.model.ParameterData
import de.jensklingenberg.ktorfit.model.annotations.HttpMethodAnnotation
import de.jensklingenberg.ktorfit.model.annotations.ParameterAnnotation.Path
import de.jensklingenberg.ktorfit.model.annotations.ParameterAnnotation.Url
import de.jensklingenberg.ktorfit.model.converterHelper
import de.jensklingenberg.ktorfit.model.ktorfitClass


Expand All @@ -19,8 +20,8 @@ fun getUrlCode(params: List<ParameterData>, methodAnnotation: HttpMethodAnnotati
""
} else {
params.firstOrNull { it.hasAnnotation<Url>() }?.let { parameterData ->
"(${ktorfitClass.objectName}.baseUrl.takeIf{ !${parameterData.name}.startsWith(\"http\")} ?: \"\") + "
} ?: "${ktorfitClass.objectName}.baseUrl + "
"(${converterHelper.objectName}.baseUrl.takeIf{ !${parameterData.name}.startsWith(\"http\")} ?: \"\") + "
} ?: "${converterHelper.objectName}.baseUrl + "
}

params.filter { it.hasAnnotation<Path>() }.forEach { parameterData ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ interface TestService {
val expectedFunctionText = """val _ext: HttpRequestBuilder.() -> Unit = {
method = HttpMethod.parse("GET2")
url{
takeFrom(_ktorfit.baseUrl + "user")
takeFrom(_converter.baseUrl + "user")
}
setBody(body)
}"""
Expand Down
Loading

0 comments on commit 5170f79

Please sign in to comment.