Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: DH-18477: Java coverage generated conditionally #6586

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions buildSrc/src/main/groovy/TestTools.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -116,28 +116,6 @@ By default only runs in CI; to run locally:
.replace "${separator}test$separator", "$separator$type$separator"
(report as SimpleReport).outputLocation.set new File(rebased)
}
// this is not part of the standard class; it is glued on later by jacoco plugin;
// we want to give each test it's own output files for jacoco analysis,
// so we don't accidentally stomp on previous output.
// TODO: verify jenkins is analyzing _all_ information here.
if (project.findProperty('jacoco.enabled') == "true") {
(t['jacoco'] as JacocoTaskExtension).with {
destinationFile = project.provider({ new File(project.buildDir, "jacoco/${type}.exec".toString()) } as Callable<File>)
classDumpDir = new File(project.buildDir, "jacoco/${type}Dumps".toString())
}
(project['jacocoTestReport'] as JacocoReport).with {
reports {
JacocoReportsContainer c ->
c.xml.enabled = true
c.csv.enabled = true
c.html.enabled = true
}
}
}

}
if (project.findProperty('jacoco.enabled') == "true") {
project.tasks.findByName('jacocoTestReport').mustRunAfter(t)
}

return t
Expand Down
22 changes: 22 additions & 0 deletions buildSrc/src/main/groovy/io.deephaven.coverage-merge.gradle
stanbrub marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id 'base'
id 'jacoco-report-aggregation'
stanbrub marked this conversation as resolved.
Show resolved Hide resolved
}

jacoco {
toolVersion = '0.8.12'
}

tasks.register("coverage-merge", JacocoReport) {
stanbrub marked this conversation as resolved.
Show resolved Hide resolved
def jprojects = allprojects.findAll { p-> p.plugins.hasPlugin('java') }
additionalSourceDirs = files(jprojects.sourceSets.main.allSource.srcDirs)
sourceDirectories = files(jprojects.sourceSets.main.allSource.srcDirs)
classDirectories = files(jprojects.sourceSets.main.output)
reports {
html.required = true
csv.required = true
xml.required = false
}
def projRootDir = project.rootDir.absolutePath
executionData fileTree(projRootDir).include("**/build/jacoco/*.exec")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@ plugins {
}

jacoco {
toolVersion = '0.8.8'
toolVersion = '0.8.12'
}

test {
jacoco {
destinationFile = layout.buildDirectory.file('jacoco/jacoco.exec').get().asFile
stanbrub marked this conversation as resolved.
Show resolved Hide resolved
}
stanbrub marked this conversation as resolved.
Show resolved Hide resolved
finalizedBy jacocoTestReport
stanbrub marked this conversation as resolved.
Show resolved Hide resolved
}

jacocoTestReport {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to look into hooking up integration tests as part of the coverage path. Right now, it seems like only the "test" task is included for the reporting. https://docs.gradle.org/current/userguide/jacoco_plugin.html#sec:jacoco_tasks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the README.md I have the expected command line for running everything. Are there more than check, testSerial, testParallel, testOutOfBand? How to I run anything that's missing?

dependsOn test
stanbrub marked this conversation as resolved.
Show resolved Hide resolved
reports {
xml.enabled true
csv.enabled true
html.enabled true
csv.required = true
csv.destination = layout.buildDirectory.file('reports/jacoco/java-coverage.csv').get().asFile
xml.required = true
xml.outputLocation = layout.buildDirectory.file('reports/jacoco/java-coverage.xml').get().asFile
html.outputLocation = layout.buildDirectory.dir('reports/jacoco/html')
}
}

project.tasks.withType(Test).all { Test t ->
finalizedBy jacocoTestReport
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ plugins {
id 'java'
}

if (project.findProperty('jacoco.enabled') == 'true') {
// Only load if jacoco enabled; otherwise
// instrumentation of the code is still done.
// Apply Jacoco instrumentation and coverage reporting
if (project.findProperty('coverage.enabled') == 'true') {
Comment on lines +5 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@niloc132; I wonder if we should unconditionally apply the jacoco plugin.

Copy link
Contributor Author

@stanbrub stanbrub Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that affect things like JMH because of instrumentation?

project.apply plugin: 'io.deephaven.java-jacoco-conventions'
rootProject.apply plugin: 'io.deephaven.coverage-merge'
stanbrub marked this conversation as resolved.
Show resolved Hide resolved
}

def testJar = project.tasks.register 'testJar', Jar, { Jar jar ->
Expand Down