From 5a43cbc6531cce9d7bd398d78930cb7b585d4ef8 Mon Sep 17 00:00:00 2001 From: Dana Maxfield Date: Fri, 14 May 2021 23:15:45 -0400 Subject: [PATCH] Fix for code coverage reported to Sonar --- .../com/synopsys/integration/Common.groovy | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/groovy/com/synopsys/integration/Common.groovy b/src/main/groovy/com/synopsys/integration/Common.groovy index cf3c410..f7ffe0b 100644 --- a/src/main/groovy/com/synopsys/integration/Common.groovy +++ b/src/main/groovy/com/synopsys/integration/Common.groovy @@ -310,21 +310,27 @@ abstract class Common implements Plugin { void configureForJacoco(Project project) { project.plugins.apply('jacoco') - Task jacocoTestReport = project.tasks.findByName('jacocoTestReport') - jacocoTestReport.reports { - xml.enabled true - xml.destination project.file("${project.buildDir}/reports/jacoco/report.xml") - html.enabled true - html.destination project.file("${project.buildDir}/reports/jacoco/html") - csv.enabled false - } + def options = ['name': 'codeCoverageReport', 'type': JacocoReport.class, 'dependsOn': project.test, 'group': 'Verification', 'description': 'Generate code coverage report for tests executed in project.'] + Task codeCoverageReport = project.tasks.create(options, { + executionData project.fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec") + + sourceSets project.sourceSets.main + + reports { + xml.enabled true + xml.destination project.file("${project.buildDir}/reports/jacoco/report.xml") + html.enabled true + html.destination project.file("${project.buildDir}/reports/jacoco/html") + csv.enabled false + } + }) } void configureForSonarQube(Project project) { def rootProject = project.rootProject if (project == rootProject) { project.plugins.apply(SonarQubePlugin.class) - project.tasks.getByName('sonarqube').dependsOn(project.tasks.getByName('jacocoTestReport')) + project.tasks.getByName('sonarqube').dependsOn(project.tasks.getByName('codeCoverageReport')) def sonarExcludes = project.ext[PROPERTY_EXCLUDES_FROM_TEST_COVERAGE]