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-18379: Java Code Coverage #6576

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stanbrub
Copy link
Contributor

@stanbrub stanbrub commented Jan 17, 2025

  • Build runs Jacoco Plugin on all Java projects
  • Jacoco Aggregator Plugin pulls up HTML results into an index.html
  • Custom merge for normalized CSV (pattern is there for other languages not yet added)
  • Coverage-exclusion filter for things like generated code
  • Added so that it does not affect any existing gradle tasks like check
  • See README.md for more info

This is the first step towards unified code coverage at the class level. It is not meant to provide fined-grained detail but instead a level that can point to areas of code that need test attention. Devs can then use IDE tools for more detail.

When this is added to a dispatch workflow, the Java HTML coverage hierarchy will be a collected artifact and will have a lot of detail like branch coverage.

@stanbrub stanbrub self-assigned this Jan 17, 2025
@@ -84,6 +85,35 @@ tasks.register('smoke') {
it.dependsOn project(':Generators').tasks.findByName(LifecycleBasePlugin.CHECK_TASK_NAME)
}

tasks.register("coverage") {
System.setProperty "coverageEnabled", "true"
Copy link
Member

Choose a reason for hiding this comment

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

We should not be configuring system properties based on when this task is executed... we should be using gradle properties for parts of the build system we want configurable.

Comment on lines +2 to +3
if (Boolean.getBoolean("coverageEnabled")) {
apply plugin: 'jacoco'
Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +90 to +115
allprojects.findAll { p-> p.plugins.hasPlugin('java') }.each {
it.apply(['from':rootProject.file("coverage/jacoco.gradle")])
}
}

tasks.register("coverage-merge", JacocoReport) {
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")
doLast {
def stdout = new StringBuilder(), stderr = new StringBuilder()
def task = ('python ' + projRootDir + '/coverage/all-coverage.py ' + projRootDir).execute()
task.consumeProcessOutput(stdout, stderr)
task.waitFor()
println(stdout)
println(stderr)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

We should not be building in this logic at the root build.gradle level; we have buildSrc plugins to do this.

Comment on lines +112 to +113
println(stdout)
println(stderr)
Copy link
Member

Choose a reason for hiding this comment

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

Here on purpose?

}
def projRootDir = project.rootDir.absolutePath
executionData fileTree(projRootDir).include("**/build/jacoco/*.exec")
doLast {
Copy link
Member

Choose a reason for hiding this comment

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

It is probably bad to attach a doLast to an existing Task type; likely, you'll want a separate task to depend on the output of JacocoReport.

@@ -1,6 +1,7 @@
plugins {
id 'base'
id 'io.deephaven.project.register'
id 'jacoco-report-aggregation'
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused... is this plugin actually being used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants