Skip to content

Commit

Permalink
Merge pull request #203 from DataDog/nogorodnikov/merge-release-1.12.…
Browse files Browse the repository at this point in the history
…0-into-main

Merge `release/1.12.0` branch into `main` branch
  • Loading branch information
0xnm authored Oct 31, 2023
2 parents 67614bb + ed8fa24 commit d603d42
Show file tree
Hide file tree
Showing 47 changed files with 721 additions and 63 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.12.0 / 2023-10-30

* [IMPROVEMENT] Make plugin compatible with Kotlin Script. See [#197](https://github.com/DataDog/dd-sdk-android-gradle-plugin/pull/197)
* [IMPROVEMENT] Lower log level from warning to info when no minification enabled. See [#198](https://github.com/DataDog/dd-sdk-android-gradle-plugin/pull/198)
* [IMPROVEMENT] Allow customer to use non-standard obfuscation. See [#199](https://github.com/DataDog/dd-sdk-android-gradle-plugin/pull/199)

# 1.11.0 / 2023-09-13

* [BUGFIX] Delete old shrinked mapping file before writing to it. See [#189](https://github.com/DataDog/dd-sdk-android-gradle-plugin/pull/189)
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import java.net.URI

object MavenConfig {

val VERSION = Version(1, 11, 0, Version.Type.Release)
val VERSION = Version(1, 12, 0, Version.Type.Release)
const val GROUP_ID = "com.datadoghq"
const val PUBLICATION = "pluginMaven"
}
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import javax.inject.Inject
/**
* Plugin adding tasks for Android projects using Datadog's SDK for Android.
*/
@Suppress("TooManyFunctions")
class DdAndroidGradlePlugin @Inject constructor(
private val execOps: ExecOperations
) : Plugin<Project> {
Expand All @@ -40,6 +41,8 @@ class DdAndroidGradlePlugin @Inject constructor(
val androidExtension = target.extensions.findByType(AppExtension::class.java)
if (androidExtension == null) {
LOGGER.error(ERROR_NOT_ANDROID)
} else if (!extension.enabled) {
LOGGER.info("Datadog extension disabled, no upload task created")
} else {
androidExtension.applicationVariants.all { variant ->
configureVariantForUploadTask(target, variant, apiKey, extension)
Expand Down Expand Up @@ -73,13 +76,13 @@ class DdAndroidGradlePlugin @Inject constructor(
apiKey: ApiKey,
extension: DdExtension
): Task? {
if (!variant.buildType.isMinifyEnabled) {
LOGGER.warn("Minifying disabled for variant ${variant.name}, no upload task created")
return null
}
val extensionConfiguration = resolveExtensionConfiguration(extension, variant)
val isDefaultObfuscationEnabled = variant.buildType.isMinifyEnabled
val isNonDefaultObfuscationEnabled = extensionConfiguration.nonDefaultObfuscation
val isObfuscationEnabled = isDefaultObfuscationEnabled || isNonDefaultObfuscationEnabled

if (!extension.enabled) {
LOGGER.warn("Extension disabled for variant ${variant.name}, no upload task created")
if (!isObfuscationEnabled) {
LOGGER.info("Minifying disabled for variant ${variant.name}, no upload task created")
return null
}

Expand All @@ -91,13 +94,10 @@ class DdAndroidGradlePlugin @Inject constructor(
DdMappingFileUploadTask::class.java,
GitRepositoryDetector(execOps)
)
val extensionConfiguration = resolveExtensionConfiguration(extension, variant)

configureVariantTask(uploadTask, apiKey, flavorName, extensionConfiguration, variant)

val outputsDir = File(target.buildDir, "outputs")
uploadTask.mappingFilePath =
resolveMappingFilePath(extensionConfiguration, outputsDir, variant)
uploadTask.mappingFilePath = resolveMappingFilePath(extensionConfiguration, target, variant)
uploadTask.mappingFilePackagesAliases =
filterMappingFileReplacements(
extensionConfiguration.mappingFilePackageAliases,
Expand All @@ -108,9 +108,7 @@ class DdAndroidGradlePlugin @Inject constructor(
uploadTask.datadogCiFile = findDatadogCiFile(target.projectDir)
}

val reportsDir = File(outputsDir, "reports")
val datadogDir = File(reportsDir, "datadog")
uploadTask.repositoryFile = File(datadogDir, "repository.json")
uploadTask.repositoryFile = resolveDatadogRepositoryFile(target)

val roots = mutableListOf<File>()
variant.sourceSets.forEach {
Expand All @@ -128,7 +126,7 @@ class DdAndroidGradlePlugin @Inject constructor(
extension: DdExtension
): Provider<DdCheckSdkDepsTask>? {
if (!extension.enabled) {
LOGGER.warn("Extension disabled for variant ${variant.name}, no sdk check task created")
LOGGER.info("Extension disabled for variant ${variant.name}, no sdk check task created")
return null
}

Expand Down Expand Up @@ -187,19 +185,27 @@ class DdAndroidGradlePlugin @Inject constructor(

private fun resolveMappingFilePath(
extensionConfiguration: DdExtensionConfiguration,
outputsDir: File,
target: Project,
variant: ApplicationVariant
): String {
val customPath = extensionConfiguration.mappingFilePath
return if (customPath != null) {
customPath
} else {
val outputsDir = File(target.buildDir, "outputs")
val mappingDir = File(outputsDir, "mapping")
val flavorDir = File(mappingDir, variant.name)
File(flavorDir, "mapping.txt").path
}
}

private fun resolveDatadogRepositoryFile(target: Project): File {
val outputsDir = File(target.buildDir, "outputs")
val reportsDir = File(outputsDir, "reports")
val datadogDir = File(reportsDir, "datadog")
return File(datadogDir, "repository.json")
}

private fun filterMappingFileReplacements(
replacements: Map<String, String>,
applicationId: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DdExtensionConfiguration>) {
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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ open class DdExtensionConfiguration(
*/
var mappingFileTrimIndents: Boolean = false

/**
* This property declares that the obfuscation technology used is not the default
* R8/Proguard included in the Android toolchain (e.g.: Dexguard, …).
* Doing so will create an upload task for all variants and all build types
*/
var nonDefaultObfuscation: Boolean = false

/**
* Ignore the config declared in `datadog-ci.json` file if found.
*/
Expand All @@ -98,5 +105,6 @@ open class DdExtensionConfiguration(
mappingFilePackageAliases = config.mappingFilePackageAliases
mappingFileTrimIndents = config.mappingFileTrimIndents
ignoreDatadogCiFileConfig = config.ignoreDatadogCiFileConfig
nonDefaultObfuscation = config.nonDefaultObfuscation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ internal class OkHttpUploader : Uploader {
companion object {

// TODO add a plugin to automatically sync this with the `MavenConfig` value
internal const val VERSION = "1.11.0"
internal const val VERSION = "1.12.0"

internal const val HEADER_API_KEY = "DD-API-KEY"
internal const val HEADER_EVP_ORIGIN = "DD-EVP-ORIGIN"
Expand Down
Loading

0 comments on commit d603d42

Please sign in to comment.