-
Notifications
You must be signed in to change notification settings - Fork 81
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
stanbrub
wants to merge
3
commits into
deephaven:main
Choose a base branch
from
stanbrub:fix-java-coverage-enabled-in-build
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,8 @@ 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @niloc132; I wonder if we should unconditionally apply the jacoco plugin. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Overview | ||
|
||
Code coverage for Deephaven Community Core manages multiple languages like Java, Python, R, Go and C++. This is handled in the gradle build at the individual project level but also supports collection of normalized results rolled up to the top level. For convenience, both top-level Java HTML and a top-level all-language CSV are created. | ||
|
||
## Running for Coverage | ||
|
||
A typical run looks like the following that is run from the root of the multi-project build | ||
``` | ||
./gradlew -Pcoverage.enabled=true check | ||
./gradlew -Pcoverage.enabled=true testSerial | ||
./gradlew -Pcoverage.enabled=true testParallel | ||
./gradlew -Pcoverage.enabled=true testOutOfBand | ||
./gradlew -Pcoverage.enabled=true coverage | ||
./gradlew -Pcoverage.enabled=true coverage-merge | ||
``` | ||
Running the second command is not contingent upon the first command succeeding. It merely collects what coverage is available. | ||
|
||
## Result Files | ||
|
||
Results for individual project coverage are stored in the project's _build_ output directory. Depending on the language and coverage tools, there will be different result files with slightly different locations and names. For example, Java coverage could produce a binary _jacoco.exec_ file, while python coverage produces a tabbed text file. | ||
|
||
Aggregated results produce a merged CSV file for each language under the top-level _build_ directory. Those CSV files are further merged into one _all-coverage.csv_. | ||
|
||
## Exclusion Filters | ||
|
||
In some cases, there may be a need to exclude some packages from coverage, even though they may be used during testing. For example, some Java classes used in GRPC are generated. The expectation is that the generator mechanism has already been tested and should produce viable classes. Including coverage for those classes in the results as zero coverage causes unnecessary noise and makes it harder to track coverage overall. | ||
|
||
To avoid unneeded coverage, the file _exclude-packages.txt_ can be used. This is a list of values to be excluded if they match the "Package" column in the coverage CSV. These are exact values and not wildcards. | ||
|
||
## File Layout | ||
|
||
Top-level Build Directory (Some languages TBD) | ||
- `coverage/` This project's directory | ||
- `gather-coverage.py` Gather and normalize coverage for all languages | ||
- `exclude-packages.txt` A list of packages to exclude from aggregated results | ||
- `buildSrc/src/main/groovy/` | ||
- `io.deephaven.java-jacoco-conventions.gradle` Applied to run coverage on Java projects | ||
- `io.deephaven.java-test-conventions.gradle` Applies the above conditionally base on the _coverage.enabled_ property | ||
- `coverage/build/reports/coverage/` | ||
- `java-coverage.csv` Normalized coverage from all Java projects | ||
- `python-coverage.py` Normalized coverage from all Python projects | ||
- `cplus-coverage.py` Normalized coverage from all C++ projects | ||
- `r-coverage.py` Normalized coverage from all R projects | ||
- `go-coverage.oy` Normalized coverage from all Go projects | ||
- `all-coverage.csv` Normalized and filtered coverage from all covered projects | ||
- `coverage/build/reports/jacoco/jacoco-merge/html/` | ||
- `index.html` Root file to view Java coverage down to the branch level (not filtered) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
plugins { | ||
id 'io.deephaven.project.register' | ||
id 'java' | ||
id 'jacoco-report-aggregation' | ||
} | ||
|
||
jacoco { | ||
toolVersion = '0.8.12' | ||
} | ||
|
||
tasks.register("jacoco-merge", JacocoReport) { | ||
def jprojects = rootProject.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 = rootProject.rootDir.absolutePath | ||
executionData fileTree(projRootDir).include("**/build/jacoco/*.exec") | ||
} | ||
|
||
tasks.register("coverage-merge", Exec) { | ||
dependsOn("jacoco-merge") | ||
def projDir = projectDir.absolutePath | ||
def script = projDir + '/gather-coverage.py' | ||
commandLine 'python', script, projDir | ||
standardOutput = System.out | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
io.deephaven.tuple.generated | ||
io.deephaven.engine.table.impl.tuplesource.generated | ||
io.deephaven.proto.backplane.grpc | ||
io.deephaven.proto.backplane.script.grpc | ||
io.deephaven.proto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# | ||
# Copyright (c) 2016-2025 Deephaven Data Labs and Patent Pending | ||
# | ||
import sys, glob, csv, os, shutil | ||
|
||
# Aggregate coverage data for all languages. Each language has a different way of doing | ||
# coverage and each normalization mechanism is used here. Class/file exclusions are | ||
# handled here, since coverage tools are inconsistent or non-functional in that regard. | ||
|
||
proj_root_dir = sys.argv[1] | ||
script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
coverage_dir = proj_root_dir + '/build/reports/coverage' | ||
coverage_output_path = coverage_dir + '/all-coverage.csv' | ||
coverage_input_glob = coverage_dir + '/*-coverage.csv' | ||
exclude_path = script_dir + '/exclude-packages.txt' | ||
|
||
if os.path.exists(coverage_dir): | ||
shutil.rmtree(coverage_dir) | ||
os.makedirs(coverage_dir) | ||
|
||
# Aggregate and normalize coverage for java projects | ||
input_glob = proj_root_dir + '/build/reports/jacoco/jacoco-merge/jacoco-merge.csv' | ||
with open(f'{coverage_dir}/java-coverage.csv', 'w', newline='') as outfile: | ||
csv_writer = csv.writer(outfile) | ||
csv_writer.writerow(['Language','Project','Package','Class','Missed','Covered']) | ||
for filename in glob.glob(input_glob, recursive = True): | ||
with open(filename, 'r') as csv_in: | ||
csv_reader = csv.reader(csv_in) | ||
next(csv_reader, None) | ||
for row in csv_reader: | ||
new_row = ['java',row[0],row[1],row[2],row[3],row[4]] | ||
csv_writer.writerow(new_row) | ||
|
||
# Load packages to be excluded from the aggregated coverage CSV | ||
with open(exclude_path) as f: | ||
excludes = [line.strip() for line in f] | ||
|
||
# Collect coverage CSVs into a single CSV without lines containing exclusions | ||
with open(coverage_output_path, 'w', newline='') as outfile: | ||
csv_writer = csv.writer(outfile) | ||
for csv_file in glob.glob(coverage_input_glob): | ||
with open(csv_file, 'r') as csv_in: | ||
for row in csv.reader(csv_in): | ||
if row[2] in excludes: continue | ||
new_row = [row[0],row[1],row[2],row[3],row[4],row[5]] | ||
csv_writer.writerow(new_row) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.deephaven.project.ProjectType=BASIC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?