This is an automated email from the ASF dual-hosted git repository. alexey pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push: new 64eeb0d9a Add code coverage support for Java 64eeb0d9a is described below commit 64eeb0d9a3767923286825139f7ca28bb3a757ad Author: Marton Greber <greber...@gmail.com> AuthorDate: Thu May 15 12:19:29 2025 +0000 Add code coverage support for Java This change adds JaCoCo-based code coverage support for the Java modules in the project. The coverage data is collected during test runs and can be viewed in HTML format using the `./gradlew jacocoAggregatedReport` task. With this setup, it's now possible to generate and publish both C++ and Java coverage reports from a single Jenkins job. As demonstrated on https://jenkins.kudu.apache.org/job/coverage/, there's no need to configure and maintain separate jobs for each language. Additionally, a small script runs `jacocoLogAggregatedCoverage` and appends the aggregated JaCoCo metrics (e.g., summary line coverage) to the bottom of the generated report. This step is necessary because JaCoCo does not include these summary values in the HTML report by default. Change-Id: I15816adb14785eade28581f75918f6848457d190 Reviewed-on: http://gerrit.cloudera.org:8080/22915 Tested-by: Kudu Jenkins Reviewed-by: Alexey Serbin <ale...@apache.org> --- build-support/jenkins/build-and-test.sh | 27 ++++++++++++++++---- build-support/process_jacoco_report.sh | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/build-support/jenkins/build-and-test.sh b/build-support/jenkins/build-and-test.sh index f69bcd55f..5a9188fd4 100755 --- a/build-support/jenkins/build-and-test.sh +++ b/build-support/jenkins/build-and-test.sh @@ -246,9 +246,9 @@ elif [ "$BUILD_TYPE" = "COVERAGE" ]; then CMAKE_BUILD=debug EXTRA_BUILD_FLAGS="-DKUDU_GENERATE_COVERAGE=1" DO_COVERAGE=1 + BUILD_JAVA=1 - # We currently dont capture coverage for Java or Python. - BUILD_JAVA=0 + # We currently dont capture coverage for Python. BUILD_PYTHON=0 BUILD_PYTHON3=0 elif [ "$BUILD_TYPE" = "LINT" ]; then @@ -597,9 +597,26 @@ if [ "$BUILD_JAVA" == "1" ]; then FAILURES="$FAILURES"$'Could not submit Java distributed test job\n' fi else - if ! ./gradlew $EXTRA_GRADLE_FLAGS clean test $EXTRA_GRADLE_TEST_FLAGS; then - TESTS_FAILED=1 - FAILURES="$FAILURES"$'Java Gradle build/test failed\n' + if [ "$DO_COVERAGE" == "1" ]; then + # Clean previous report results + rm -rf ./build + + # jacocoAggregatedReport will trigger test execution if necessary. + if ! ./gradlew $EXTRA_GRADLE_FLAGS clean jacocoAggregatedReport; then + TESTS_FAILED=1 + EXIT_STATUS=1 + FAILURES="$FAILURES"$'Java Gradle test/coverage aggregation failed\n' + fi + + if ! $SOURCE_ROOT/build-support/process_jacoco_report.sh; then + EXIT_STATUS=1 + FAILURES="$FAILURES"$'Java Jacoco report processing failed\n' + fi + else + if ! ./gradlew $EXTRA_GRADLE_FLAGS clean test $EXTRA_GRADLE_TEST_FLAGS; then + TESTS_FAILED=1 + FAILURES="$FAILURES"$'Java Gradle build/test failed\n' + fi fi fi set +x diff --git a/build-support/process_jacoco_report.sh b/build-support/process_jacoco_report.sh new file mode 100755 index 000000000..adcefc348 --- /dev/null +++ b/build-support/process_jacoco_report.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# This script should be run from the '$KUDU_HOME/java' directory. +set -euo pipefail + +SUMMARY_FILE="build/jacocoLogAggregatedCoverage.txt" +HTML_REPORT="build/reports/jacoco/jacocoAggregatedReport/html/index.html" + +echo "Running JaCoCo CLI summary..." +# Run the jacocoLogAggregatedCoverage task and extract only the summary section +# (starting with "Test Coverage:" until the next blank line), stripping all other Gradle logs. +if ! ./gradlew jacocoLogAggregatedCoverage | awk '/^Test Coverage:/,/^$/' > "$SUMMARY_FILE"; then + echo "Gradle jacocoLogAggregatedCoverage task failed." + exit 1 +fi + +if [ ! -f "$HTML_REPORT" ]; then + echo "HTML report not found at $HTML_REPORT" + exit 1 +fi + +echo "Appending summary to HTML report..." +{ + echo "<pre>" + cat "$SUMMARY_FILE" + echo "</pre>" +} >> "$HTML_REPORT" +echo "Summary appended to $HTML_REPORT"