From e7db31bba236041701d1c53768e27a5840e0de30 Mon Sep 17 00:00:00 2001 From: Dora Horvath Date: Fri, 10 Jun 2022 11:25:01 +0200 Subject: [PATCH 1/2] HBASE-26934: Publish code coverage reports to SonarQube --- dev-support/code-coverage/run-coverage.sh | 71 +++++++++++++++++ pom.xml | 94 +++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 dev-support/code-coverage/run-coverage.sh diff --git a/dev-support/code-coverage/run-coverage.sh b/dev-support/code-coverage/run-coverage.sh new file mode 100644 index 0000000000..fec1afe50f --- /dev/null +++ b/dev-support/code-coverage/run-coverage.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env 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. + +usage() { + echo + echo "options:" + echo "-h Display help" + echo "-u SonarQube Host URL" + echo "-l SonarQube Login Credentials" + echo "-k SonarQube Project Key" + echo "-n SonarQube Project Name" + echo + echo "Important:" + echo " The required parameters for publishing the coverage results to SonarQube:" + echo " - Host URL" + echo " - Login Credentials" + echo " - Project Key" + echo +} + +execute() { + SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" + MAIN_POM="${SCRIPT_DIR}/../../pom.xml" + + mvn -B -e -Pclover -Psonar -f "$MAIN_POM" clean install -DskipTests -DskipShade + + mvn -B -e -Pclover -f "$MAIN_POM" test -Dparallel-tests -DtestsThreadCount=8 -Dscale -fn + + mvn -B -e -Pclover -f "$MAIN_POM" clover:aggregate clover:clover + + # If the required parameters are given, the code coverage results are uploaded to the SonarQube Server + if [ -n "$SONAR_LOGIN" ] && [ -n "$SONAR_PROJECT_KEY" ] && [ -n "$SONAR_URL" ]; then + mvn -B -e -Psonar -f "$MAIN_POM" sonar:sonar -Dsonar.projectName="$SONAR_PROJECT_NAME" \ + -Dsonar.host.url="$SONAR_URL" -Dsonar.login="$SONAR_LOGIN" -Dsonar.projectKey="$SONAR_PROJECT_KEY" + fi +} + +while getopts ":u:l:k:n:h" option; do + case $option in + u) SONAR_URL=${OPTARG:-} ;; + l) SONAR_LOGIN=${OPTARG:-} ;; + k) SONAR_PROJECT_KEY=${OPTARG:-} ;; + n) SONAR_PROJECT_NAME=${OPTARG:-} ;; + h) # Display usage + usage + exit + ;; + \?) # Invalid option + echo "Error: Invalid option" + exit + ;; + esac +done + +# Start code analysis +execute diff --git a/pom.xml b/pom.xml index 9138ef58b1..e523eb417b 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,9 @@ 3.0.0-M2 1.0-beta-9 1.3.9-1 + + 4.4.1 + 3.9.1.2184 @@ -470,5 +473,96 @@ + + + clover + + false + + clover + + + + ${project.build.directory}/clover/code-coverage.db + + + + + org.openclover + clover-maven-plugin + + ${cloverDatabase} + ${cloverDatabase} + ${project.build.directory}/clover + 50% + true + false + true + true + true + false + + **/org/apache/**/*.java + + + **/src/main/assembly/**/* + hbase-operator-tools-assembly/**/* + + + + + clover-setup + + setup + + + + + + + + + org.openclover + clover-maven-plugin + ${clover-maven-plugin.version} + + + + + + + sonar + + false + + sonar + + + + clover + ${clover-maven-plugin.version} + ${project.build.directory}/clover/clover.xml + ${project.build.directory}/surefire-reports + reuseReports + hbase-operator-tools-assembly/**/*,**/pom.xml + + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + + + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + ${sonar-maven-plugin.version} + + + + + From 3ec42463d0b474a68ffabe061096a9de23e6e01f Mon Sep 17 00:00:00 2001 From: Dora Horvath Date: Mon, 13 Jun 2022 12:23:03 +0200 Subject: [PATCH 2/2] HBASE-26934: add short description --- dev-support/code-coverage/README.md | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 dev-support/code-coverage/README.md diff --git a/dev-support/code-coverage/README.md b/dev-support/code-coverage/README.md new file mode 100644 index 0000000000..7f8899b545 --- /dev/null +++ b/dev-support/code-coverage/README.md @@ -0,0 +1,40 @@ + + + +# Clover code analysis +The `run-coverage.sh` script runs maven with the clover profile which generates the test coverage data. +If the necessary parameters are given it also runs maven with the sonar profile and uploads the results to SonarQube. + +## Running code coverage +The coverage results can be found under `target/clover/index.html` and here is how you can run the clover code analysis: + + +```sh dev-support/code-coverage/run-coverage.sh``` + + +## Publishing coverage results to SonarQube +The required parameters for publishing to SonarQube are: + +- host URL +- login credentials +- project key + +Here is an example command for running and publishing the coverage data: + +```sh dev-support/code-coverage/run-coverage.sh -l ProjectCredentials -u https://exampleserver.com -k Project_Key -n Project_Name```