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

Allow to set aggregateTestCoverage from root project #147

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading