KAFKA-3451: Add basic HTML coverage report generation to gradle

Author: Grant Henke <granthenke@gmail.com>

Reviewers: Gwen Shapira, Ismael Juma, Ewen Cheslack-Postava

Closes #1121 from granthenke/coverage
This commit is contained in:
Grant Henke 2016-03-31 10:07:54 -07:00 committed by Gwen Shapira
parent 9f6a6f9713
commit 623ab1e7c6
4 changed files with 71 additions and 5 deletions

View File

@ -47,6 +47,9 @@ Change the log4j setting in either `clients/src/test/resources/log4j.properties`
./gradlew -i -Dtest.single=RequestResponseSerializationTest core:test
### Generating test coverage reports ###
./gradlew reportCoverage
### Building a binary release gzipped tar ball ###
./gradlew clean
./gradlew releaseTarGz

View File

@ -26,12 +26,15 @@ buildscript {
// For Apache Rat plugin to ignore non-Git files
classpath "org.ajoberstar:grgit:1.5.0"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.12.0'
classpath 'org.scoverage:gradle-scoverage:2.0.1'
}
}
allprojects {
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: "jacoco"
repositories {
mavenCentral()
}
@ -249,8 +252,50 @@ subprojects {
configProperties = [importControlFile: "$rootDir/checkstyle/import-control.xml"]
}
test.dependsOn('checkstyleMain', 'checkstyleTest')
// Ignore core since its a scala project
if (it.path != ':core') {
// NOTE: Gradles Jacoco plugin does not support "offline instrumentation" this means that classes mocked by PowerMock
// may report 0 coverage, since the source was modified after initial instrumentation.
// See https://github.com/jacoco/jacoco/issues/51
jacocoTestReport {
dependsOn tasks.test
sourceSets sourceSets.main
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
}
}
}
// Aggregates all jacoco results into the root project directory
task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
def javaProjects = subprojects.findAll { it.path != ':core' }
description = 'Generates an aggregate report from all subprojects'
dependsOn(javaProjects.test)
additionalSourceDirs = files(javaProjects.sourceSets.main.allSource.srcDirs)
sourceDirectories = files(javaProjects.sourceSets.main.allSource.srcDirs)
classDirectories = files(javaProjects.sourceSets.main.output)
executionData = files(javaProjects.jacocoTestReport.executionData)
reports {
html.enabled = true
xml.enabled = true
}
// workaround to ignore projects that don't have any tests at all
onlyIf = { true }
doFirst {
executionData = files(executionData.findAll { it.exists() })
}
}
task reportCoverage(dependsOn: ['jacocoRootReport', 'core:reportScoverage'])
for ( sv in ['2_10', '2_11'] ) {
String svInDot = sv.replaceAll( "_", ".")
@ -320,6 +365,7 @@ project(':core') {
println "Building project 'core' with Scala version ${versions.scala}"
apply plugin: 'scala'
apply plugin: "org.scoverage"
archivesBaseName = "kafka_${versions.baseScala}"
dependencies {
@ -351,8 +397,21 @@ project(':core') {
testCompile libs.apachedsJdbmPartition
testCompile libs.junit
testCompile libs.scalaTest
scoverage libs.scoveragePlugin
scoverage libs.scoverageRuntime
}
jacocoTestReport.enabled = false
scoverage {
reportDir = file("${rootProject.buildDir}/scoverage")
highlighting = false
}
checkScoverage {
minimumRate = 0.0
}
checkScoverage.shouldRunAfter('test')
configurations {
// manually excludes some unnecessary dependencies
compile.exclude module: 'javax'

View File

@ -452,12 +452,13 @@ class ZkUtils(val zkClient: ZkClient,
} catch {
case e1: ZkBadVersionException =>
optionalChecker match {
case Some(checker) => return checker(this, path, data)
case _ => debug("Checker method is not passed skipping zkData match")
}
warn("Conditional update of path %s with data %s and expected version %d failed due to %s".format(path, data,
expectVersion, e1.getMessage))
case Some(checker) => checker(this, path, data)
case _ =>
debug("Checker method is not passed skipping zkData match")
warn("Conditional update of path %s with data %s and expected version %d failed due to %s"
.format(path, data,expectVersion, e1.getMessage))
(false, -1)
}
case e2: Exception =>
warn("Conditional update of path %s with data %s and expected version %d failed due to %s".format(path, data,
expectVersion, e2.getMessage))

View File

@ -41,6 +41,7 @@ versions += [
rocksDB: "4.1.0",
scalaTest: "2.2.6",
scalaParserCombinators: "1.0.4",
scoverage: "1.1.1",
slf4j: "1.7.18",
snappy: "1.1.2.1",
zkclient: "0.8",
@ -96,6 +97,8 @@ libs += [
scalaCompiler: "org.scala-lang:scala-compiler:$versions.scala",
scalaTest: "org.scalatest:scalatest_$versions.baseScala:$versions.scalaTest",
scalaParserCombinators: "org.scala-lang.modules:scala-parser-combinators_$versions.baseScala:$versions.scalaParserCombinators",
scoveragePlugin: "org.scoverage:scalac-scoverage-plugin_$versions.baseScala:$versions.scoverage",
scoverageRuntime: "org.scoverage:scalac-scoverage-runtime_$versions.baseScala:$versions.scoverage",
slf4jApi: "org.slf4j:slf4j-api:$versions.slf4j",
slf4jlog4j: "org.slf4j:slf4j-log4j12:$versions.slf4j",
snappy: "org.xerial.snappy:snappy-java:$versions.snappy",