Skip to content

Commit

Permalink
Move Flow converter to own module (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
Foso authored Sep 27, 2023
1 parent 9288a7c commit e88e3b9
Show file tree
Hide file tree
Showing 20 changed files with 300 additions and 91 deletions.
16 changes: 7 additions & 9 deletions gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
kotlin("kapt") version("1.9.10")
id("java-gradle-plugin")
`maven-publish`
`kotlin-dsl`
id("com.gradle.plugin-publish") version "1.2.1"
}

Expand All @@ -26,6 +27,10 @@ java {
}
}

dependencies {
add("compileOnly", kotlin("gradle-plugin"))
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
Expand All @@ -41,28 +46,21 @@ gradlePlugin {

create("ktorfitPlugin") {
id = "de.jensklingenberg.ktorfit" // users will do `apply plugin: "de.jensklingenberg.ktorfit"`
implementationClass = "de.jensklingenberg.ktorfit.gradle.KtorfitGradleSubPlugin" // entry-point class
implementationClass = "de.jensklingenberg.ktorfit.gradle.KtorfitGradlePlugin" // entry-point class
displayName = "Ktorfit Gradle Plugin"
description = "Gradle Plugin for Ktorfit"
tags.set(listOf("http","kotlin","kotlin-mpp","ktor","rest"))
}
}
}

tasks.register("sourcesJar", Jar::class) {
group = "build"
description = "Assembles Kotlin sources"

archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
dependsOn(tasks.classes)
}

publishing {
publications {
create<MavenPublication>("default") {
from(components["java"])
artifact(tasks["sourcesJar"])


pom {
name.set("ktorfit-gradle-plugin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,12 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption

open class KtorfitGradleConfiguration {
/**
* If the compiler plugin should be active
*/
var enabled: Boolean = true

/**
* version number of the compiler plugin
*/
var version: String = "1.7.0" // remember to bump this version before any release!

/**
* used to get debug information from the compiler plugin
*/
var logging: Boolean = false
}


class KtorfitGradleSubPlugin : KotlinCompilerPluginSupportPlugin {
internal class KtorfitCompilerSubPlugin : KotlinCompilerPluginSupportPlugin {

companion object {
const val SERIALIZATION_GROUP_NAME = "de.jensklingenberg.ktorfit"
const val ARTIFACT_NAME = "compiler-plugin"
const val COMPILER_PLUGIN_ID = "ktorfitPlugin"
const val GRADLE_TASKNAME = "ktorfit"
}

private lateinit var myproject: Project
Expand All @@ -52,10 +33,8 @@ class KtorfitGradleSubPlugin : KotlinCompilerPluginSupportPlugin {
private fun Project.getKtorfitConfig() =
this.extensions.findByType(KtorfitGradleConfiguration::class.java) ?: KtorfitGradleConfiguration()

override fun apply(target: Project) {
target.extensions.create(GRADLE_TASKNAME, KtorfitGradleConfiguration::class.java)
myproject = target
super.apply(target)
override fun apply(project: Project) {
myproject = project
}

override fun getCompilerPluginId(): String = COMPILER_PLUGIN_ID
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.jensklingenberg.ktorfit.gradle

open class KtorfitGradleConfiguration {
/**
* If the compiler plugin should be active
*/
var enabled: Boolean = true

/**
* version number of the compiler plugin
*/
@Deprecated("Update the this Gradle plugin instead of updating this version")
var version: String = "1.7.0" // remember to bump this version before any release!

/**
* used to get debug information from the compiler plugin
*/
var logging: Boolean = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package de.jensklingenberg.ktorfit.gradle

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.findByType
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"
}

private val Project.kotlinExtension: KotlinProjectExtension?
get() = this.extensions.findByType<KotlinProjectExtension>()

override fun apply(project: Project) {

with(project) {
extensions.create(GRADLE_TASKNAME, KtorfitGradleConfiguration::class.java)

val flowConverterDependencyNotation = "de.jensklingenberg.ktorfit:ktorfit-converters-flow:1.7.0"
when (kotlinExtension) {
is KotlinSingleTargetExtension<*> -> {
dependencies {
add("implementation", flowConverterDependencyNotation)
}
}

is KotlinMultiplatformExtension -> {
dependencies {
add("commonMainImplementation", flowConverterDependencyNotation)
}
}

else -> { /* Do nothing */
}
}
}
project.pluginManager.apply(KtorfitCompilerSubPlugin::class.java)
}


}
2 changes: 2 additions & 0 deletions ktorfit-converters/flow/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/.gradle/
20 changes: 20 additions & 0 deletions ktorfit-converters/flow/api/android/flow.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public final class de/jensklingenberg/ktorfit/converter/builtin/FlowConverterFactory : 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/FlowResponseConverter : 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 final class de/jensklingenberg/ktorfit/converters/flow/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
}

13 changes: 13 additions & 0 deletions ktorfit-converters/flow/api/jvm/flow.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public final class de/jensklingenberg/ktorfit/converter/builtin/FlowConverterFactory : 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/FlowResponseConverter : 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;
}

174 changes: 174 additions & 0 deletions ktorfit-converters/flow/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")
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2"
id("app.cash.licensee")
}

licensee {
allow("Apache-2.0")
allow("MIT")
}


val enableSigning = project.hasProperty("ORG_GRADLE_PROJECT_signingInMemoryKey")

mavenPublishing {

coordinates(
"de.jensklingenberg.ktorfit",
"ktorfit-converters-flow",
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.flow"
}



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"
}
1 change: 1 addition & 0 deletions ktorfit-converters/flow/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kotlin.mpp.androidSourceSetLayoutVersion=2
2 changes: 2 additions & 0 deletions ktorfit-converters/flow/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 />
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import kotlinx.coroutines.flow.flow
/**
* Converter to enable the use of Flow<> as return type
*/
@Deprecated("Use FlowConverterFactory")
public class FlowResponseConverter : ResponseConverter {

override fun supportedType(typeData: TypeData, isSuspend: Boolean): Boolean {
Expand Down
Loading

0 comments on commit e88e3b9

Please sign in to comment.