Gradle jacocoReport and jacocoBranchReport now only use subprojects with Java sourceSets

This commit is contained in:
ghidra4 2019-04-24 15:06:39 -04:00
parent 55f31e550d
commit cfc51a00ea
2 changed files with 43 additions and 20 deletions

View File

@ -5,16 +5,12 @@
A gradle project can add itself to the jacoco run by adding the following to its build.gradle A gradle project can add itself to the jacoco run by adding the following to its build.gradle
file: file:
apply from: "$rootProject.projectDir/gradle/support/jacocoProject.gradle" apply from: "$rootProject.projectDir/gradle/jacocoProject.gradle"
*****************************************************************************************/ *****************************************************************************************/
// Apply jacoco plugin to root and subprojects. This will create coverage files for each java Test task. // Apply jacoco plugin to subprojects. This will create coverage files for each java Test task.
if (rootProject.ext.jacocoEnabled) { if (rootProject.ext.jacocoEnabled) {
apply plugin:'jacoco' apply plugin:'jacoco'
dependencies {
jacocoAnt 'org.jacoco:org.jacoco.ant:0.8.2'
jacocoAgent 'org.jacoco:org.jacoco.agent:0.8.2'
}
} }
// Clean any jacoco files that may have been left behind previously. // Clean any jacoco files that may have been left behind previously.

View File

@ -10,9 +10,18 @@ rootProject.ext.jacocoEnabled = (rootProject.gradle.startParameter.taskNames.con
rootProject.gradle.startParameter.taskNames.contains('jacocoBranchReport') || rootProject.gradle.startParameter.taskNames.contains('jacocoBranchReport') ||
rootProject.gradle.startParameter.taskNames.contains('jacocoReport')) rootProject.gradle.startParameter.taskNames.contains('jacocoReport'))
if (project.jacocoEnabled) { if (project.jacocoEnabled) {
// jacoco plugin needs to be in the root-level to get the jacocoAnt and jacocoAgent dependencies below
// and any subproject (via jacocoProject.gradle)
apply plugin:'jacoco'
// set classpath dependency for root-level tasks defined in this file.
dependencies {
jacocoAnt 'org.jacoco:org.jacoco.ant:0.8.2'
jacocoAgent 'org.jacoco:org.jacoco.agent:0.8.2'
}
def String jacocoRootExecPath = "$buildDir/jacoco/jacocoMerge.exec" def String jacocoRootExecPath = "$buildDir/jacoco/jacocoMerge.exec"
def numFoundExecutionFiles = 0 // number of jacoco data files found in subprojects def numFoundExecutionFiles = 0 // number of jacoco data files found in subprojects
@ -105,8 +114,25 @@ List excludesList = generateExcludesList()
} }
} }
sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs) // Turn on html reports, 'doFirst' may disable this later on.
classDirectories = files(subprojects.sourceSets.main.output) reports {
html.enabled = true
xml.enabled = false
}
// Output info before execution.
doFirst {
// Only report on subprojects with Java sourceSets
def subprojectsWithJava = []
subprojects { p ->
p.plugins.withType(JavaPlugin) {
subprojectsWithJava += p
}
}
sourceDirectories = files(subprojectsWithJava.sourceSets.main.allSource.srcDirs)
classDirectories = files(subprojectsWithJava.sourceSets.main.output)
logger.debug("jacocoBranchReport: Files to include: " + filesToInclude) logger.debug("jacocoBranchReport: Files to include: " + filesToInclude)
@ -118,14 +144,6 @@ List excludesList = generateExcludesList()
}) })
} }
// Turn on html reports, 'doFirst' may disable this later on.
reports {
html.enabled = true
xml.enabled = false
}
// Output info before execution.
doFirst {
println "jacocoBranchReport: Found $filesToInclude.size Java files to filter on branch '$branchName' and revision $lastRevision from origin '$jacoco_origin'" println "jacocoBranchReport: Found $filesToInclude.size Java files to filter on branch '$branchName' and revision $lastRevision from origin '$jacoco_origin'"
println "jacocoBranchReport: Number of jacoco execution data files found from jacocoMerge: $numFoundExecutionFiles" println "jacocoBranchReport: Number of jacoco execution data files found from jacocoMerge: $numFoundExecutionFiles"
// Turn off reports if no files to report or no jacoco data files found. Otherwise the jacoco task will create empty report. // Turn off reports if no files to report or no jacoco data files found. Otherwise the jacoco task will create empty report.
@ -142,15 +160,24 @@ List excludesList = generateExcludesList()
} }
/********************************************************************************* /*********************************************************************************
* Task to generate an aggregate jacoco report from all subprojects * Task to generate an aggregate jacoco report from subprojects with Java sourceSets.
*********************************************************************************/ *********************************************************************************/
task jacocoReport(type: JacocoReport, group: 'Coverage reports') { task jacocoReport(type: JacocoReport, group: 'Coverage reports') {
description = 'Generates an aggregate Jacoco report from all subprojects' description = 'Generates an aggregate Jacoco report from all subprojects'
dependsOn ":jacocoMerge" dependsOn ":jacocoMerge"
executionData new File(jacocoRootExecPath) executionData new File(jacocoRootExecPath)
sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs) // Only report on subprojects with Java sourceSets
classDirectories = files(subprojects.sourceSets.main.output) def subprojectsWithJava = []
subprojects { p ->
p.plugins.withType(JavaPlugin) {
subprojectsWithJava += p
}
}
sourceDirectories = files(subprojectsWithJava.sourceSets.main.allSource.srcDirs)
classDirectories = files(subprojectsWithJava.sourceSets.main.output)
classDirectories = files(classDirectories.files.collect { classDirectories = files(classDirectories.files.collect {
fileTree(dir: it, exclude: excludesList) fileTree(dir: it, exclude: excludesList)
}) })