From e614fa93434fe31ab39c0222fd51c6e31be96ffd Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 16 Oct 2023 16:49:40 +0200 Subject: [PATCH] database -> kts --- buildSrc/src/main/kotlin/Libs.kt | 13 ++++- .../kotlin/all-open-dependencies.gradle.kts | 1 - database/entities/build.gradle | 36 ------------- database/entities/build.gradle.kts | 25 +++++++++ database/impl/build.gradle | 52 ------------------- database/impl/build.gradle.kts | 50 ++++++++++++++++++ .../database/annotations/DbOpenForTesting.kt | 15 ------ .../app/aaps/database/impl/AppRepository.kt | 7 +-- .../database/annotations/DbOpenForTesting.kt | 8 --- 9 files changed, 90 insertions(+), 117 deletions(-) delete mode 100644 database/entities/build.gradle create mode 100644 database/entities/build.gradle.kts delete mode 100644 database/impl/build.gradle create mode 100644 database/impl/build.gradle.kts delete mode 100644 database/impl/src/debug/kotlin/app/aaps/database/annotations/DbOpenForTesting.kt delete mode 100644 database/impl/src/release/kotlin/app/aaps/database/annotations/DbOpenForTesting.kt diff --git a/buildSrc/src/main/kotlin/Libs.kt b/buildSrc/src/main/kotlin/Libs.kt index f975fa505d..2f1a0b33d3 100644 --- a/buildSrc/src/main/kotlin/Libs.kt +++ b/buildSrc/src/main/kotlin/Libs.kt @@ -7,6 +7,7 @@ object Libs { const val stdlibJdk8 = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin" const val test = "org.jetbrains.kotlin:kotlin-test:$kotlin" + const val reflect = "org.jetbrains.kotlin:kotlin-reflect:$kotlin" } object KotlinX { @@ -39,6 +40,15 @@ object Libs { const val uiAutomator = "androidx.test.uiautomator:uiautomator:2.2.0" } + object Room { + private const val roomVersion = "2.5.2" + + const val room = "androidx.room:room-ktx:$roomVersion" + const val compiler = "androidx.room:room-compiler:$roomVersion" + const val runtime = "androidx.room:room-runtime:$roomVersion" + const val rxJava3 = "androidx.room:room-rxjava3:$roomVersion" + const val testing = "androidx.room:room-testing:$roomVersion" + } object Wear { const val wear = "androidx.wear:wear:1.3.0" @@ -63,6 +73,7 @@ object Libs { } const val truth = "com.google.truth:truth:1.1.5" + const val gson = "com.google.code.gson:gson:2.10.1" } object Dagger { @@ -113,13 +124,11 @@ object Libs { const val json = "org.json:json:20230618" const val jsonAssert = "org.skyscreamer:jsonassert:1.5.0" - const val room = "2.5.2" const val lifecycle = "2.6.2" const val coroutines = "1.7.3" const val activity = "1.8.0" const val fragmentktx = "1.6.1" const val ormLite = "4.46" - const val gson = "2.10.1" const val nav = "2.7.4" const val material = "1.10.0" const val gridlayout = "1.0.0" diff --git a/buildSrc/src/main/kotlin/all-open-dependencies.gradle.kts b/buildSrc/src/main/kotlin/all-open-dependencies.gradle.kts index 756dbced71..6041077214 100644 --- a/buildSrc/src/main/kotlin/all-open-dependencies.gradle.kts +++ b/buildSrc/src/main/kotlin/all-open-dependencies.gradle.kts @@ -1,4 +1,3 @@ - plugins { id("com.android.library") id("kotlin-android") diff --git a/database/entities/build.gradle b/database/entities/build.gradle deleted file mode 100644 index eb9e59ed72..0000000000 --- a/database/entities/build.gradle +++ /dev/null @@ -1,36 +0,0 @@ -plugins { - id 'com.android.library' - id 'kotlin-android' - id 'kotlin-kapt' - id 'kotlin-allopen' -} - -apply from: "${project.rootDir}/core/main/android_module_dependencies.gradle" -apply from: "${project.rootDir}/core/main/test_dependencies.gradle" - -android { - - namespace 'app.aaps.database.entities' - defaultConfig { - minSdkVersion 26 // for wear - } - - buildFeatures { - buildConfig = false - } -} - -dependencies { - api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - - api "androidx.core:core-ktx:$core_version" - - kapt "androidx.room:room-compiler:$room_version" - api "androidx.room:room-ktx:$room_version" - -} - -allOpen { - // allows mocking for classes w/o directly opening them for release builds - annotation 'app.aaps.database.annotations.DbOpenForTesting' -} diff --git a/database/entities/build.gradle.kts b/database/entities/build.gradle.kts new file mode 100644 index 0000000000..3831333d35 --- /dev/null +++ b/database/entities/build.gradle.kts @@ -0,0 +1,25 @@ +plugins { + id("com.android.library") + id("kotlin-android") + id("kotlin-kapt") + id("kotlin-allopen") + id("android-module-dependencies") + id("all-open-dependencies") + id("test-dependencies") +} + +android { + + namespace = "app.aaps.database.entities" + defaultConfig { + minSdk = Versions.wearMinSdk // for wear + } +} + +dependencies { + api(Libs.Kotlin.stdlibJdk8) + api(Libs.AndroidX.core) + api(Libs.AndroidX.Room.room) + + kapt(Libs.AndroidX.Room.compiler) +} \ No newline at end of file diff --git a/database/impl/build.gradle b/database/impl/build.gradle deleted file mode 100644 index 5c830ec3c4..0000000000 --- a/database/impl/build.gradle +++ /dev/null @@ -1,52 +0,0 @@ -plugins { - id 'com.android.library' - id 'kotlin-android' - id 'kotlin-kapt' - id 'kotlin-allopen' -} - -apply from: "${project.rootDir}/core/main/android_module_dependencies.gradle" -apply from: "${project.rootDir}/core/main/test_dependencies.gradle" -apply from: "${project.rootDir}/core/main/jacoco_global.gradle" - -android { - namespace 'app.aaps.database.impl' - - defaultConfig { - kapt { - arguments { - arg("room.incremental", "true") - arg("room.schemaLocation", "$projectDir/schemas") - } - } - } - sourceSets { - androidTest.assets.srcDirs += files("$projectDir/schemas") - } -} - -dependencies { - implementation project(':database:entities') - - api "androidx.core:core-ktx:$core_version" - api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - api "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" - - api "io.reactivex.rxjava3:rxjava:$rxjava_version" - api "io.reactivex.rxjava3:rxandroid:$rxandroid_version" - api "io.reactivex.rxjava3:rxkotlin:$rxkotlin_version" - - api "com.google.code.gson:gson:$gson_version" - - api "androidx.room:room-runtime:$room_version" - kapt "androidx.room:room-compiler:$room_version" - /* Database schema export */ - kapt "androidx.room:room-compiler:$room_version" - api "androidx.room:room-ktx:$room_version" - api "androidx.room:room-rxjava3:$room_version" - - api "com.google.dagger:dagger-android:$dagger_version" - api "com.google.dagger:dagger-android-support:$dagger_version" - - androidTestImplementation "androidx.room:room-testing:$room_version" -} \ No newline at end of file diff --git a/database/impl/build.gradle.kts b/database/impl/build.gradle.kts new file mode 100644 index 0000000000..08daa20c40 --- /dev/null +++ b/database/impl/build.gradle.kts @@ -0,0 +1,50 @@ +plugins { + id("com.android.library") + id("kotlin-android") + id("kotlin-kapt") + id("kotlin-allopen") + id("android-module-dependencies") + id("test-dependencies") +} + +apply(from = "${project.rootDir}/core/main/jacoco_global.gradle") + +android { + namespace = "app.aaps.database.impl" + + defaultConfig { + kapt { + arguments { + arg("room.incremental", "true") + arg("room.schemaLocation", "$projectDir/schemas") + } + } + } + sourceSets { + getByName("androidTest").assets.srcDirs("$projectDir/schemas") + } +} + +dependencies { + implementation(project(":database:entities")) + + api(Libs.Kotlin.stdlibJdk8) + api(Libs.Kotlin.reflect) + api(Libs.AndroidX.core) + + api(Libs.Rx.rxJava) + api(Libs.Rx.rxAndroid) + api(Libs.Rx.rxKotlin) + + api(Libs.Google.gson) + + api(Libs.AndroidX.Room.room) + api(Libs.AndroidX.Room.runtime) + api(Libs.AndroidX.Room.rxJava3) + kapt(Libs.AndroidX.Room.compiler) + + api(Libs.Dagger.android) + api(Libs.Dagger.androidSupport) + + androidTestImplementation(Libs.AndroidX.Room.testing) +} \ No newline at end of file diff --git a/database/impl/src/debug/kotlin/app/aaps/database/annotations/DbOpenForTesting.kt b/database/impl/src/debug/kotlin/app/aaps/database/annotations/DbOpenForTesting.kt deleted file mode 100644 index 4d71733d52..0000000000 --- a/database/impl/src/debug/kotlin/app/aaps/database/annotations/DbOpenForTesting.kt +++ /dev/null @@ -1,15 +0,0 @@ -package app.aaps.database.annotations - -/** - * This is the actual annotation that makes the class open. Don't use it directly, only through [DbOpenForTesting] - * which has a NOOP replacement in production. - */ -@Target(AnnotationTarget.ANNOTATION_CLASS) -annotation class DbOpenClass - -/** - * Annotate a class with [DbOpenForTesting] if it should be extendable for testing. - */ -@DbOpenClass -@Target(AnnotationTarget.CLASS) -annotation class DbOpenForTesting \ No newline at end of file diff --git a/database/impl/src/main/java/app/aaps/database/impl/AppRepository.kt b/database/impl/src/main/java/app/aaps/database/impl/AppRepository.kt index 7cccd799e3..b7a546f229 100644 --- a/database/impl/src/main/java/app/aaps/database/impl/AppRepository.kt +++ b/database/impl/src/main/java/app/aaps/database/impl/AppRepository.kt @@ -1,7 +1,7 @@ package app.aaps.database.impl +import androidx.annotation.OpenForTesting import app.aaps.database.ValueWrapper -import app.aaps.database.annotations.DbOpenForTesting import app.aaps.database.entities.Bolus import app.aaps.database.entities.BolusCalculatorResult import app.aaps.database.entities.Carbs @@ -34,8 +34,9 @@ import javax.inject.Inject import javax.inject.Singleton import kotlin.math.roundToInt -@DbOpenForTesting -@Singleton class AppRepository @Inject internal constructor( +@OpenForTesting +@Singleton +class AppRepository @Inject internal constructor( internal val database: AppDatabase ) { diff --git a/database/impl/src/release/kotlin/app/aaps/database/annotations/DbOpenForTesting.kt b/database/impl/src/release/kotlin/app/aaps/database/annotations/DbOpenForTesting.kt deleted file mode 100644 index f00a7a2ff0..0000000000 --- a/database/impl/src/release/kotlin/app/aaps/database/annotations/DbOpenForTesting.kt +++ /dev/null @@ -1,8 +0,0 @@ -package app.aaps.database.annotations - -/** - * Annotate a class with [DbOpenForTesting] if it should be extendable for testing. - * In production the class remains final. - */ -@Target(AnnotationTarget.CLASS) -annotation class DbOpenForTesting \ No newline at end of file