From f92026fff339c7186c894e314a84dd4ec9d2843c Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Wed, 21 Feb 2024 11:54:03 +0700 Subject: [PATCH 1/4] #207 removed use of project in task --- .../kotlin/dev/icerock/moko/network/tasks/GenerateTask.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/network-generator/src/main/kotlin/dev/icerock/moko/network/tasks/GenerateTask.kt b/network-generator/src/main/kotlin/dev/icerock/moko/network/tasks/GenerateTask.kt index bbcc0ee..a47a3dc 100644 --- a/network-generator/src/main/kotlin/dev/icerock/moko/network/tasks/GenerateTask.kt +++ b/network-generator/src/main/kotlin/dev/icerock/moko/network/tasks/GenerateTask.kt @@ -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 { @@ -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() } } } From 38c0a1cb88675fbc5aeb2c030dfaba315bfd1d4e Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Wed, 21 Feb 2024 11:54:50 +0700 Subject: [PATCH 2/4] #207 reformat plugin --- .../MultiPlatformNetworkGeneratorPlugin.kt | 58 ++++++++++++------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/network-generator/src/main/kotlin/dev/icerock/moko/network/MultiPlatformNetworkGeneratorPlugin.kt b/network-generator/src/main/kotlin/dev/icerock/moko/network/MultiPlatformNetworkGeneratorPlugin.kt index d7933f0..f41a4bc 100644 --- a/network-generator/src/main/kotlin/dev/icerock/moko/network/MultiPlatformNetworkGeneratorPlugin.kt +++ b/network-generator/src/main/kotlin/dev/icerock/moko/network/MultiPlatformNetworkGeneratorPlugin.kt @@ -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 { - 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" } @@ -53,3 +50,22 @@ class MultiPlatformNetworkGeneratorPlugin : Plugin { .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 = tasks.register( + "${spec.name}OpenApiGenerate", + GenerateTask::class.java + ) { it.configure(spec, generatedDir) } + + openApiGenerateTask.dependsOn(generateTask) +} From 2583911ca85697b181ad5244986f7d6807d537c4 Mon Sep 17 00:00:00 2001 From: Konstantin Kolchurin Date: Wed, 21 Feb 2024 11:55:08 +0700 Subject: [PATCH 3/4] #207 upgrade version --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 03b303a..9e87337 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" From 866c77aa3d549bc95f58b7aa44e778fcc1593211 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 25 Feb 2024 22:46:35 +0700 Subject: [PATCH 4/4] up version in readme --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d165f20..eecaf0a 100755 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ buildscript { } dependencies { - classpath "dev.icerock.moko:network-generator:0.21.0" + classpath "dev.icerock.moko:network-generator:0.21.1" } } @@ -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 } ```