Skip to content

Commit

Permalink
Collect code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsi committed Feb 28, 2020
1 parent 681394d commit 104f2b9
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 4 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ jobs:
java-version: 8
- name: 'Test'
run: |
# TODO: run SlowTests as well
echo enable_ssl_tests=true > ssltest.local.properties
# '-PincludeTestTags=!org.postgresql.test.SlowTests'
./gradlew --no-parallel --no-daemon -PskipReplicationTests -Pport=${{ job.services.postgres.ports['5432'] }} test
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ matrix:
- JDK=11
- TZ=America/New_York # flips between −05:00 and −04:00
- TEST_CLIENTS=Y
- COVERAGE=Y

# Deploy snapshots to Maven Central
after_success:
Expand Down
2 changes: 1 addition & 1 deletion .travis/travis_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fi

if [[ "${COVERAGE}" == *"Y"* ]];
then
GRADLE_ARGS="$GRADLE_ARGS "
GRADLE_ARGS="$GRADLE_ARGS jacocoReport"
fi

if [[ "${JDK}" == *"9"* ]];
Expand Down
60 changes: 59 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ plugins {
publishing
// Verification
checkstyle
jacoco
id("com.github.autostyle")
id("com.github.spotbugs")
id("org.owasp.dependencycheck")
Expand All @@ -28,7 +29,7 @@ plugins {
id("com.github.vlsi.stage-vote-release")
}

fun reportsForHumans() = !(System.getenv()["CI"]?.toBoolean() ?: false)
fun reportsForHumans() = !(System.getenv()["CI"]?.toBoolean() ?: props.bool("CI"))

val lastEditYear = 2019 // TODO: by extra(lastEditYear("$rootDir/LICENSE"))

Expand All @@ -45,6 +46,9 @@ val includeTestTags by props("") // e.g. !org.postgresql.test.SlowTests
val useGpgCmd by props()
val slowSuiteLogThreshold = stringProperty("slowSuiteLogThreshold")?.toLong() ?: 0
val slowTestLogThreshold = stringProperty("slowTestLogThreshold")?.toLong() ?: 2000
val jacocoEnabled by extra {
props.bool("coverage") || gradle.startParameter.taskNames.any { it.contains("jacoco") }
}

ide {
// TODO: set copyright to PostgreSQL Global Development Group
Expand Down Expand Up @@ -75,6 +79,11 @@ val isReleaseVersion = rootProject.releaseParams.release.get()

val licenseHeaderFile = file("config/license.header.java")

val jacocoReport by tasks.registering(JacocoReport::class) {
group = "Coverage reports"
description = "Generates an aggregate report from all subprojects"
}

allprojects {
group = "org.postgresql"
version = buildVersion
Expand All @@ -91,6 +100,9 @@ allprojects {
val javaUsed = file("src/main/java").isDirectory
if (javaUsed) {
apply(plugin = "java-library")
if (jacocoEnabled) {
apply(plugin = "jacoco")
}
}

plugins.withId("java-library") {
Expand Down Expand Up @@ -186,6 +198,43 @@ allprojects {
}
}

plugins.withType<JacocoPlugin> {
the<JacocoPluginExtension>().toolVersion = "jacoco".v

val testTasks = tasks.withType<Test>()
val javaExecTasks = tasks.withType<JavaExec>()
// This configuration must be postponed since JacocoTaskExtension might be added inside
// configure block of a task (== before this code is run). See :src:dist-check:createBatchTask
afterEvaluate {
for (t in arrayOf(testTasks, javaExecTasks)) {
t.configureEach {
extensions.findByType<JacocoTaskExtension>()?.apply {
// Do not collect coverage when not asked (e.g. via jacocoReport or -Pcoverage)
isEnabled = jacocoEnabled
// We don't want to collect coverage for third-party classes
includes?.add("org.postgresql.*")
}
}
}
}

jacocoReport {
// Note: this creates a lazy collection
// Some of the projects might fail to create a file (e.g. no tests or no coverage),
// So we check for file existence. Otherwise JacocoMerge would fail
val execFiles =
files(testTasks, javaExecTasks).filter { it.exists() && it.name.endsWith(".exec") }
executionData(execFiles)
}

tasks.withType<JacocoReport>().configureEach {
reports {
html.isEnabled = reportsForHumans()
xml.isEnabled = !reportsForHumans()
}
}
}

tasks {
withType<Javadoc>().configureEach {
(options as StandardJavadocDocletOptions).apply {
Expand Down Expand Up @@ -258,6 +307,15 @@ allprojects {
}
}
}
if (jacocoEnabled) {
// Add each project to combined report
val mainCode = sourceSets["main"]
jacocoReport.configure {
additionalSourceDirs.from(mainCode.allJava.srcDirs)
sourceDirectories.from(mainCode.allSource.srcDirs)
classDirectories.from(mainCode.output)
}
}
if (enableSpotBugs) {
apply(plugin = "com.github.spotbugs")
spotbugs {
Expand Down
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
codecov:
notify:
after_n_builds: 11
after_n_builds: 1
require_ci_to_pass: false
comment:
layout: header, changes, diff
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ org.owasp.dependencycheck.version=5.2.2
# docker-maven-plugin.version=1.2.0

# Tools
jacoco.version=0.8.5
checkstyle.version=8.18
spotbugs.version=3.1.11

Expand Down

0 comments on commit 104f2b9

Please sign in to comment.