From 3d86975b054f4ae25cca5fcf585e09822b3c33ab Mon Sep 17 00:00:00 2001 From: Julian Bokelmann Date: Tue, 9 Apr 2024 13:22:42 +0200 Subject: [PATCH 01/10] Fix typo in docs --- docs/reference/koin-annotations/start.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/koin-annotations/start.md b/docs/reference/koin-annotations/start.md index 57bf82a..47669c1 100644 --- a/docs/reference/koin-annotations/start.md +++ b/docs/reference/koin-annotations/start.md @@ -51,7 +51,7 @@ The Koin compiler offers some options to configure. Following the official doc, ### Compile Safety - check your Koin config at compile time (since 1.3.0) -Koin Annotations allows the compiler plugin to verify yout Koin configuration at compile time. This can be activated with the following Ksp options, to add to your Gradle module: +Koin Annotations allows the compiler plugin to verify your Koin configuration at compile time. This can be activated with the following Ksp options, to add to your Gradle module: ```groovy // in build.gradle or build.gradle.kts From 2d82fdbb82e44aeed5b08cfcb8b2b802b9dda6f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ShellWen=20=7C=20=E9=A2=89=E6=96=87?= Date: Wed, 17 Jul 2024 00:05:12 +0800 Subject: [PATCH 02/10] Fix typos in `/docs/reference/koin-annotations/start.md` --- docs/reference/koin-annotations/start.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/koin-annotations/start.md b/docs/reference/koin-annotations/start.md index 47669c1..2a5a1e9 100644 --- a/docs/reference/koin-annotations/start.md +++ b/docs/reference/koin-annotations/start.md @@ -69,7 +69,7 @@ The compiler will check that all dependencies used in your configuration is decl ### Disabling Default Module (since 1.3.0) -By default, the Koibn compiler detect any definition not bound to a module and put it in a "default mmodule", a Koin module generated at the root of your project. You can disable the use and generation of default module with the following option: +By default, the Koin compiler detect any definition not bound to a module and put it in a "default module", a Koin module generated at the root of your project. You can disable the use and generation of default module with the following option: ```groovy // in build.gradle or build.gradle.kts From b05bbdf5e0ccbe4b6d93cd45a370af8371898172 Mon Sep 17 00:00:00 2001 From: Tomas Sustek Date: Sun, 25 Aug 2024 21:09:38 +0200 Subject: [PATCH 03/10] Fix compose ViewModel import Fixes InsertKoinIO/koin-annotations#150 Fixes InsertKoinIO/koin-annotations#86 --- .../kotlin/org/koin/compiler/generator/KoinCodeGenerator.kt | 2 +- .../jvmMain/kotlin/org/koin/compiler/generator/ModuleWriter.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/KoinCodeGenerator.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/KoinCodeGenerator.kt index c14cb4f..4b5dc15 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/KoinCodeGenerator.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/KoinCodeGenerator.kt @@ -57,7 +57,7 @@ class KoinCodeGenerator( if (defaultModule.alreadyGenerated == false && hasDefaultDefinitions){ defaultModule.setCurrentDefinitionsToExternals() - DefaultModuleWriter(codeGenerator, resolver, defaultModule, generateDefaultModule).writeModule() + DefaultModuleWriter(codeGenerator, resolver, defaultModule, generateDefaultModule).writeModule(isComposeViewModelActive) } } diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleWriter.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleWriter.kt index eee5c8a..d0af042 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleWriter.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleWriter.kt @@ -49,7 +49,7 @@ abstract class ModuleWriter( private val generatedField = "${module.packageName("_")}_${module.name}" //TODO Remove isComposeViewModelActive with Koin 4 - fun writeModule(isComposeViewModelActive: Boolean = false) { + fun writeModule(isComposeViewModelActive: Boolean) { fileStream = createFileStream() definitionFactory = DefinitionWriterFactory(resolver, fileStream!!) From c799a51067e010403e291fe4d2f634f547c3f261 Mon Sep 17 00:00:00 2001 From: Tomas Sustek Date: Sun, 25 Aug 2024 21:36:42 +0200 Subject: [PATCH 04/10] Fix missing newline between imports Fixes InsertKoinIO/koin-annotations#158 --- .../kotlin/org/koin/compiler/generator/ModuleWriter.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleWriter.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleWriter.kt index eee5c8a..76b00f1 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleWriter.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleWriter.kt @@ -85,11 +85,11 @@ abstract class ModuleWriter( } open fun writeHeader() { - write(MODULE_HEADER) + writeln(MODULE_HEADER) } open fun writeHeaderImports(isComposeViewModelActive: Boolean) { - write(generateImports(module.definitions, isComposeViewModelActive)) + writeln(generateImports(module.definitions, isComposeViewModelActive)) } private fun generateImports( @@ -105,7 +105,7 @@ abstract class ModuleWriter( keyword.import?.let { "import $it" } } } - .joinToString(separator = "\n", postfix = "\n") + .joinToString(separator = "\n") } open fun writeExternalDefinitions() { From 3727e24032367a773bcdb3667777dc3860f900b8 Mon Sep 17 00:00:00 2001 From: Tomas Sustek Date: Sun, 25 Aug 2024 21:39:58 +0200 Subject: [PATCH 05/10] Add "in" to forbidden keywords Fixes InsertKoinIO/koin-annotations#110 --- .../src/jvmMain/kotlin/org/koin/compiler/scanner/ext/KspExt.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/ext/KspExt.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/ext/KspExt.kt index 15ba836..061a3e5 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/ext/KspExt.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/ext/KspExt.kt @@ -138,7 +138,7 @@ internal fun List.getValueArgument(): String? { fun KSClassDeclaration.getPackageName() : String = packageName.asString() -val forbiddenKeywords = listOf("interface","it") +val forbiddenKeywords = listOf("in","interface","it") fun String.filterForbiddenKeywords() : String{ return split(".").joinToString(".") { if (it in forbiddenKeywords) "`$it`" else it From 688e05c2c86d8ab07002966d0cc1e1bccea98266 Mon Sep 17 00:00:00 2001 From: Fabio Catinella Date: Tue, 27 Aug 2024 14:39:43 +0200 Subject: [PATCH 06/10] fix: Removed "it" from forbiddenKeywords and replace "" with "_ -> " when generating params string in case of no injected params. Fixes gh-161 (koin-annotations) --- .../kotlin/org/koin/compiler/generator/DefinitionWriter.kt | 2 +- .../src/jvmMain/kotlin/org/koin/compiler/scanner/ext/KspExt.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/DefinitionWriter.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/DefinitionWriter.kt index ff1d64b..b905177 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/DefinitionWriter.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/DefinitionWriter.kt @@ -95,7 +95,7 @@ class DefinitionWriter( } private fun List.generateParamFunction(): String { - return if (any { it is KoinMetaData.DefinitionParameter.ParameterInject }) "params -> " else "" + return if (any { it is KoinMetaData.DefinitionParameter.ParameterInject }) "params -> " else "_ -> " } private fun String?.generateQualifier(): String = when { diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/ext/KspExt.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/ext/KspExt.kt index 15ba836..a713942 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/ext/KspExt.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/ext/KspExt.kt @@ -138,7 +138,7 @@ internal fun List.getValueArgument(): String? { fun KSClassDeclaration.getPackageName() : String = packageName.asString() -val forbiddenKeywords = listOf("interface","it") +val forbiddenKeywords = listOf("interface") fun String.filterForbiddenKeywords() : String{ return split(".").joinToString(".") { if (it in forbiddenKeywords) "`$it`" else it From 4cba2bf083ebec6e2f297ea0cffe473fd5119285 Mon Sep 17 00:00:00 2001 From: theophiluskibet Date: Fri, 27 Sep 2024 09:24:30 +0300 Subject: [PATCH 07/10] fix warning shown when KOIN_USE_COMPOSE_VIEWMODEL arg is used --- .../kotlin/org/koin/compiler/BuilderProcessor.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/BuilderProcessor.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/BuilderProcessor.kt index 95c2223..11c0eb9 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/BuilderProcessor.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/BuilderProcessor.kt @@ -82,13 +82,16 @@ class BuilderProcessor( //TODO Use Koin 4.0 ViewModel DSL @Deprecated("use isKoinComposeViewModelActive") private fun isComposeViewModelActive(): Boolean { - logger.warn("[Deprecated] 'USE_COMPOSE_VIEWMODEL' arg is deprecated. Please use 'KOIN_USE_COMPOSE_VIEWMODEL'") - return options.getOrDefault(USE_COMPOSE_VIEWMODEL.name, "false") == true.toString() + val option = options.getOrDefault(USE_COMPOSE_VIEWMODEL.name, "false") == true.toString() + if (option) logger.warn("[Deprecated] 'USE_COMPOSE_VIEWMODEL' arg is deprecated. Please use 'KOIN_USE_COMPOSE_VIEWMODEL'") + return option } private fun isKoinComposeViewModelActive(): Boolean { - logger.warn("Activate Compose ViewModel for @KoinViewModel generation") - return options.getOrDefault(KOIN_USE_COMPOSE_VIEWMODEL.name, "false") == true.toString() + val option = + options.getOrDefault(KOIN_USE_COMPOSE_VIEWMODEL.name, "false") == true.toString() + if (option) logger.warn("Activate Compose ViewModel for @KoinViewModel generation") + return option } //TODO turn KOIN_DEFAULT_MODULE to false by default - Next Major version (breaking) From 3a966bdcc625d39376163407899a3b40b8cb4d29 Mon Sep 17 00:00:00 2001 From: Arnaud Giuliani Date: Tue, 15 Oct 2024 16:52:01 +0200 Subject: [PATCH 08/10] bump version 1.4.0 --- examples/gradle/libs.versions.toml | 2 +- projects/gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gradle/libs.versions.toml b/examples/gradle/libs.versions.toml index b0375b4..90beffd 100644 --- a/examples/gradle/libs.versions.toml +++ b/examples/gradle/libs.versions.toml @@ -5,7 +5,7 @@ # Core kotlin = "1.9.24" koin = "3.5.6" -koinAnnotations = "1.4.0-RC4" +koinAnnotations = "1.4.0" ksp = "1.9.24-1.0.20" junit = "4.13.2" # Android diff --git a/projects/gradle.properties b/projects/gradle.properties index 85b6a64..22ff7e0 100644 --- a/projects/gradle.properties +++ b/projects/gradle.properties @@ -7,7 +7,7 @@ org.gradle.parallel=true #Kotlin kotlin.code.style=official #Koin -koinAnnotationsVersion=1.4.0-RC4 +koinAnnotationsVersion=1.4.0 #Android android.useAndroidX=true androidMinSDK=14 From f4a19b920e5af1e971225e6a63b06bdcf77337da Mon Sep 17 00:00:00 2001 From: Arnaud Giuliani Date: Tue, 15 Oct 2024 17:25:50 +0200 Subject: [PATCH 09/10] white list ViewModel type --- .../jvmMain/kotlin/org/koin/compiler/verify/KoinTagWriter.kt | 2 +- .../jvmMain/kotlin/org/koin/compiler/verify/TypeWhiteList.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/KoinTagWriter.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/KoinTagWriter.kt index 0d6e2e2..ca050e2 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/KoinTagWriter.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/KoinTagWriter.kt @@ -119,7 +119,7 @@ class KoinTagWriter(val codeGenerator: CodeGenerator, val logger: KSPLogger) { fileStream: OutputStream, alreadyDeclared: java.util.ArrayList ) { - LOGGER.logging("tag: $tagName") +// LOGGER.logging("tag: $tagName") val tag = "public class $tagPrefix$tagName" fileStream.appendText("\n$tag") alreadyDeclared.add(tagName) diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/TypeWhiteList.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/TypeWhiteList.kt index b1842c0..903265b 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/TypeWhiteList.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/TypeWhiteList.kt @@ -8,5 +8,6 @@ internal val typeWhiteList = listOf( "androidx.appcompat.app.AppCompatActivity", "androidx.appcompat.app.AppCompatActivity", "androidx.fragment.app.Fragment", - "androidx.lifecycle.SavedStateHandle" + "androidx.lifecycle.SavedStateHandle", + "androidx.lifecycle.ViewModel" ) \ No newline at end of file From 2ae4175e91fb5b7c37e7d0c89f8b6294f09fca06 Mon Sep 17 00:00:00 2001 From: Arnaud Giuliani Date: Tue, 15 Oct 2024 17:35:29 +0200 Subject: [PATCH 10/10] add sample for it package --- .../src/test/java/AndroidModuleTest.kt | 4 ++++ .../src/main/java/it/example/component/Example.kt | 12 ++++++++++++ .../org/koin/sample/android/library/CommonModule.kt | 3 ++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 examples/android-library/src/main/java/it/example/component/Example.kt diff --git a/examples/android-coffee-maker/src/test/java/AndroidModuleTest.kt b/examples/android-coffee-maker/src/test/java/AndroidModuleTest.kt index 37b08e0..4ffa8a8 100644 --- a/examples/android-coffee-maker/src/test/java/AndroidModuleTest.kt +++ b/examples/android-coffee-maker/src/test/java/AndroidModuleTest.kt @@ -1,5 +1,6 @@ package org.koin.sample.androidx +import it.example.component.ExampleSingleton import org.junit.Test import org.koin.core.context.startKoin import org.koin.core.context.stopKoin @@ -38,6 +39,9 @@ class AndroidModuleTest { assert(koin.getOrNull() != null) assert(koin.getOrNull() != null) + assert(koin.getOrNull() != null) + + stopKoin() } } \ No newline at end of file diff --git a/examples/android-library/src/main/java/it/example/component/Example.kt b/examples/android-library/src/main/java/it/example/component/Example.kt new file mode 100644 index 0000000..61c6070 --- /dev/null +++ b/examples/android-library/src/main/java/it/example/component/Example.kt @@ -0,0 +1,12 @@ +package it.example.component + +import org.koin.core.annotation.ComponentScan +import org.koin.core.annotation.Module +import org.koin.core.annotation.Single + +@Module +@ComponentScan +class ExampleModule + +@Single +class ExampleSingleton \ No newline at end of file diff --git a/examples/android-library/src/main/java/org/koin/sample/android/library/CommonModule.kt b/examples/android-library/src/main/java/org/koin/sample/android/library/CommonModule.kt index dd4884d..87cc1a8 100644 --- a/examples/android-library/src/main/java/org/koin/sample/android/library/CommonModule.kt +++ b/examples/android-library/src/main/java/org/koin/sample/android/library/CommonModule.kt @@ -1,8 +1,9 @@ package org.koin.sample.android.library +import it.example.component.ExampleModule import org.koin.core.annotation.ComponentScan import org.koin.core.annotation.Module -@Module +@Module(includes = [ExampleModule::class]) @ComponentScan class CommonModule \ No newline at end of file