Skip to content

Commit

Permalink
Allow to set aggregateTestCoverage from root project
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzo committed Jun 28, 2024
1 parent b86874b commit b3e1891
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

package io.github.gmazzo.android.test.aggregation

import org.gradle.api.DomainObjectSet
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.provider.Property
Expand All @@ -13,29 +12,23 @@ import org.gradle.kotlin.dsl.typeOf

internal abstract class AndroidTestBaseAggregationPlugin : Plugin<Project> {

abstract val extendedProperties: DomainObjectSet<Property<*>>

override fun apply(target: Project): Unit = with(target) {
apply(plugin = "com.android.base")

android.buildTypes.configureEach {
extensions.add(
typeOf<Property<Boolean>>(),
::aggregateTestCoverage.name,
objects.property<Boolean>().also(extendedProperties::add)
objects.property<Boolean>()
)
}
android.productFlavors.configureEach {
extensions.add(
typeOf<Property<Boolean>>(),
::aggregateTestCoverage.name,
objects.property<Boolean>().also(extendedProperties::add)
objects.property<Boolean>()
)
}

androidComponents.finalizeDsl {
extendedProperties.all { finalizeValue() }
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.gradle.kotlin.dsl.USAGE_TEST_AGGREGATION
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getAt
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.listProperty
import org.gradle.kotlin.dsl.named
Expand All @@ -46,14 +45,14 @@ abstract class AndroidTestCoverageAggregationPlugin : Plugin<Project> {
val jacocoVariants = objects.namedDomainObjectSet(Variant::class)

androidComponents.onVariants { variant ->
val buildType = android.buildTypes[variant.buildType!!]

if ((variant as? HasUnitTest)?.unitTest != null &&
buildType.enableUnitTestCoverage &&
android.shouldAggregate(variant)
) {
jacocoVariants.add(variant)
}
jacocoVariants.addAllLater(provider {
val buildType = android.buildTypes[variant.buildType!!]
val aggregate = (variant as? HasUnitTest)?.unitTest != null &&
buildType.enableUnitTestCoverage &&
android.shouldAggregate(variant)

if (aggregate) listOf(variant) else emptyList()
})
}

configurations.create("codeCoverageExecutionData") {
Expand Down Expand Up @@ -161,7 +160,6 @@ abstract class AndroidTestCoverageAggregationPlugin : Plugin<Project> {
val robolectricSupport = objects.property<Boolean>()
.convention(true)
.apply { finalizeValueOnRead() }
.also(plugins.getAt(AndroidTestBaseAggregationPlugin::class).extendedProperties::add)

(android as ExtensionAware).extensions
.add("coverageRobolectricSupport", robolectricSupport)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ abstract class AndroidTestResultsAggregationPlugin : Plugin<Project> {
}

androidComponents.onVariants { variant ->
if ((variant as? HasUnitTest)?.unitTest != null && android.shouldAggregate(variant)) {
afterEvaluate {
val testTask = unitTestTaskOf(variant)!!
testResultsElements.outgoing.artifacts(provider {
val aggregate = (variant as? HasUnitTest)?.unitTest != null && android.shouldAggregate(variant)

testResultsElements.outgoing.artifact(testTask.flatMap { it.binaryResultsDirectory })
}
}
if (aggregate) listOf(unitTestTaskOf(variant)!!.flatMap { it.binaryResultsDirectory }) else emptyList()
})
}
}

Expand Down

0 comments on commit b3e1891

Please sign in to comment.