Skip to content

Commit

Permalink
Use constructor injection for RepositoryDetector.
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzybinary committed Feb 9, 2024
1 parent 851894e commit 739345e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import javax.inject.Inject
* Proguard/R8 files, etc.)..
*/
abstract class DdFileUploadTask @Inject constructor(
providerFactory: ProviderFactory
providerFactory: ProviderFactory,
@get:Internal internal val repositoryDetector: RepositoryDetector
) : DefaultTask() {
@get:Internal
internal var uploader: Uploader = OkHttpUploader()
Expand All @@ -48,12 +49,6 @@ abstract class DdFileUploadTask @Inject constructor(
@get:Input
var apiKeySource: ApiKeySource = ApiKeySource.NONE

/**
* The repository detector to use for detecting the repository information.
*/
@get:Internal
var repositoryDetector: RepositoryDetector? = null

/**
* The variant name of the application.
*/
Expand Down Expand Up @@ -147,17 +142,17 @@ abstract class DdFileUploadTask @Inject constructor(
val mappingFiles = getFilesList()
if (mappingFiles.isEmpty()) return

val repositories = repositoryDetector?.detectRepositories(
val repositories = repositoryDetector.detectRepositories(
sourceSetRoots,
remoteRepositoryUrl
).orEmpty()
)

if (repositories.isNotEmpty()) {
generateRepositoryFile(repositories)
}

val site = DatadogSite.valueOf(site)
var caughtErrors = mutableListOf<Exception>()
val caughtErrors = mutableListOf<Exception>()
for (mappingFile in mappingFiles) {
LOGGER.info("Uploading ${mappingFile.fileType} file: ${mappingFile.file.absolutePath}")
try {
Expand Down Expand Up @@ -185,7 +180,7 @@ abstract class DdFileUploadTask @Inject constructor(
if (caughtErrors.count() == 1) {
throw caughtErrors.first()
} else {
val consolidatedError = Exception("Multiple errors occurred during upload")
val consolidatedError = RuntimeException("Multiple errors occurred during upload")
caughtErrors.forEach {
consolidatedError.addSuppressed(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import kotlin.reflect.full.memberProperties
*/
internal abstract class DdNdkSymbolFileUploadTask @Inject constructor(
objectFactory: ObjectFactory,
providerFactory: ProviderFactory
) : DdFileUploadTask(providerFactory) {
providerFactory: ProviderFactory,
repositoryDetector: RepositoryDetector
) : DdFileUploadTask(providerFactory, repositoryDetector) {

@get:InputFiles
val searchDirectories: ConfigurableFileCollection = objectFactory.fileCollection()
Expand Down Expand Up @@ -154,37 +155,39 @@ internal abstract class DdNdkSymbolFileUploadTask @Inject constructor(

return project.tasks.register(
TASK_NAME + variant.name.capitalize(),
DdNdkSymbolFileUploadTask::class.java
) { task ->
val roots = mutableListOf<File>()
variant.sourceSets.forEach {
roots.addAll(it.javaDirectories)
@Suppress("MagicNumber")
if (isAgpAbove(7, 0, 0)) {
roots.addAll(it.kotlinDirectories)
DdNdkSymbolFileUploadTask::class.java,
repositoryDetector
).apply {
configure { task ->
val roots = mutableListOf<File>()
variant.sourceSets.forEach {
roots.addAll(it.javaDirectories)
@Suppress("MagicNumber")
if (isAgpAbove(7, 0, 0)) {
roots.addAll(it.kotlinDirectories)
}
}
}
task.sourceSetRoots = roots
task.sourceSetRoots = roots

nativeBuildProviders.forEach { buildTask ->
val searchFiles = getSearchDirs(buildTask, providerFactory)
nativeBuildProviders.forEach { buildTask ->
val searchFiles = getSearchDirs(buildTask, providerFactory)

task.searchDirectories.from(searchFiles)
task.dependsOn(buildTask)
}
task.searchDirectories.from(searchFiles)
task.dependsOn(buildTask)
}

task.datadogCiFile = findDatadogCiFile(project.rootDir)
task.repositoryDetector = repositoryDetector
task.repositoryFile = resolveDatadogRepositoryFile(project)
task.configureWith(
apiKey,
extensionConfiguration,
variant
)
task.datadogCiFile = findDatadogCiFile(project.rootDir)
task.repositoryFile = resolveDatadogRepositoryFile(project)
task.configureWith(
apiKey,
extensionConfiguration,
variant
)

task.buildId = buildIdTask.flatMap {
it.buildIdFile.flatMap {
providerFactory.provider { it.asFile.readText().trim() }
task.buildId = buildIdTask.flatMap {
it.buildIdFile.flatMap {
providerFactory.provider { it.asFile.readText().trim() }
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,8 @@ internal class DdAndroidGradlePluginFunctionalTest {

// Then
val buildIdInOriginFile = testProjectDir.findBuildIdInOriginFile(variant)
val buildIdInApk = testProjectDir.findBuildIdInApk(variant)
assertThat(buildIdInApk).isEqualTo(buildIdInOriginFile)

assertThat(nativeResult).containsInOutput("Creating request with GZIP encoding.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ internal class DdNdkSymbolFileUploadTaskTest {

testedTask = fakeProject.tasks.create(
"DdSymbolFileUploadTask",
DdNdkSymbolFileUploadTask::class.java
DdNdkSymbolFileUploadTask::class.java,
mockRepositoryDetector
)
testedTask.uploader = mockUploader
fakeApiKey = ApiKey(
Expand All @@ -111,8 +112,6 @@ internal class DdNdkSymbolFileUploadTaskTest {
whenever(get()) doReturn fakeBuildId
}

testedTask.repositoryDetector = mockRepositoryDetector

val fakeConfiguration = with(DdExtensionConfiguration()) {
versionName = fakeVersion
serviceName = fakeService
Expand Down

0 comments on commit 739345e

Please sign in to comment.