Created
March 16, 2023 20:28
-
-
Save Badbond/0777680409ce28349c792416535940e0 to your computer and use it in GitHub Desktop.
JaCoCo -- Generate HTML report from coverage data and (compiled) source code
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
#!/usr/bin/env bash | |
set -e -u -o pipefail | |
if [[ "${#}" -lt 2 ]]; then | |
echo "Usage: ${0} <path-to-jacococli.jar> [--sourcefiles-matcher=<string>] [ --classfiles-miles-matcher<string>] <source-roots>..." | |
exit 1 | |
fi | |
JACOCO_CLI_LOCAL="$(realpath "${1}")" | |
shift | |
SOURCEFILES_MATCHER='*/src/main/java' | |
CLASSFILES_MATCHER='*/target/classes' | |
while [ "${#}" -gt 0 ]; do | |
case "${1}" in | |
--sourcefiles-matcher) | |
shift | |
SOURCEFILES_MATCHER="${1}" | |
;; | |
--classfiles-matcher) | |
shift | |
CLASSFILES_MATCHER="${1}" | |
;; | |
*) | |
break | |
;; | |
esac | |
done | |
if [[ "${#}" -ne 1 ]]; then | |
echo "No source roots passed." | |
exit 1 | |
fi | |
pushd /tmp/jacoco-export | |
# Generate an HTML report based on the collected data. Note that this command | |
# assumes that the associated source code has been compiled (i.e. that the | |
# `target/classes` directories are present and populated). | |
java -jar "${JACOCO_CLI_LOCAL}" report jacoco.exec --html report \ | |
$(find "${@:1}" -path "${CLASSFILES_MATCHER}" | sed 's/^/--classfiles /') \ | |
$(find "${@:1}" -path "${SOURCEFILES_MATCHER}" | sed 's/^/--sourcefiles /') | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment