Skip to content

Commit

Permalink
Androidx Room Support (#16)
Browse files Browse the repository at this point in the history
- Added Androidx Room integration for mobile and desktop targets.
- Slightly updated CacheSource API.
- Cleaned up some dependencies from versions catalog to have only what is included.
  • Loading branch information
kotlitecture committed Jul 13, 2024
1 parent dc1584f commit 41578b3
Show file tree
Hide file tree
Showing 85 changed files with 1,076 additions and 117 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
kotli = "0.5.2"
kotli = "0.5.3"
kotlin = "1.9.23"
kotlinxCoroutines = "1.8.0"
logback = "1.5.6"
Expand Down
2 changes: 1 addition & 1 deletion processor/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apply from: "${project.rootDir}/gradle/kotlin/processor.gradle"

group = 'com.kotlitecture.kotli'
version = '0.5.2'
version = '0.6.0'
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,13 @@ object MultiplatformComposeTemplateProcessor : BaseTemplateProcessor() {
)
renamePackage(state, "${Rules.CommonAppSrcDir}/androidMain/kotlin")
renamePackage(state, "${Rules.CommonAppSrcDir}/commonMain/kotlin")
renamePackage(state, "${Rules.CommonAppSrcDir}/iosArm64Main/kotlin")
renamePackage(state, "${Rules.CommonAppSrcDir}/iosMain/kotlin")
renamePackage(state, "${Rules.CommonAppSrcDir}/iosSimulatorArm64Main/kotlin")
renamePackage(state, "${Rules.CommonAppSrcDir}/iosX64Main/kotlin")
renamePackage(state, "${Rules.CommonAppSrcDir}/jsMain/kotlin")
renamePackage(state, "${Rules.CommonAppSrcDir}/jvmMain/kotlin")
renamePackage(state, "${Rules.CommonAppSrcDir}/mobileAndDesktopMain/kotlin")
}

private fun renamePackage(state: TemplateState, root: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object Rules {
// sources
const val IosAppDir = "iosApp"
const val SrcAndroidMainDir = "*/src/androidMain"
const val SrcIosMainDir = "*/src/iosMain"
const val SrcIosMainDir = "*/src/ios*"
const val SrcJsMainDir = "*/src/jsMain"
const val SrcJvmMainDir = "*/src/jvmMain"
const val SharedPresentationDir = "shared/presentation"
Expand All @@ -33,12 +33,12 @@ object Rules {
const val BackendDir = "backend"

// kotlin
const val DIKt = "*/DI*.kt"
const val CommonAppSrcDir = "app/src"
const val SharedDesignSrcDir = "shared/design/src"
const val CommonAppMainDir = "${CommonAppSrcDir}/commonMain"
const val AppIconsProviderKt = "${SharedDesignSrcDir}/commonMain/kotlin/shared/design/icon/AppIconsProvider.kt"
const val AppModuleKt = "${CommonAppMainDir}/kotlin/kotli/app/di/presentation/AppModule.kt"
const val AppDIKt = "${CommonAppMainDir}/kotlin/kotli/app/di/DI.kt"
const val AppWebPackConfigDir = "app/webpack.config.d"
const val AppSqlDelightConfigJs = "${AppWebPackConfigDir}/sqljs-config.js"
const val AppPresentationDir = "${CommonAppMainDir}/kotlin/kotli/app/presentation"
Expand All @@ -60,14 +60,15 @@ object Rules {
const val AppNavigationModalProvider = "${AppNavigationDir}/ModalProvider.kt"
const val AppNavigationPermanentProvider = "${AppNavigationDir}/PermanentProvider.kt"
const val AppNavigationRailProvider = "${AppNavigationDir}/RailProvider.kt"
const val ShowcasesDir = "${AppPresentationDir}/showcases"
const val ShowcasesDir = "*/presentation/showcases"
const val ShowcasesDataFlowDir = "${ShowcasesDir}/dataflow"
const val ShowcasesUserFlowDir = "${ShowcasesDir}/userflow"
const val ShowcasesHttpDir = "${ShowcasesDataFlowDir}/http"
const val ShowcasesCacheDir = "${ShowcasesDataFlowDir}/cache"
const val ShowcasesPagingDir = "${ShowcasesDataFlowDir}/paging"
const val ShowcasesKeyValueDir = "${ShowcasesDataFlowDir}/keyvalue"
const val ShowcasesSqlDelightDir = "${ShowcasesDataFlowDir}/sqldelight"
const val ShowcasesRoomDir = "${ShowcasesDataFlowDir}/room"
const val ShowcasesNavigationDir = "${ShowcasesUserFlowDir}/navigation"
const val ShowcasesThemeDir = "${ShowcasesUserFlowDir}/theme"
const val ShowcasesLoaderDir = "${ShowcasesUserFlowDir}/loader"
Expand All @@ -82,11 +83,13 @@ object Rules {
const val AnalyticsSource = "*/*AnalyticsSource*.kt"
const val CacheSource = "*/*CacheSource*.kt"
const val SqlDelightSource = "*/*SqlDelightSource*.kt"
const val SqlDelightDir = "*/sqldelight/*"
const val RoomSource = "*/*RoomSource*.kt"
const val RoomDir = "*/database/room/*"
const val ConfigSource = "*/*ConfigSource*.kt"
const val PagingSource = "*/*Paging*.kt"
const val HttpSource = "*/*HttpSource*.kt"
const val KeyValueSource = "*/*KeyValueSource*.kt"
const val SettingsKeyValueSource = "*/*SettingsKeyValueSource*.kt"
const val AppSqlDelightDir = "*/sqldelight/*"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package kotli.template.multiplatform.compose.common

import kotli.engine.BaseFeatureProcessor
import kotli.engine.TemplateState
import kotli.engine.template.VersionCatalogRules
import kotli.engine.template.rule.CleanupMarkedBlock
import kotli.engine.template.rule.CleanupMarkedLine
import kotli.engine.template.rule.RemoveMarkedBlock
import kotli.engine.template.rule.RemoveMarkedLine
import kotli.template.multiplatform.compose.Rules

object CommonKspProcessor : BaseFeatureProcessor() {

override fun getId(): String = "common.ksp"
override fun isInternal(): Boolean = true

override fun doApply(state: TemplateState) {
state.onApplyRules(
Rules.BuildGradleApp,
CleanupMarkedLine("{common.ksp}"),
CleanupMarkedBlock("{common.ksp.config}")
)
}

override fun doRemove(state: TemplateState) {
state.onApplyRules(
VersionCatalogRules(
RemoveMarkedLine("ksp")
)
)
state.onApplyRules(
Rules.BuildGradleApp,
RemoveMarkedLine("{common.ksp}"),
RemoveMarkedBlock("{common.ksp.config}")
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ object CommonProvider : BaseFeatureProvider() {
override fun getId(): String = "common"
override fun createProcessors(): List<FeatureProcessor> = listOf(
CommonKtorProcessor,
CommonStatelyProcessor
CommonStatelyProcessor,
CommonKspProcessor
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object FacadeAnalyticsProcessor : BaseFeatureProcessor() {
RemoveFile()
)
state.onApplyRules(
Rules.AppDIKt,
Rules.DIKt,
RemoveMarkedLine("AnalyticsSource")
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotli.engine.template.rule.RemoveMarkedLine
import kotli.template.multiplatform.compose.Rules
import kotli.template.multiplatform.compose.Tags
import kotli.template.multiplatform.compose.common.CommonStatelyProcessor
import kotli.template.multiplatform.compose.showcases.datasource.cache.CacheShowcasesProcessor
import kotli.template.multiplatform.compose.showcases.dataflow.cache.CacheShowcasesProcessor
import kotlin.time.Duration.Companion.hours

object BasicCacheProcessor : BaseFeatureProcessor() {
Expand Down Expand Up @@ -39,7 +39,7 @@ object BasicCacheProcessor : BaseFeatureProcessor() {
RemoveFile()
)
state.onApplyRules(
Rules.AppDIKt,
Rules.DIKt,
RemoveMarkedLine("CacheSource")
)
state.onApplyRules(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kotli.template.multiplatform.compose.dataflow.common

import kotli.engine.BaseFeatureProcessor
import kotli.engine.TemplateState
import kotli.engine.template.VersionCatalogRules
import kotli.engine.template.rule.RemoveFile
import kotli.engine.template.rule.RemoveMarkedLine
import kotli.template.multiplatform.compose.Rules
Expand All @@ -26,6 +27,11 @@ object CommonDataFlowProcessor : BaseFeatureProcessor() {
Rules.BuildGradle,
RemoveMarkedLine("shared.data")
)
state.onApplyRules(
VersionCatalogRules(
RemoveMarkedLine("kotlin-test =")
)
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object FacadeConfigProcessor : BaseFeatureProcessor() {
RemoveFile()
)
state.onApplyRules(
Rules.AppDIKt,
Rules.DIKt,
RemoveMarkedLine("ConfigSource")
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kotli.template.multiplatform.compose.dataflow.database

import kotli.engine.FeatureProcessor
import kotli.template.multiplatform.compose.dataflow.BaseDataFlowProvider
import kotli.template.multiplatform.compose.dataflow.database.room.RoomProcessor
import kotli.template.multiplatform.compose.dataflow.database.sqldelight.SqlDelightProcessor

object DatabaseProvider : BaseDataFlowProvider() {
Expand All @@ -10,7 +11,10 @@ object DatabaseProvider : BaseDataFlowProvider() {
override fun isMultiple(): Boolean = false

override fun createProcessors(): List<FeatureProcessor> = listOf(
SqlDelightProcessor
SqlDelightProcessor,
RoomProcessor,
SqliteProcessor,
SqliteLinkerProcessor
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package kotli.template.multiplatform.compose.dataflow.database

import kotli.engine.BaseFeatureProcessor
import kotli.engine.TemplateState
import kotli.engine.template.rule.CleanupMarkedLine
import kotli.engine.template.rule.RemoveMarkedLine
import kotli.template.multiplatform.compose.Rules

object SqliteLinkerProcessor : BaseFeatureProcessor() {

const val ID = "dataflow.database.sqlite-linker"
override fun isInternal(): Boolean = true

override fun getId(): String = ID

override fun doApply(state: TemplateState) {
state.onApplyRules(
Rules.BuildGradleApp,
CleanupMarkedLine("{dataflow.database.sqlite-linker}")
)
}

override fun doRemove(state: TemplateState) {
state.onApplyRules(
Rules.BuildGradleApp,
RemoveMarkedLine("{dataflow.database.sqlite-linker}")
)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package kotli.template.multiplatform.compose.dataflow.database

import kotli.engine.BaseFeatureProcessor
import kotli.engine.FeatureProcessor
import kotli.engine.TemplateState
import kotli.engine.template.VersionCatalogRules
import kotli.engine.template.rule.CleanupMarkedLine
import kotli.engine.template.rule.RemoveMarkedLine
import kotli.template.multiplatform.compose.Rules

object SqliteProcessor : BaseFeatureProcessor() {

const val ID = "dataflow.database.sqlite"
override fun isInternal(): Boolean = true
override fun dependencies(): List<Class<out FeatureProcessor>> = listOf(
SqliteLinkerProcessor::class.java
)

override fun getId(): String = ID

override fun doApply(state: TemplateState) {
state.onApplyRules(
Rules.BuildGradleApp,
CleanupMarkedLine("{dataflow.database.sqlite}")
)
}

override fun doRemove(state: TemplateState) {
state.onApplyRules(
Rules.BuildGradleApp,
RemoveMarkedLine("{dataflow.database.sqlite}")
)
state.onApplyRules(
VersionCatalogRules(
RemoveMarkedLine("sqlite-bundled")
)
)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package kotli.template.multiplatform.compose.dataflow.database.room

import kotli.engine.BaseFeatureProcessor
import kotli.engine.FeatureProcessor
import kotli.engine.FeatureTag
import kotli.engine.TemplateState
import kotli.engine.template.VersionCatalogRules
import kotli.engine.template.rule.CleanupMarkedBlock
import kotli.engine.template.rule.CleanupMarkedLine
import kotli.engine.template.rule.RemoveFile
import kotli.engine.template.rule.RemoveMarkedBlock
import kotli.engine.template.rule.RemoveMarkedLine
import kotli.template.multiplatform.compose.Rules
import kotli.template.multiplatform.compose.Tags
import kotli.template.multiplatform.compose.common.CommonKspProcessor
import kotli.template.multiplatform.compose.dataflow.database.SqliteProcessor
import kotli.template.multiplatform.compose.platform.client.MobileAndDesktopProcessor
import kotli.template.multiplatform.compose.platform.client.android.AndroidPlatformProcessor
import kotli.template.multiplatform.compose.platform.client.ios.IOSPlatformProcessor
import kotli.template.multiplatform.compose.platform.client.jvm.JvmPlatformProcessor
import kotlin.time.Duration.Companion.hours

object RoomProcessor : BaseFeatureProcessor() {

const val ID = "dataflow.database.room"

override fun getId(): String = ID
override fun getTags(): List<FeatureTag> = Tags.MobileAndDesktop
override fun getIntegrationEstimate(state: TemplateState): Long = 4.hours.inWholeMilliseconds
override fun getWebUrl(state: TemplateState): String =
"https://developer.android.com/kotlin/multiplatform/room"

override fun getIntegrationUrl(state: TemplateState): String =
"https://developer.android.com/kotlin/multiplatform/room#defining-database"

override fun canApply(state: TemplateState): Boolean {
return listOfNotNull(
state.getFeature(AndroidPlatformProcessor.ID),
state.getFeature(IOSPlatformProcessor.ID),
state.getFeature(JvmPlatformProcessor.ID)
).isNotEmpty()
}

override fun dependencies(): List<Class<out FeatureProcessor>> = listOf(
MobileAndDesktopProcessor::class.java,
CommonKspProcessor::class.java,
SqliteProcessor::class.java,
)

override fun doApply(state: TemplateState) {
state.onApplyRules(
Rules.BuildGradleApp,
CleanupMarkedBlock("{dataflow.database.room.config}"),
CleanupMarkedLine("{dataflow.database.room}")
)
}

override fun doRemove(state: TemplateState) {
state.onApplyRules(
Rules.BuildGradleApp,
RemoveMarkedBlock("{dataflow.database.room.config}"),
RemoveMarkedLine("{dataflow.database.room}")
)
state.onApplyRules(
VersionCatalogRules(
RemoveMarkedLine("androidx-room")
)
)
state.onApplyRules(
Rules.RoomSource,
RemoveFile()
)
state.onApplyRules(
Rules.RoomDir,
RemoveFile()
)
state.onApplyRules(
"app/schemas",
RemoveFile()
)
state.onApplyRules(
Rules.DIKt,
RemoveMarkedLine("RoomSource")
)

// showcases
state.onApplyRules(
Rules.ShowcasesKt,
RemoveMarkedLine("Room")
)
state.onApplyRules(
Rules.ShowcasesRoomDir,
RemoveFile()
)
state.onApplyRules(
Rules.AppModuleKt,
RemoveMarkedLine("createRoom")
)
}

}
Loading

0 comments on commit 41578b3

Please sign in to comment.