diff --git a/README.md b/README.md index 0b546eb7..d8ae4561 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ datadog { If you're using variants, you can set a custom configuration per variant using the following syntax. +#### Groovy + ```groovy datadog { site = "US1" // Variants with no configurations will use this as default @@ -44,6 +46,20 @@ datadog { } ``` +#### Kotlin Script + +```kotlin +datadog { + site = "US1" // Variants with no configurations will use this as default + variants { + register("fr") { + site = "EU1" + mappingFilePath = "path/to/fr/mapping.txt" + } + } +} +``` + ### Gradle configuration cache support This plugin supports [Gradle configuration cache](https://docs.gradle.org/7.1/userguide/configuration_cache.html) starting from the version `1.1.0`, but to have this support you need to disable SDK dependency check by setting `checkProjectDependencies` to `none`: diff --git a/buildSrc/src/main/kotlin/com/datadog/gradle/config/MavenConfig.kt b/buildSrc/src/main/kotlin/com/datadog/gradle/config/MavenConfig.kt index 79d0decd..aa23a84b 100644 --- a/buildSrc/src/main/kotlin/com/datadog/gradle/config/MavenConfig.kt +++ b/buildSrc/src/main/kotlin/com/datadog/gradle/config/MavenConfig.kt @@ -37,7 +37,7 @@ fun Project.publishingConfig(projectDescription: String) { signingExtension.apply { val privateKey = System.getenv("GPG_PRIVATE_KEY") val password = System.getenv("GPG_PASSWORD") - isRequired = !hasProperty("dd-skip-signing") + isRequired = System.getenv("CI").toBoolean() && !hasProperty("dd-skip-signing") useInMemoryPgpKeys(privateKey, password) // com.gradle.plugin-publish plugin will automatically add signing task "signPluginMavenPublication" // sign(publishingExtension.publications.getByName(MavenConfig.PUBLICATION)) diff --git a/dd-sdk-android-gradle-plugin/src/main/kotlin/com/datadog/gradle/plugin/DdExtension.kt b/dd-sdk-android-gradle-plugin/src/main/kotlin/com/datadog/gradle/plugin/DdExtension.kt index f884bdcf..5f0d4b3f 100644 --- a/dd-sdk-android-gradle-plugin/src/main/kotlin/com/datadog/gradle/plugin/DdExtension.kt +++ b/dd-sdk-android-gradle-plugin/src/main/kotlin/com/datadog/gradle/plugin/DdExtension.kt @@ -25,13 +25,36 @@ open class DdExtension( /** * Container for the variant's configurations. */ - internal val variants = - objectFactory.domainObjectContainer(DdExtensionConfiguration::class.java) + internal val variants = objectFactory.domainObjectContainer(DdExtensionConfiguration::class.java) /** - * Closure method to create a DSL for variant configurations. + * Closure method to create a groovy DSL for variant configurations. */ fun variants(configureClosure: Closure) { variants.configure(configureClosure) } + + /** + * Method compatible with Kotlin Script to create a DSL for variant configurations. + */ + fun variants(configure: VariantScope.() -> Unit) { + configure(VariantScope()) + } + + /** + * Inner class used for Kotlin DSL. + */ + inner class VariantScope { + + /** + * Defines a new named object, which will be created and configured when it is required. + * @param name the name of the variant to configure + * @param configuration the action to run to configure the variant + */ + fun register(name: String, configuration: DdExtensionConfiguration.() -> Unit) { + variants.register(name) { + configuration(it) + } + } + } } diff --git a/samples/variants-kotlin/.gitignore b/samples/variants-kotlin/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/samples/variants-kotlin/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/samples/variants-kotlin/build.gradle.kts b/samples/variants-kotlin/build.gradle.kts new file mode 100644 index 00000000..69de09e0 --- /dev/null +++ b/samples/variants-kotlin/build.gradle.kts @@ -0,0 +1,105 @@ +@file:Suppress("StringLiteralDuplication") + +import com.datadog.gradle.config.AndroidConfig + +plugins { + id("com.android.application") + id("kotlin-android") +// id("com.datadoghq.dd-sdk-android-gradle-plugin") +} + +android { + compileSdk = AndroidConfig.TARGET_SDK + buildToolsVersion = AndroidConfig.BUILD_TOOLS_VERSION + + namespace = "com.datadog.example.variants.kotlin" + defaultConfig { + applicationId = "com.datadog.example.variants.kotlin" + + minSdk = AndroidConfig.MIN_SDK + targetSdk = AndroidConfig.TARGET_SDK + versionCode = 1 + versionName = "1.0" + multiDexEnabled = true + } + + buildTypes { + release { + isMinifyEnabled = true + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + + sourceSets.named("main") { + java.srcDir("src/main/kotlin") + } + + flavorDimensions.add("version") + flavorDimensions.add("colour") + productFlavors { + register("demo") { + dimension = "version" + applicationIdSuffix = ".demo" + versionNameSuffix = "-demo" + } + register("full") { + dimension = "version" + applicationIdSuffix = ".full" + versionNameSuffix = "-full" + } + register("pro") { + dimension = "version" + applicationIdSuffix = ".pro" + versionNameSuffix = "-pro" + } + + register("red") { + dimension = "colour" + } + register("green") { + dimension = "colour" + } + register("blue") { + dimension = "colour" + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + kotlinOptions { + jvmTarget = "17" + } +} + +dependencies { + implementation(project(":samples:lib-module")) + implementation(libs.kotlin) + + implementation(libs.androidx.core) + implementation(libs.androidx.appcompat) + implementation(libs.androidx.constraintlayout) +} + +/* +datadog { + site = "US" + checkProjectDependencies = com.datadog.gradle.plugin.SdkCheckLevel.FAIL + mappingFilePath = "path/to/mapping.txt" + + variants { + register("demo") { + site = "US3" + versionName = "demo" + } + register("full") { + versionName = "full" + } + register("pro") { + versionName = "pro" + } + } +} +*/ diff --git a/samples/variants-kotlin/proguard-rules.pro b/samples/variants-kotlin/proguard-rules.pro new file mode 100644 index 00000000..ff59496d --- /dev/null +++ b/samples/variants-kotlin/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle.kts. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/samples/variants-kotlin/src/demo/java/com/datadog/example/variants/VaryingClass.kt b/samples/variants-kotlin/src/demo/java/com/datadog/example/variants/VaryingClass.kt new file mode 100644 index 00000000..c235b8f5 --- /dev/null +++ b/samples/variants-kotlin/src/demo/java/com/datadog/example/variants/VaryingClass.kt @@ -0,0 +1,5 @@ +package com.datadog.example.variants + +internal class VaryingClass : VaryingInfo { + override fun getName(): String = "demo" +} diff --git a/samples/variants-kotlin/src/full/java/com/datadog/example/variants/VaryingClass.kt b/samples/variants-kotlin/src/full/java/com/datadog/example/variants/VaryingClass.kt new file mode 100644 index 00000000..72092414 --- /dev/null +++ b/samples/variants-kotlin/src/full/java/com/datadog/example/variants/VaryingClass.kt @@ -0,0 +1,5 @@ +package com.datadog.example.variants + +internal class VaryingClass : VaryingInfo { + override fun getName(): String = "full" +} diff --git a/samples/variants-kotlin/src/main/AndroidManifest.xml b/samples/variants-kotlin/src/main/AndroidManifest.xml new file mode 100644 index 00000000..11853bb1 --- /dev/null +++ b/samples/variants-kotlin/src/main/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/variants-kotlin/src/main/java/com/datadog/example/variants/MainActivity.kt b/samples/variants-kotlin/src/main/java/com/datadog/example/variants/MainActivity.kt new file mode 100644 index 00000000..c864a168 --- /dev/null +++ b/samples/variants-kotlin/src/main/java/com/datadog/example/variants/MainActivity.kt @@ -0,0 +1,23 @@ +package com.datadog.example.variants + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import com.datadog.example.variants.ext.toast + +/** + * Main Activity for the sample app. + */ +class MainActivity : AppCompatActivity() { + + private val varyingClass: VaryingInfo = VaryingClass() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + } + + override fun onResume() { + super.onResume() + toast("Hello World, with ${varyingClass.getName()}") + } +} diff --git a/samples/variants-kotlin/src/main/java/com/datadog/example/variants/VaryingInfo.kt b/samples/variants-kotlin/src/main/java/com/datadog/example/variants/VaryingInfo.kt new file mode 100644 index 00000000..9e8f33c6 --- /dev/null +++ b/samples/variants-kotlin/src/main/java/com/datadog/example/variants/VaryingInfo.kt @@ -0,0 +1,5 @@ +package com.datadog.example.variants + +internal interface VaryingInfo { + fun getName(): String +} diff --git a/samples/variants-kotlin/src/main/kotlin/com/datadog/example/variants/ext/ActivityExt.kt b/samples/variants-kotlin/src/main/kotlin/com/datadog/example/variants/ext/ActivityExt.kt new file mode 100644 index 00000000..8aba8e68 --- /dev/null +++ b/samples/variants-kotlin/src/main/kotlin/com/datadog/example/variants/ext/ActivityExt.kt @@ -0,0 +1,8 @@ +package com.datadog.example.variants.ext + +import android.app.Activity +import android.widget.Toast + +internal fun Activity.toast(message: String) { + Toast.makeText(this, message, Toast.LENGTH_LONG).show() +} diff --git a/samples/variants-kotlin/src/main/res/drawable-v24/ic_launcher_foreground.xml b/samples/variants-kotlin/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..855287e7 --- /dev/null +++ b/samples/variants-kotlin/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/variants-kotlin/src/main/res/drawable/ic_launcher_background.xml b/samples/variants-kotlin/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..28cdb698 --- /dev/null +++ b/samples/variants-kotlin/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/variants-kotlin/src/main/res/layout/activity_main.xml b/samples/variants-kotlin/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..0eb50901 --- /dev/null +++ b/samples/variants-kotlin/src/main/res/layout/activity_main.xml @@ -0,0 +1,25 @@ + + + + + + + + \ No newline at end of file diff --git a/samples/variants-kotlin/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/samples/variants-kotlin/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 00000000..1a8bbae7 --- /dev/null +++ b/samples/variants-kotlin/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/samples/variants-kotlin/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/samples/variants-kotlin/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 00000000..1a8bbae7 --- /dev/null +++ b/samples/variants-kotlin/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/samples/variants-kotlin/src/main/res/mipmap-hdpi/ic_launcher.png b/samples/variants-kotlin/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 00000000..a571e600 Binary files /dev/null and b/samples/variants-kotlin/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/samples/variants-kotlin/src/main/res/mipmap-hdpi/ic_launcher_round.png b/samples/variants-kotlin/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 00000000..61da551c Binary files /dev/null and b/samples/variants-kotlin/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/samples/variants-kotlin/src/main/res/mipmap-mdpi/ic_launcher.png b/samples/variants-kotlin/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 00000000..c41dd285 Binary files /dev/null and b/samples/variants-kotlin/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/samples/variants-kotlin/src/main/res/mipmap-mdpi/ic_launcher_round.png b/samples/variants-kotlin/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 00000000..db5080a7 Binary files /dev/null and b/samples/variants-kotlin/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/samples/variants-kotlin/src/main/res/mipmap-xhdpi/ic_launcher.png b/samples/variants-kotlin/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 00000000..6dba46da Binary files /dev/null and b/samples/variants-kotlin/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/samples/variants-kotlin/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/samples/variants-kotlin/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 00000000..da31a871 Binary files /dev/null and b/samples/variants-kotlin/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/samples/variants-kotlin/src/main/res/mipmap-xxhdpi/ic_launcher.png b/samples/variants-kotlin/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..15ac6817 Binary files /dev/null and b/samples/variants-kotlin/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/samples/variants-kotlin/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/samples/variants-kotlin/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 00000000..b216f2d3 Binary files /dev/null and b/samples/variants-kotlin/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/samples/variants-kotlin/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/samples/variants-kotlin/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 00000000..f25a4197 Binary files /dev/null and b/samples/variants-kotlin/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/samples/variants-kotlin/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/samples/variants-kotlin/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 00000000..e96783cc Binary files /dev/null and b/samples/variants-kotlin/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/samples/variants-kotlin/src/main/res/values/colors.xml b/samples/variants-kotlin/src/main/res/values/colors.xml new file mode 100644 index 00000000..101b93b4 --- /dev/null +++ b/samples/variants-kotlin/src/main/res/values/colors.xml @@ -0,0 +1,12 @@ + + + + + #6200EE + #3700B3 + #03DAC5 + \ No newline at end of file diff --git a/samples/variants-kotlin/src/main/res/values/strings.xml b/samples/variants-kotlin/src/main/res/values/strings.xml new file mode 100644 index 00000000..047cf603 --- /dev/null +++ b/samples/variants-kotlin/src/main/res/values/strings.xml @@ -0,0 +1,9 @@ + + + + Sample App + \ No newline at end of file diff --git a/samples/variants-kotlin/src/main/res/values/styles.xml b/samples/variants-kotlin/src/main/res/values/styles.xml new file mode 100644 index 00000000..fb1a768e --- /dev/null +++ b/samples/variants-kotlin/src/main/res/values/styles.xml @@ -0,0 +1,16 @@ + + + + + + + \ No newline at end of file diff --git a/samples/variants-kotlin/src/pro/java/com/datadog/example/variants/VaryingClass.kt b/samples/variants-kotlin/src/pro/java/com/datadog/example/variants/VaryingClass.kt new file mode 100644 index 00000000..1e772b19 --- /dev/null +++ b/samples/variants-kotlin/src/pro/java/com/datadog/example/variants/VaryingClass.kt @@ -0,0 +1,5 @@ +package com.datadog.example.variants + +internal class VaryingClass : VaryingInfo { + override fun getName(): String = "pro" +} diff --git a/settings.gradle.kts b/settings.gradle.kts index ea5273ff..f32f328f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,4 +8,5 @@ include(":dd-sdk-android-gradle-plugin") include(":samples:basic") include(":samples:variants") +include(":samples:variants-kotlin") include(":samples:lib-module")