Skip to content

Commit

Permalink
Java coverage fixes (#3253)
Browse files Browse the repository at this point in the history
  • Loading branch information
externl authored Dec 11, 2024
1 parent a87b04e commit 86d1ec6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 19 deletions.
25 changes: 6 additions & 19 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Generate API Coverage

on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 0" # Run every Sunday at midnight

jobs:
generate-cpp-coverage-report:
Expand All @@ -17,18 +19,18 @@ jobs:

- name: Generate C++ Coverage
working-directory: ./cpp
run: ../scripts/generate-code-coverage.sh
run: ../scripts/generate-cpp-code-coverage.sh

- name: Generate C++ Coverage Reports
working-directory: ./cpp
run: |
for binary in bin/*; do
../scripts/generate-code-coverage.sh "$binary"
../scripts/generate-cpp-code-coverage.sh "$binary"
done
for library in lib/*; do
if [[ $library =~ lib/lib[a-zA-Z0-9]+\.dylib ]]; then
../scripts/generate-code-coverage.sh "$library"
../scripts/generate-cpp-code-coverage.sh "$library"
fi
done
Expand Down Expand Up @@ -104,25 +106,10 @@ jobs:
with:
use_ccache: false

- name: Build
run: |
make -C cpp srcs
make -C java
- name: Generate Java Coverage
working-directory: ./java
run: |
wget https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/0.8.12/org.jacoco.cli-0.8.12-nodeps.jar
wget https://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.8.12/org.jacoco.agent-0.8.12-runtime.jar
python3 allTests.py --all --workers=4 --debug --jacoco $(pwd)/org.jacoco.agent-0.8.12-runtime.jar
args=""
for pkg in src/*; do
args="$args --classfiles $pkg/build/classes/ --sourcefiles $pkg/src/main/java/"
done
java -jar org.jacoco.cli-0.8.12-nodeps.jar report $(find . -name \*.jacoco.exec) $args --html coverage
../scripts/generate-java-code-coverage.sh
- name: Sync Documentation to S3
working-directory: ./java/coverage
Expand Down
File renamed without changes.
56 changes: 56 additions & 0 deletions scripts/generate-java-code-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

JACOCO_VERSION=0.8.12

if [ "$(basename "$(pwd)")" != "java" ]; then
echo "This script must be run from the 'java' directory."
exit 1
fi

make -C ../cpp srcs
make

if [ ! -f org.jacoco.cli-nodeps.jar ]; then
wget https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/$JACOCO_VERSION/org.jacoco.cli-$JACOCO_VERSION-nodeps.jar -O org.jacoco.cli-nodeps.jar
fi

if [ ! -f org.jacoco.agent-runtime.jar ]; then
wget https://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/$JACOCO_VERSION/org.jacoco.agent-$JACOCO_VERSION-runtime.jar -O org.jacoco.agent-runtime.jar
fi

python3 allTests.py --all --workers=4 --debug --jacoco $(pwd)/org.jacoco.agent-runtime.jar

# We don't want any coverage for generated code. We remove their class files and any inner classes.
jacocoArgs=()
for dir in src/*; do
# Skip non-directories.
[ -d "$dir" ] || continue

# Skip IceGridGUI
[ "$(basename "$dir")" == "IceGridGUI" ] && continue

jacocoArgs+=(--classfiles "$dir/build/classes/java/main")
jacocoArgs+=(--sourcefiles "$dir/src/main/java")

# Iterate over the generated Java files and remove the associated class and inner class files.
IFS=$'\n'; set -f
for javaFile in $(find "$dir" -name '*.java' | grep generated-src); do
# Remove everything up to generated-src/ from the path.
relativeJavaRoot=${javaFile#*generated-src/}
classDir="$dir/build/classes/java/main"
classFile=${classDir}/${relativeJavaRoot%.java}.class
# Remove the class file (a/b/Foo.class)
rm "$classFile"
# Remove any inner classes (a/b/Foo$*.class)
find "$(dirname "$classFile")" -name "$(basename -- "$classFile" ".class")\$*.class" -exec rm {} \;

done
unset IFS; set +f
done

IFS=$'\n'; set -f
# shellcheck disable=SC2207
coverageFiles=($(find . -name \*.jacoco.exec))
unset IFS; set +f

java -jar org.jacoco.cli-nodeps.jar report "${coverageFiles[@]}" "${jacocoArgs[@]}" --html coverage

0 comments on commit 86d1ec6

Please sign in to comment.