Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
* Code cleanup
  • Loading branch information
Foso authored Oct 6, 2023
1 parent 0a89b62 commit 80fec2c
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: gradle/gradle-build-action@v2

- name: Publish release
run: ./gradlew clean :ktorfit-annotations:publishAllPublicationsToMavenCentralRepository :ktorfit-ksp:publishAllPublicationsToMavenCentralRepository :ktorfit-lib:publishAllPublicationsToMavenCentralRepository :ktorfit-lib-common:publishAllPublicationsToMavenCentralRepository :compiler-plugin:publishAllPublicationsToMavenCentralRepository
run: ./gradlew clean :ktorfit-annotations:publishAllPublicationsToMavenCentralRepository :ktorfit-ksp:publishAllPublicationsToMavenCentralRepository :ktorfit-lib:publishAllPublicationsToMavenCentralRepository :ktorfit-lib-common:publishAllPublicationsToMavenCentralRepository :compiler-plugin:publishAllPublicationsToMavenCentralRepository :ktorfit-converters:call:publishAllPublicationsToMavenCentralRepository :ktorfit-converters:flow:publishAllPublicationsToMavenCentralRepository
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
Expand Down
21 changes: 12 additions & 9 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
Releasing
=========

1. Change the version in `gradle.properties` to a non-SNAPSHOT version.
2. Update the `CHANGELOG.md` for the impending release.
3. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version)
4. `git tag -a X.Y.Z -m "Version X.Y.Z"` (where X.Y.Z is the new version)
5. `./gradlew clean publish --no-daemon --no-parallel && ./gradlew closeAndReleaseRepository`
6. Update the `gradle.properties` to the next SNAPSHOT version.
7. `git commit -am "Prepare next development version."`
8. `git push && git push --tags`
# Publish new version

//publishAllPublicationsToMavenCentralRepository
1. Create new branch `release/X.Y.Z` from `master` branch
2. Update **ktorfit** version inside `gradle/libs.versions.toml`
3. Update Compatibility table in Readme.md
4. Update ktorfit release version in mkdocs.yml
5. `git commit -am "Release X.Y.Z."` (where X.Y.Z is the new version)
6. Push and create a PR to the `master` branch
7. When all checks successful, run GitHub Action `Publish Release` from your branch
8. Set the Git tag `git tag -a X.Y.Z -m "X.Y.Z"` (where X.Y.Z is the new version)
9. Merge the PR
10. Create a new release with for the Tag on GitHub
11. Put the relevant changelog in the release description
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ subprojects {
google()
mavenLocal()
mavenCentral()

}

}

