5 MIN_COVERAGE_PERCENT="$2"
6 ROOT_SOURCES_MODULE_POM="$3"
7 LOG_FILE=target/check-coverage.log
9 function coverage_from_report() {
10 local xpath_expr="string(/report/counter[@type='INSTRUCTION']/@$1)"
11 xmllint --xpath "${xpath_expr}" "$JACOCO_REPORT" 2>> ${LOG_FILE}
14 function check_preconditions() {
15 local num_deps=$(grep -c 'project\.parent\.groupId' pom.xml)
16 local num_submodules=$(grep -c '<module>' ${ROOT_SOURCES_MODULE_POM})
17 local difference=$((${num_submodules}-${num_deps}))
19 if [[ ${difference} -ne 0 ]]; then
20 echo "Not all modules are included in the coverage report."
21 echo "Verify if all submodules of hv-collector-sources module are included as a dependency to hv-collector-coverage module."
22 echo "Number of missing modules: ${difference}"
27 function check_coverage() {
28 local missed=$(coverage_from_report missed)
29 local covered=$(coverage_from_report covered)
30 local total=$(($missed + $covered))
31 local coverage=$((100 * $covered / $total))
33 if [[ $(wc -c < ${LOG_FILE}) > 0 ]]; then
34 echo "Warnings from xpath evaluation:"
39 echo "Coverage: $coverage% (covered/total: $covered/$total)"
41 if [[ ${coverage} -lt ${MIN_COVERAGE_PERCENT} ]]; then
42 echo "Coverage is too low. Minimum coverage: $MIN_COVERAGE_PERCENT%"
47 check_preconditions || exit 1
48 check_coverage || exit 2