From 9ce98747d696f113ca6d81d0ea87cc9c2ec7c3c2 Mon Sep 17 00:00:00 2001 From: Ash Davies <1892070+ashdavies@users.noreply.github.com> Date: Mon, 9 Dec 2024 15:46:58 +0100 Subject: [PATCH] Make properties null-by-default (#1378) * Make properties null-by-default * Resolve value before property get * Restore property to boolean --------- Co-authored-by: Ashley Davies --- app-check/app-check-sdk/build.gradle.kts | 19 +++----------- app-launcher/android/build.gradle.kts | 9 ++----- app-launcher/desktop/build.gradle.kts | 4 +-- cloud-run/build.gradle.kts | 14 +++------- conferences-app/build.gradle.kts | 26 +++++++++---------- .../src/main/kotlin/StringProperty.kt | 20 +++----------- identity-manager/build.gradle.kts | 4 +-- map-routes/build.gradle.kts | 8 +++--- 8 files changed, 31 insertions(+), 73 deletions(-) diff --git a/app-check/app-check-sdk/build.gradle.kts b/app-check/app-check-sdk/build.gradle.kts index e5ded4031..722c75110 100644 --- a/app-check/app-check-sdk/build.gradle.kts +++ b/app-check/app-check-sdk/build.gradle.kts @@ -6,21 +6,10 @@ plugins { } buildConfig { - val firebaseAndroidAppId by stringPropertyOrNull { value -> - buildConfigField("FIREBASE_ANDROID_APP_ID", value) - } - - val gcloudProject by stringPropertyOrNull { value -> - buildConfigField("GCLOUD_PROJECT", value) - } - - val gcpProject by stringPropertyOrNull { value -> - buildConfigField("GCP_PROJECT", value) - } - - val googleCloudProject by stringPropertyOrNull { value -> - buildConfigField("GOOGLE_CLOUD_PROJECT", value) - } + val firebaseAndroidAppId by stringProperty(::buildConfigField) + val gcloudProject by stringProperty(::buildConfigField) + val gcpProject by stringProperty(::buildConfigField) + val googleCloudProject by stringProperty(::buildConfigField) packageName.set("io.ashdavies.check") } diff --git a/app-launcher/android/build.gradle.kts b/app-launcher/android/build.gradle.kts index fc7f0443d..e624ad2dc 100644 --- a/app-launcher/android/build.gradle.kts +++ b/app-launcher/android/build.gradle.kts @@ -23,13 +23,8 @@ android { } buildConfig { - val androidApiKey by stringProperty { value -> - buildConfigField("ANDROID_API_KEY", value) - } - - val androidStrictMode by booleanProperty { value -> - buildConfigField("ANDROID_STRICT_MODE", value) - } + val androidApiKey by stringProperty(::buildConfigField) + val androidStrictMode by booleanProperty(::buildConfigField) packageName.set(android.namespace) } diff --git a/app-launcher/desktop/build.gradle.kts b/app-launcher/desktop/build.gradle.kts index 386715140..0db3efd36 100644 --- a/app-launcher/desktop/build.gradle.kts +++ b/app-launcher/desktop/build.gradle.kts @@ -9,9 +9,7 @@ plugins { } buildConfig { - val browserApiKey by stringProperty { value -> - buildConfigField("BROWSER_API_KEY", value) - } + val browserApiKey by stringProperty(::buildConfigField) packageName.set("io.ashdavies.playground") } diff --git a/cloud-run/build.gradle.kts b/cloud-run/build.gradle.kts index 6eabc30a0..a8371ed5f 100644 --- a/cloud-run/build.gradle.kts +++ b/cloud-run/build.gradle.kts @@ -13,17 +13,9 @@ application { } buildConfig { - val firebaseAndroidAppId by stringPropertyOrNull { value -> - buildConfigField("FIREBASE_ANDROID_APP_ID", value) - } - - val googleServiceAccountId by stringPropertyOrNull { value -> - buildConfigField("GOOGLE_SERVICE_ACCOUNT_ID", value) - } - - val integrationApiKey by stringPropertyOrNull { value -> - buildConfigField("INTEGRATION_API_KEY", value) - } + val firebaseAndroidAppId by stringProperty(::buildConfigField) + val googleServiceAccountId by stringProperty(::buildConfigField) + val integrationApiKey by stringProperty(::buildConfigField) packageName.set("io.ashdavies.cloud") } diff --git a/conferences-app/build.gradle.kts b/conferences-app/build.gradle.kts index 5846d721c..7d432da0d 100644 --- a/conferences-app/build.gradle.kts +++ b/conferences-app/build.gradle.kts @@ -28,20 +28,20 @@ android { enableV3Signing = true enableV4Signing = true - val keyStoreFile by stringPropertyOrNull { - if (it != null) storeFile = rootProject.file(it) + val keyStoreFile by stringProperty { _, value -> + if (value != null) storeFile = rootProject.file(value) } - val keyStorePassword by stringPropertyOrNull { - if (it != null) storePassword = it + val keyStorePassword by stringProperty { _, value -> + if (value != null) storePassword = value } - val releaseKeyAlias by stringPropertyOrNull { - if (it != null) keyAlias = it + val releaseKeyAlias by stringProperty { _, value -> + if (value != null) keyAlias = value } - val releaseKeyPassword by stringPropertyOrNull { - if (it != null) keyPassword = it + val releaseKeyPassword by stringProperty { _, value -> + if (value != null) keyPassword = value } } @@ -68,8 +68,8 @@ android { } defaultConfig { - val versionCode by stringPropertyOrNull { - versionCode = it?.toInt() ?: 1 + val versionCode by stringProperty { _, value -> + versionCode = value?.toInt() ?: 1 } versionName = "1.0.0" @@ -96,9 +96,9 @@ android { } buildConfig { - val androidApiKey by stringPropertyWithTag(::buildConfigField) - val androidStrictMode by booleanPropertyWithTag(::buildConfigField) - val browserApiKey by stringPropertyWithTag(::buildConfigField) + val androidApiKey by stringProperty(::buildConfigField) + val androidStrictMode by booleanProperty(::buildConfigField) + val browserApiKey by stringProperty(::buildConfigField) packageName.set(android.namespace) } diff --git a/fused-properties/src/main/kotlin/StringProperty.kt b/fused-properties/src/main/kotlin/StringProperty.kt index 837002dd9..4ab68b1dd 100644 --- a/fused-properties/src/main/kotlin/StringProperty.kt +++ b/fused-properties/src/main/kotlin/StringProperty.kt @@ -29,24 +29,12 @@ private fun Project.stringPropertyProvider(definition: PropertyDefinition): Prov .orElse(providers.environmentVariable(definition.envPropertyName)) } -public fun Project.booleanProperty(block: (Boolean) -> Unit = { }): ReadOnlyDelegateProvider { - return readOnlyDelegateProvider { provider, _ -> provider.get().toBoolean().also(block) } +public fun Project.booleanProperty(block: (String, Boolean?) -> Unit): ReadOnlyDelegateProvider { + return readOnlyDelegateProvider { provider, tag -> provider.get().toBoolean().also { block(tag, it) } } } -public fun Project.booleanPropertyWithTag(action: (String, Boolean) -> Unit): ReadOnlyDelegateProvider { - return readOnlyDelegateProvider { provider, tag -> provider.get().toBoolean().also { action(tag, it) } } -} - -public fun Project.stringProperty(block: (String) -> Unit = { }): ReadOnlyDelegateProvider { - return readOnlyDelegateProvider { provider, _ -> provider.get().also(block) } -} - -public fun Project.stringPropertyWithTag(action: (String, String) -> Unit): ReadOnlyDelegateProvider { - return readOnlyDelegateProvider { provider, tag -> provider.get().also { action(tag, it) } } -} - -public fun Project.stringPropertyOrNull(block: (String?) -> Unit = { }): ReadOnlyDelegateProvider { - return readOnlyDelegateProvider { provider, _ -> provider.orNull.also(block) } +public fun Project.stringProperty(block: (String, String?) -> Unit): ReadOnlyDelegateProvider { + return readOnlyDelegateProvider { provider, tag -> provider.orNull.also { block(tag, it) } } } private fun Project.readOnlyDelegateProvider( diff --git a/identity-manager/build.gradle.kts b/identity-manager/build.gradle.kts index 88a984d6a..8ca0e1004 100644 --- a/identity-manager/build.gradle.kts +++ b/identity-manager/build.gradle.kts @@ -11,9 +11,7 @@ android { } buildConfig { - val serverClientId by stringProperty { value -> - buildConfigField("SERVER_CLIENT_ID", value) - } + val serverClientId by stringProperty(::buildConfigField) packageName.set(android.namespace) } diff --git a/map-routes/build.gradle.kts b/map-routes/build.gradle.kts index f17472e0a..6ea667106 100644 --- a/map-routes/build.gradle.kts +++ b/map-routes/build.gradle.kts @@ -9,8 +9,8 @@ plugins { android { defaultConfig { - val androidApiKey by stringProperty { value -> - manifestPlaceholders["ANDROID_API_KEY"] = value + val androidApiKey by stringProperty { _, value -> + manifestPlaceholders["ANDROID_API_KEY"] = "$value" } } @@ -18,9 +18,7 @@ android { } buildConfig { - val androidApiKey by stringProperty { value -> - buildConfigField("ANDROID_API_KEY", value) - } + val androidApiKey by stringProperty(::buildConfigField) packageName.set(android.namespace) }