// ./gradlew clean :sandbox:compileKotlinJvm --no-daemon -Dorg.gradle.debug=true -Dkotlin.compiler.execution.strategy="in-process" -Dkotlin.daemon.jvm.options="-Xdebug,-Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n"
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ internal class KtorfitCompilerSubPlugin : KotlinCompilerPluginSupportPlugin {
?: KtorfitGradleConfiguration()

return kotlinCompilation.target.project.provider {
val options = mutableListOf(
listOf(
SubpluginOption("enabled", gradleExtension.enabled.toString()),
SubpluginOption("logging", gradleExtension.logging.toString())
)
options
}
}

Expand Down
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktorVer
ktor-client-core-jvm = { module = "io.ktor:ktor-client-core-jvm", version.ref = "ktorVersion" }
ktor-client-core-linux = { module = "io.ktor:ktor-client-core-linuxx64", version.ref = "ktorVersion" }
ktor-client-core-mingwx64 = { module = "io.ktor:ktor-client-core-mingwx64", version.ref = "ktorVersion" }
ktor-client-core-native = "io.ktor:ktor-client-core-native:1.3.1"
ktor-client-curl = { module = "io.ktor:ktor-client-curl", version.ref = "ktorVersion" }
ktor-client-ios = { module = "io.ktor:ktor-client-ios", version.ref = "ktorVersion" }
ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktorVersion" }
Expand All @@ -55,7 +54,6 @@ ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx
licensee-gradle-plugin = "app.cash.licensee:licensee-gradle-plugin:1.8.0"
logbackClassic = "ch.qos.logback:logback-classic:1.4.11"
mockito-kotlin = "org.mockito.kotlin:mockito-kotlin:4.1.0"
rxjava3 = "io.reactivex.rxjava3:rxjava:3.1.6"
truth = "com.google.truth:truth:1.1.5"

[plugins]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ public class CallResponseConverter : SuspendResponseConverter, ResponseConverter
} catch (ex: Exception) {
callBack.onError(ex)
}

}
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ fun getHeadersCode(
arrayType: KSType
): String {

val contentTypeText = if (functionAnnotations.anyInstance<FormUrlEncoded>()) {
"append(\"Content-Type\", \"application/x-www-form-urlencoded\")\n"
} else ""

val headerAnnotationText =
parameterDataList
.filter { it.hasAnnotation<Header>() }
Expand Down Expand Up @@ -60,6 +56,10 @@ fun getHeadersCode(
"${it.name}?.forEach { append(it.key, \"\${it.value}\") }\n"
}

val contentTypeText = if (functionAnnotations.anyInstance<FormUrlEncoded>()) {
"append(\"Content-Type\", \"application/x-www-form-urlencoded\")\n"
} else ""

return "$contentTypeText$headerAnnotationText$headerMapAnnotationText$headersAnnotationText".surroundIfNotEmpty(
"headers{\n",
"}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ internal class DefaultSuspendResponseConverterFactory : Converter.Factory {
class DefaultSuspendResponseConverter(val typeData: TypeData) :
Converter.SuspendResponseConverter<HttpResponse, Any> {
override suspend fun convert(response: HttpResponse): Any {
return try {
response.call.body(typeData.typeInfo)
} catch (exception: Exception) {
throw exception
}
return response.call.body(typeData.typeInfo)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,29 @@ internal class KtorfitDefaultConverterFactory : Converter.Factory {
Converter.SuspendResponseConverter<HttpResponse, Response<Any?>> {
override suspend fun convert(response: HttpResponse): Response<Any?> {
val typeInfo = typeData.typeArgs.first().typeInfo
return try {
val rawResponse = response

val code: Int = rawResponse.status.value
when {
code < 200 || code >= 300 -> {
val errorBody = rawResponse.body<Any>()
Response.error(errorBody, rawResponse)
}

code == 204 || code == 205 -> {
Response.success<Any>(null, rawResponse)
}

else -> {
val convertedBody = ktorfit.nextSuspendResponseConverter(
null,
typeData.typeArgs.first()
)?.convert(rawResponse)
?: rawResponse.body<Any>(typeInfo)
Response.success(convertedBody, rawResponse)
}

val rawResponse = response

val code: Int = rawResponse.status.value

return when {
code < 200 || code >= 300 -> {
val errorBody = rawResponse.body<Any>()
Response.error(errorBody, rawResponse)
}

code == 204 || code == 205 -> {
Response.success<Any>(null, rawResponse)
}

else -> {
val convertedBody = ktorfit.nextSuspendResponseConverter(
null,
typeData.typeArgs.first()
)?.convert(rawResponse)
?: rawResponse.body(typeInfo)
Response.success(convertedBody, rawResponse)
}
} catch (exception: Exception) {
throw exception
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ internal class KtorfitClient(private val ktorfit: Ktorfit) : Client {
} as ReturnType
}

if (returnTypeData.typeInfo.type == HttpResponse::class) {
val response = httpClient.request {
requestBuilder(requestData)
}
return response as ReturnType
}

ktorfit.nextSuspendResponseConverter(null, returnTypeData)?.let {

val response = httpClient.request {
Expand Down Expand Up @@ -124,6 +117,4 @@ internal class KtorfitClient(private val ktorfit: Ktorfit) : Client {
) {
requestData.ktorfitRequestBuilder(this)
}


}
4 changes: 1 addition & 3 deletions sandbox/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ kotlin {
}
val linuxX64Main by getting {
dependencies {

implementation(libs.ktor.client.core.native)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.ktor.client.curl)
implementation(libs.ktor.client.core.linux)
Expand All @@ -85,7 +83,7 @@ kotlin {
dependencies {
implementation(libs.ktor.client.core.jvm)
implementation(libs.kotlinx.coroutines.rx3)
implementation(libs.rxjava3)
implementation("io.reactivex.rxjava3:rxjava:3.1.7")

implementation(libs.ktor.client.logging)
// implementation(libs.logbackClassic)
Expand Down

0 comments on commit 80fec2c

Please sign in to comment.