diff options
Diffstat (limited to 'simulator/buildSrc/src')
3 files changed, 54 insertions, 14 deletions
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<JacocoReport>("jacocoTestReport") { +tasks.register<JacocoReport>("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<JacocoReport>() } - 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<JacocoPlugin>().configureEach { + this@subprojects.tasks.matching { + it.extensions.findByType<JacocoTaskExtension>() != null } + .configureEach { + sourceSets(this@subprojects.the<SourceSetContainer>().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<JacocoTaskExtension>().destinationFile!! + }) +} 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 { |
