Skip to content

Commit

Permalink
always write tags
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgiuliani committed Aug 13, 2024
1 parent 4cf934e commit 4844d9e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BuilderProcessor(
private val koinCodeGenerator = KoinGenerator(codeGenerator, logger, isComposeViewModelActive() || isKoinComposeViewModelActive())
private val koinMetaDataScanner = KoinMetaDataScanner(logger)
private val koinTagWriter = KoinTagWriter(codeGenerator,logger)
private val koinConfigChecker = KoinConfigChecker(codeGenerator, logger, koinTagWriter)
private val koinConfigChecker = KoinConfigChecker(codeGenerator, logger)

override fun process(resolver: Resolver): List<KSAnnotated> {
logger.logging("Scan symbols ...")
Expand All @@ -56,10 +56,13 @@ class BuilderProcessor(
logger.logging("Generate code ...")
koinCodeGenerator.generateModules(moduleList, defaultModule, isDefaultModuleActive())

val allModules = moduleList + defaultModule
koinTagWriter.writeAllTags(allModules)

if (isConfigCheckActive()) {
logger.warn("Koin Configuration Check")
koinConfigChecker.verifyDefinitionDeclarations(moduleList + defaultModule, resolver)
koinConfigChecker.verifyModuleIncludes(moduleList + defaultModule, resolver)
koinConfigChecker.verifyDefinitionDeclarations(allModules, resolver)
koinConfigChecker.verifyModuleIncludes(allModules, resolver)
}
return emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const val codeGenerationPackage = "org.koin.ksp.generated"
/**
* Koin Configuration Checker
*/
class KoinConfigChecker(val codeGenerator: CodeGenerator, val logger: KSPLogger, val koinTagWriter: KoinTagWriter) {
class KoinConfigChecker(val codeGenerator: CodeGenerator, val logger: KSPLogger) {

fun verifyDefinitionDeclarations(
moduleList: List<KoinMetaData.Module>,
Expand All @@ -35,9 +35,7 @@ class KoinConfigChecker(val codeGenerator: CodeGenerator, val logger: KSPLogger,
val isAlreadyGenerated = codeGenerator.generatedFile.isEmpty()
val allDefinitions = moduleList.flatMap { it.definitions }

if (!isAlreadyGenerated) {
koinTagWriter.writeTags(allDefinitions)
} else {
if (isAlreadyGenerated) {
verifyTags(allDefinitions, resolver)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@ const val tagPrefix = "KoinDef"

class KoinTagWriter(val codeGenerator: CodeGenerator, val logger: KSPLogger) {

fun writeTags(allDefinitions: List<KoinMetaData.Definition>) {
fun writeAllTags(
moduleList: List<KoinMetaData.Module>
) {

val isAlreadyGenerated = codeGenerator.generatedFile.isEmpty()
val allDefinitions = moduleList.flatMap { it.definitions }

if (!isAlreadyGenerated) {
logger.warn("Koin Tags Generation ...")
writeTags(allDefinitions)
}
}

private fun writeTags(allDefinitions: List<KoinMetaData.Definition>) {
val alreadyDeclaredTags = arrayListOf<String>()
val tagFileName = "KoinMeta-${hashCode()}"
val tagFileStream = writeTagFile(tagFileName)
Expand Down

0 comments on commit 4844d9e

Please sign in to comment.