From 52467695b1534a8098e8936a3a849c02b2ff98c4 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Sat, 20 Mar 2021 13:09:59 +0100 Subject: build: Add support for aggregate code coverage results This change adds support for aggregating code coverage results from the different modules. --- .../src/main/kotlin/jacoco-aggregation.gradle.kts | 26 ++++++++++------- .../src/main/kotlin/jacoco-conventions.gradle.kts | 33 ++++++++++++++++++++++ 2 files changed, 49 insertions(+), 10 deletions(-) (limited to 'simulator/buildSrc/src') diff --git a/simulator/buildSrc/src/main/kotlin/jacoco-aggregation.gradle.kts b/simulator/buildSrc/src/main/kotlin/jacoco-aggregation.gradle.kts index 8c07fdea..3e8aa741 100644 --- a/simulator/buildSrc/src/main/kotlin/jacoco-aggregation.gradle.kts +++ b/simulator/buildSrc/src/main/kotlin/jacoco-aggregation.gradle.kts @@ -32,19 +32,25 @@ repositories { mavenCentral() } -task("jacocoTestReport") { +tasks.register("codeCoverageReport") { group = "Coverage reports" - description = "Generates an aggregate report from all subprojects" + description = "Generates an aggregate report based on all subprojects" - val jacocoReportTasks = subprojects.map { it.tasks.withType() } - dependsOn(jacocoReportTasks) - executionData(jacocoReportTasks) + reports { + xml.isEnabled = true + xml.destination = file("${buildDir}/reports/jacoco/report.xml") - subprojects.forEach { testedProject -> - val sourceSets = testedProject.convention.findPlugin(JavaPluginConvention::class)?.sourceSets ?: return@forEach + html.isEnabled = true + } - this@task.additionalSourceDirs.from(sourceSets["main"].allSource.srcDirs) - this@task.sourceDirectories.from(sourceSets["main"].allSource.srcDirs) - this@task.classDirectories.from(sourceSets["main"].output) + subprojects { + this@subprojects.plugins.withType().configureEach { + this@subprojects.tasks.matching { + it.extensions.findByType() != null } + .configureEach { + sourceSets(this@subprojects.the().named("main").get()) + executionData(this) + } + } } } diff --git a/simulator/buildSrc/src/main/kotlin/jacoco-conventions.gradle.kts b/simulator/buildSrc/src/main/kotlin/jacoco-conventions.gradle.kts index e0bc2ce4..d0534d4f 100644 --- a/simulator/buildSrc/src/main/kotlin/jacoco-conventions.gradle.kts +++ b/simulator/buildSrc/src/main/kotlin/jacoco-conventions.gradle.kts @@ -30,3 +30,36 @@ tasks.jacocoTestReport { html.isEnabled = true } } + +/* Share sources folder with other projects for aggregated JaCoCo reports */ +configurations.create("transitiveSourcesElements") { + isVisible = false + isCanBeResolved = false + isCanBeConsumed = true + extendsFrom(configurations.implementation.get()) + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("source-folders")) + } + sourceSets.main.get().java.srcDirs.forEach { + outgoing.artifact(it) + } +} + +/* Share the coverage data to be aggregated for the whole product */ +configurations.create("coverageDataElements") { + isVisible = false + isCanBeResolved = false + isCanBeConsumed = true + extendsFrom(configurations.implementation.get()) + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data")) + } + // This will cause the test task to run if the coverage data is requested by the aggregation task + outgoing.artifact(tasks.test.map { task -> + task.extensions.getByType().destinationFile!! + }) +} -- cgit v1.2.3 From 05331ae9927d487ed89733dcb32cb883a0b6bedf Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Sat, 20 Mar 2021 15:58:41 +0100 Subject: ci: Generate test reports for CI builds This change updates the Github Actions workflow configuration to generate test reports for the simulator CI builds. --- .../buildSrc/src/main/kotlin/testing-conventions.gradle.kts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'simulator/buildSrc/src') diff --git a/simulator/buildSrc/src/main/kotlin/testing-conventions.gradle.kts b/simulator/buildSrc/src/main/kotlin/testing-conventions.gradle.kts index 566b765f..f129c282 100644 --- a/simulator/buildSrc/src/main/kotlin/testing-conventions.gradle.kts +++ b/simulator/buildSrc/src/main/kotlin/testing-conventions.gradle.kts @@ -1,7 +1,3 @@ -import org.gradle.kotlin.dsl.`java-library` -import org.gradle.kotlin.dsl.kotlin -import org.gradle.platform.base.Library - /* * Copyright (c) 2021 AtLarge Research * @@ -30,6 +26,11 @@ plugins { tasks.test { useJUnitPlatform() + + reports { + html.isEnabled = true + junitXml.isEnabled = true + } } dependencies { -- cgit v1.2.3