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

Release 0.21.1 #209

Merged
merged 5 commits into from
Feb 25, 2024
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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ buildscript {
}

dependencies {
classpath "dev.icerock.moko:network-generator:0.21.0"
classpath "dev.icerock.moko:network-generator:0.21.1"
}
}

Expand All @@ -53,10 +53,10 @@ project build.gradle
apply plugin: "dev.icerock.mobile.multiplatform-network-generator"

dependencies {
commonMainApi("dev.icerock.moko:network:0.21.0")
commonMainApi("dev.icerock.moko:network-engine:0.21.0") // configured HttpClientEngine
commonMainApi("dev.icerock.moko:network-bignum:0.21.0") // kbignum serializer
commonMainApi("dev.icerock.moko:network-errors:0.21.0") // moko-errors integration
commonMainApi("dev.icerock.moko:network:0.21.1")
commonMainApi("dev.icerock.moko:network-engine:0.21.1") // configured HttpClientEngine
commonMainApi("dev.icerock.moko:network-bignum:0.21.1") // kbignum serializer
commonMainApi("dev.icerock.moko:network-errors:0.21.1") // moko-errors integration
}
```

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mokoResourcesVersion = "0.21.2"
mokoMvvmVersion = "0.16.0"
mokoErrorsVersion = "0.7.0"
mokoTestVersion = "0.6.1"
mokoNetworkVersion = "0.21.0"
mokoNetworkVersion = "0.21.1"

# tests
espressoCoreVersion = "3.5.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,39 @@ package dev.icerock.moko.network
import dev.icerock.moko.network.tasks.GenerateTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinNativeCompile

@Suppress("ForbiddenComment")
class MultiPlatformNetworkGeneratorPlugin : Plugin<Project> {

override fun apply(target: Project) {
val mokoNetworkExtension = target.extensions.create("mokoNetwork", SpecConfig::class.java)
override fun apply(project: Project) {
val mokoNetworkExtension = project.extensions.create("mokoNetwork", SpecConfig::class.java)

target.afterEvaluate { it.setupProject(mokoNetworkExtension) }
project.afterEvaluate {
it.setupProject(mokoNetworkExtension)
}
}

private fun Project.setupProject(extension: SpecConfig) {
val multiplatformExtension =
extensions.findByType(KotlinMultiplatformExtension::class.java)
private fun Project.setupProject(mokoNetworkExtension: SpecConfig) {
val multiplatformExtension: KotlinMultiplatformExtension = project.extensions.getByType()

if (extension.specs.isEmpty()) return
if (mokoNetworkExtension.specs.isEmpty()) return

val openApiGenerateTask = tasks.create("openApiGenerate") {
it.group = "moko-network"
}

extension.specs.forEach { spec ->
val generatedDir = "$buildDir/generated/moko-network/${spec.name}"
val generatedSourcesDir = "$generatedDir/src/main/kotlin"
val sourceSet = multiplatformExtension?.sourceSets?.getByName(spec.sourceSet)

sourceSet?.kotlin?.srcDir(generatedSourcesDir)

val generateTask: GenerateTask = tasks.create(
"${spec.name}OpenApiGenerate",
GenerateTask::class.java
) { it.configure(spec, generatedDir) }

openApiGenerateTask.dependsOn(generateTask)
mokoNetworkExtension.specs.forEach { spec ->
registerSpecGenerationTask(
spec = spec,
openApiGenerateTask = openApiGenerateTask,
multiplatformExtension = multiplatformExtension
)
}

tasks.matching { it.name == "preBuild" }
Expand All @@ -53,3 +50,22 @@ class MultiPlatformNetworkGeneratorPlugin : Plugin<Project> {
.all { it.dependsOn(openApiGenerateTask) }
}
}

private fun Project.registerSpecGenerationTask(
spec: SpecInfo,
openApiGenerateTask: Task,
multiplatformExtension: KotlinMultiplatformExtension,
) {
val generatedDir = "$buildDir/generated/moko-network/${spec.name}"
val generatedSourcesDir = "$generatedDir/src/main/kotlin"
val sourceSet: KotlinSourceSet? = multiplatformExtension.sourceSets.getByName(spec.sourceSet)

sourceSet?.kotlin?.srcDir(generatedSourcesDir)

val generateTask: TaskProvider<GenerateTask> = tasks.register(
"${spec.name}OpenApiGenerate",
GenerateTask::class.java
) { it.configure(spec, generatedDir) }

openApiGenerateTask.dependsOn(generateTask)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package dev.icerock.moko.network.tasks
import dev.icerock.moko.network.KtorCodegen
import dev.icerock.moko.network.SpecInfo
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
import java.io.File

open class GenerateTask : GenerateTask() {
init {
Expand All @@ -33,9 +34,7 @@ open class GenerateTask : GenerateTask() {

doFirst {
// clean directory before generate new code
val cleanupDir = outputDir.get()
val dir = project.file(cleanupDir)
dir.deleteRecursively()
File(outputDir.get()).deleteRecursively()
}
}
}
Loading