Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release 1.11.0 branch into main branch #193

Merged
merged 19 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 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)
* [IMPROVEMENT] Read `DATADOG_API_KEY` from gradle properties. See [#186](https://github.com/DataDog/dd-sdk-android-gradle-plugin/pull/186)
* [MAINTENANCE] Update AGP to 8.1.0. See [#182](https://github.com/DataDog/dd-sdk-android-gradle-plugin/pull/182)

# 1.10.0 / 2023-07-17

* [IMPROVEMENT] Improve output of gradle plugin upload. See [#173](https://github.com/DataDog/dd-sdk-android-gradle-plugin/pull/173)
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, 10, 0, Version.Type.Release)
val VERSION = Version(1, 11, 0, Version.Type.Release)
const val GROUP_ID = "com.datadoghq"
const val PUBLICATION = "pluginMaven"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,14 @@ class DdAndroidGradlePlugin @Inject constructor(
@Suppress("ReturnCount")
// TODO RUMM-2382 use ProviderFactory/Provider APIs to watch changes in external environment
internal fun resolveApiKey(target: Project): ApiKey {
val propertyKey = target.findProperty(DD_API_KEY)?.toString()
if (!propertyKey.isNullOrBlank()) return ApiKey(propertyKey, ApiKeySource.GRADLE_PROPERTY)

val environmentKey = System.getenv(DD_API_KEY)
if (!environmentKey.isNullOrBlank()) return ApiKey(environmentKey, ApiKeySource.ENVIRONMENT)

val alternativeEnvironmentKey = System.getenv(DATADOG_API_KEY)
if (!alternativeEnvironmentKey.isNullOrBlank()) {
return ApiKey(alternativeEnvironmentKey, ApiKeySource.ENVIRONMENT)
}
return ApiKey.NONE
val apiKey = listOf(
ApiKey(target.stringProperty(DD_API_KEY).orEmpty(), ApiKeySource.GRADLE_PROPERTY),
ApiKey(target.stringProperty(DATADOG_API_KEY).orEmpty(), ApiKeySource.GRADLE_PROPERTY),
ApiKey(System.getenv(DD_API_KEY).orEmpty(), ApiKeySource.ENVIRONMENT),
ApiKey(System.getenv(DATADOG_API_KEY).orEmpty(), ApiKeySource.ENVIRONMENT)
).firstOrNull { it.value.isNotBlank() }

return apiKey ?: ApiKey.NONE
}

@Suppress("DefaultLocale", "ReturnCount")
Expand Down Expand Up @@ -273,6 +270,10 @@ class DdAndroidGradlePlugin @Inject constructor(
return null
}

private fun Project.stringProperty(propertyName: String): String? {
return findProperty(propertyName)?.toString()
}

// endregion

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ open class DdMappingFileUploadTask
)

val shrinkedFile = File(mappingFile.parent, MAPPING_OPTIMIZED_FILE_NAME)
if (shrinkedFile.exists()) {
shrinkedFile.delete()
}
// sort is needed to have predictable replacement in the following case:
// imagine there are 2 keys - "androidx.work" and "androidx.work.Job", and the latter
// occurs much more often than the rest under "androidx.work.*". So for the more efficient
Expand Down
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.10.0"
internal const val VERSION = "1.11.0"

internal const val HEADER_API_KEY = "DD-API-KEY"
internal const val HEADER_EVP_ORIGIN = "DD-EVP-ORIGIN"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.extension.Extensions
import org.junit.jupiter.api.io.TempDir
import java.io.File
import java.util.Locale
import java.util.Properties
import kotlin.io.path.Path

Expand Down Expand Up @@ -64,7 +65,7 @@ internal class DdAndroidGradlePluginFunctionalTest {
private lateinit var datadogCiFile: File

@BeforeEach
fun `set up`() {
fun `set up`(forge: Forge) {
appRootDir = File(testProjectDir, "samples/app").apply { mkdirs() }
libModuleRootDir = File(testProjectDir, "samples/lib-module").apply { mkdirs() }
settingsFile = File(testProjectDir, "settings.gradle")
Expand All @@ -81,7 +82,10 @@ internal class DdAndroidGradlePluginFunctionalTest {
libModulePlaceholderFile = File(libModuleKotlinSourcesDir, "Placeholder.kt")
datadogCiFile = File(testProjectDir.parent, "datadog-ci.json")

stubFile(settingsFile, SETTINGS_FILE_CONTENT)
// we need to check that our plugin supports different AGP versions (backward and forward
// compatible)
val agpVersion = forge.anElementFrom(OLD_AGP_VERSION, LATEST_AGP_VERSION)
stubFile(settingsFile, SETTINGS_FILE_CONTENT.format(Locale.US, agpVersion))
stubFile(sampleApplicationClassFile, APPLICATION_CLASS_CONTENT)
stubFile(appManifestFile, APP_MANIFEST_FILE_CONTENT)
stubFile(gradlePropertiesFile, GRADLE_PROPERTIES_FILE_CONTENT)
Expand Down Expand Up @@ -802,7 +806,7 @@ internal class DdAndroidGradlePluginFunctionalTest {
resolutionStrategy {
eachPlugin {
if (requested.id.id == "com.android.application") {
useModule("com.android.tools.build:gradle:7.1.2")
useModule("com.android.tools.build:gradle:%s")
}
if (requested.id.id == "kotlin-android") {
useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
Expand All @@ -822,5 +826,8 @@ internal class DdAndroidGradlePluginFunctionalTest {
org.gradle.jvmargs=-Xmx2560m
android.useAndroidX=true
""".trimIndent()

const val OLD_AGP_VERSION = "7.1.2"
const val LATEST_AGP_VERSION = "8.1.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ internal class DdAndroidGradlePluginTest {
// region resolveApiKey

@Test
fun `𝕄 resolve API KEY from project properties 𝕎 resolveApiKey()`() {
fun `𝕄 resolve API KEY from project properties 𝕎 resolveApiKey() { as DD_API_KEY }`() {
// Given
fakeProject = mock()
whenever(fakeProject.findProperty(DdAndroidGradlePlugin.DD_API_KEY)) doReturn
Expand All @@ -477,7 +477,7 @@ internal class DdAndroidGradlePluginTest {
}

@Test
fun `𝕄 resolve API KEY from environment variable 𝕎 resolveApiKey()`() {
fun `𝕄 resolve API KEY from environment variable 𝕎 resolveApiKey() { as DD_API_KEY }`() {
// Given
setEnv(DdAndroidGradlePlugin.DD_API_KEY, fakeApiKey.value)

Expand All @@ -490,7 +490,22 @@ internal class DdAndroidGradlePluginTest {
}

@Test
fun `𝕄 resolve API KEY from alternative environment variable 𝕎 resolveApiKey()`() {
fun `𝕄 resolve API KEY from project properties 𝕎 resolveApiKey() { as DATADOG_API_KEY }`() {
// Given
fakeProject = mock()
whenever(fakeProject.findProperty(DdAndroidGradlePlugin.DATADOG_API_KEY)) doReturn
fakeApiKey.value

// When
val apiKey = testedPlugin.resolveApiKey(fakeProject)

// Then
assertThat(apiKey.value).isEqualTo(fakeApiKey.value)
assertThat(apiKey.source).isEqualTo(ApiKeySource.GRADLE_PROPERTY)
}

@Test
fun `𝕄 resolve API KEY from environment variable 𝕎 resolveApiKey() { as DATADOG_API_KEY }`() {
// Given
setEnv(DdAndroidGradlePlugin.DATADOG_API_KEY, fakeApiKey.value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,59 @@ internal class DdMappingFileUploadTaskTest {
}
}

@Test
fun `𝕄 upload file 𝕎 applyTask() { delete old shrinked mapping file before writing }`(
forge: Forge
) {
// Given
val expectedLines = forge.aList {
forge.anAlphabeticalString() + forge.aString { ' ' }
}
val fakeMappingFile = File(tempDir, fakeMappingFileName)
fakeMappingFile.writeText(
expectedLines.joinToString(separator = "\n") {
val indent = if (forge.aBool()) forge.aString { ' ' } else ""
indent + it
}
)

testedTask.mappingFileTrimIndents = true
testedTask.mappingFilePath = fakeMappingFile.path
val fakeRepositoryFile = File(tempDir, fakeRepositoryFileName)
testedTask.repositoryFile = fakeRepositoryFile
whenever(mockRepositoryDetector.detectRepositories(any(), eq("")))
.doReturn(listOf(fakeRepoInfo))
val oldShrinkedMappingFile = File(
fakeMappingFile.parent,
DdMappingFileUploadTask.MAPPING_OPTIMIZED_FILE_NAME
)
oldShrinkedMappingFile.createNewFile()
oldShrinkedMappingFile.writeText(forge.aString())

// When
testedTask.applyTask()

// Then
argumentCaptor<File> {
verify(mockUploader).upload(
eq(fakeSite),
capture(),
eq(fakeRepositoryFile),
eq(fakeApiKey.value),
eq(
DdAppIdentifier(
serviceName = fakeService,
version = fakeVersion,
variant = fakeVariant
)
),
eq(fakeRepoInfo),
useGzip = eq(true)
)
assertThat(lastValue.readLines()).isEqualTo(expectedLines)
}
}

@Test
fun `𝕄 upload file 𝕎 applyTask { remote url provided }`() {
// Given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ internal fun initializeGit(remoteUrl: String, rootDirectory: File) {
.start()
.waitForSuccess(5, TimeUnit.SECONDS)
)
check(
ProcessBuilder("git", "config", "commit.gpgsign", "false")
.directory(rootDirectory)
.start()
.waitForSuccess(5, TimeUnit.SECONDS)
)
check(
ProcessBuilder("git", "config", "user.name", "\"Some User\"")
.directory(rootDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ android {
}

dependencies {
implementation("com.datadoghq:dd-sdk-android-rum:2.0.0-beta2")
implementation("com.datadoghq:dd-sdk-android-rum:2.1.0")
}

datadog {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ android {
}

dependencies {
implementation("com.datadoghq:dd-sdk-android-rum:2.0.0-beta2")
implementation("com.datadoghq:dd-sdk-android-rum:2.1.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ android {

dependencies {
implementation(project(':samples:lib-module'))
implementation("com.datadoghq:dd-sdk-android-rum:2.0.0-beta2")
implementation("com.datadoghq:dd-sdk-android-rum:2.1.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ android {
}

dependencies {
implementation("com.datadoghq:dd-sdk-android-rum:2.0.0-beta2")
implementation("com.datadoghq:dd-sdk-android-rum:2.1.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ android {
}

dependencies {
implementation("com.datadoghq:dd-sdk-android-rum:2.0.0-beta2")
implementation("com.datadoghq:dd-sdk-android-rum:2.1.0")
}

datadog {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ android {
}

dependencies {
implementation("com.datadoghq:dd-sdk-android-rum:2.0.0-beta2")
implementation("com.datadoghq:dd-sdk-android-rum:2.1.0")
}

datadog {
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ json = "20180813"
okHttp = "4.11.0"

# Android
androidToolsPlugin = "8.0.1"
androidToolsPlugin = "8.1.0"

# AndroidX
androidx-core ="1.3.2"
Expand Down Expand Up @@ -38,8 +38,8 @@ versionsPluginGradle = "0.33.0"
kotlinGrammarParser = "c35b50fa44"

# Datadog
datadogSdk = "2.0.0-beta2"
datadogPluginGradle = "1.9.0"
datadogSdk = "2.1.0"
datadogPluginGradle = "1.10.0"

[libraries]

Expand Down