Skip to content

Commit

Permalink
Merge pull request #212 from DataDog/nogorodnikov/rum-2271/files-unde…
Browse files Browse the repository at this point in the history
…r-kotlin-source-set-are-not-added-to-repository-information

RUM-2271: Add files under kotlin source set to the repository information
  • Loading branch information
0xnm authored Dec 8, 2023
2 parents 0fd0071 + 1537f56 commit ee172eb
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package com.datadog.gradle.plugin

import com.android.build.gradle.AppExtension
import com.android.build.gradle.api.ApplicationVariant
import com.android.builder.model.Version
import com.datadog.gradle.plugin.internal.ApiKey
import com.datadog.gradle.plugin.internal.ApiKeySource
import com.datadog.gradle.plugin.internal.GitRepositoryDetector
Expand Down Expand Up @@ -191,8 +192,16 @@ class DdAndroidGradlePlugin @Inject constructor(
val roots = mutableListOf<File>()
variant.sourceSets.forEach {
roots.addAll(it.javaDirectories)
if (isAgp7OrAbove()) {
roots.addAll(it.kotlinDirectories)
}
}
uploadTask.sourceSetRoots = roots

// it can be an overlap between java and kotlin directories and since File doesn't override
// equals for set comparison, we will remove duplicates manually
uploadTask.sourceSetRoots = roots.map { it.absolutePath }
.distinct()
.map { File(it) }

return uploadTask
}
Expand Down Expand Up @@ -370,6 +379,18 @@ class DdAndroidGradlePlugin @Inject constructor(
return isDefaultObfuscationEnabled || isNonDefaultObfuscationEnabled
}

@Suppress("MagicNumber", "ReturnCount")
private fun isAgp7OrAbove(): Boolean {
val version = Version.ANDROID_GRADLE_PLUGIN_VERSION
val groups = version.split(".")
if (groups.size < 3) return false
val major = groups[0].toIntOrNull()
val minor = groups[1].toIntOrNull()
val patch = groups[2].substringBefore("-").toIntOrNull()
if (major == null || minor == null || patch == null) return false
return major >= 7 && minor >= 0 && patch >= 0
}

private val Project.androidApplicationExtension: AppExtension?
get() = extensions.findByType(AppExtension::class.java)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import java.io.File
// TODO RUMM-1096 handle git subtrees
// TODO RUMM-1093 let customer override `origin` with custom remote name
internal class GitRepositoryDetector(
@Suppress("UnstableApiUsage") private val execOperations: ExecOperations,
private val execOperations: ExecOperations,
private val urlSanitizer: UrlSanitizer = GitRemoteUrlSanitizer()
) : RepositoryDetector {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.gradle.process.ExecOperations
import org.gradle.process.internal.ExecException
import java.io.ByteArrayOutputStream

@Suppress("UnstableApiUsage")
internal fun ExecOperations.execShell(vararg command: String): String {
val outputStream = ByteArrayOutputStream()
val errorStream = ByteArrayOutputStream()
Expand Down
Loading

0 comments on commit ee172eb

Please sign in to comment.