This is an automated email from the ASF dual-hosted git repository.
psomogyi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase-filesystem.git
The following commit(s) were added to refs/heads/master by this push:
new 7f93728 HBASE-27196: Enable code coverage reporting to SonarQube in
hbase-filesystem (#36)
7f93728 is described below
commit 7f93728629d5f321eae004bb871b5baccb179eff
Author: Horváth Dóra <[email protected]>
AuthorDate: Fri Jul 15 11:18:22 2022 +0200
HBASE-27196: Enable code coverage reporting to SonarQube in
hbase-filesystem (#36)
Signed-off-by: Peter Somogyi <[email protected]>
Reviewed-by: Andor Molnar <[email protected]>
---
dev-support/code-coverage/README.md | 42 ++++++++++++++
dev-support/code-coverage/run-coverage.sh | 71 ++++++++++++++++++++++++
pom.xml | 92 +++++++++++++++++++++++++++++++
3 files changed, 205 insertions(+)
diff --git a/dev-support/code-coverage/README.md
b/dev-support/code-coverage/README.md
new file mode 100644
index 0000000..17526dd
--- /dev/null
+++ b/dev-support/code-coverage/README.md
@@ -0,0 +1,42 @@
+<!--
+ 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.
+-->
+
+
+# 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
+
+The project name is an optional parameter.
+
+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```
\ No newline at end of file
diff --git a/dev-support/code-coverage/run-coverage.sh
b/dev-support/code-coverage/run-coverage.sh
new file mode 100644
index 0000000..68a0b6f
--- /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
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 891b559..638419c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,6 +65,9 @@
<!-- system property for the hadoop version passed
down in tests. -->
<HBOSS_HADOOP_VERSION>3.3</HBOSS_HADOOP_VERSION>
+ <!-- Code coverage properties -->
+ <clover-maven-plugin.version>4.4.1</clover-maven-plugin.version>
+ <sonar-maven-plugin.version>3.9.1.2184</sonar-maven-plugin.version>
</properties>
<modules>
@@ -200,6 +203,95 @@
</plugins>
</build>
</profile>
+
+ <profile>
+ <id>clover</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ <property>
+ <name>clover</name>
+ </property>
+ </activation>
+ <properties>
+
<cloverDatabase>${project.build.directory}/clover/code-coverage.db</cloverDatabase>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.openclover</groupId>
+ <artifactId>clover-maven-plugin</artifactId>
+ <configuration>
+ <cloverDatabase>${cloverDatabase}</cloverDatabase>
+ <cloverMergeDatabase>${cloverDatabase}</cloverMergeDatabase>
+
<outputDirectory>${project.build.directory}/clover</outputDirectory>
+ <alwaysReport>true</alwaysReport>
+ <generateHistorical>false</generateHistorical>
+ <generateHtml>true</generateHtml>
+ <includesTestSourceRoots>true</includesTestSourceRoots>
+ <includesAllSourceRoots>false</includesAllSourceRoots>
+ <includes>
+ <include>**/org/apache/**/*.java</include>
+ </includes>
+ <excludes>
+ <exclude>**/src/main/appended-resources/**/*</exclude>
+ </excludes>
+ </configuration>
+ <executions>
+ <execution>
+ <id>clover-setup</id>
+ <goals>
+ <goal>setup</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.openclover</groupId>
+ <artifactId>clover-maven-plugin</artifactId>
+ <version>${clover-maven-plugin.version}</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+ </profile>
+
+ <profile>
+ <id>sonar</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ <property>
+ <name>sonar</name>
+ </property>
+ </activation>
+ <properties>
+ <sonar.core.codeCoveragePlugin>clover</sonar.core.codeCoveragePlugin>
+
<sonar.clover.version>${clover-maven-plugin.version}</sonar.clover.version>
+
<sonar.clover.reportPath>${project.build.directory}/clover/clover.xml</sonar.clover.reportPath>
+
<sonar.surefire.reportsPath>${project.build.directory}/surefire-reports</sonar.surefire.reportsPath>
+ <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.sonarsource.scanner.maven</groupId>
+ <artifactId>sonar-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.sonarsource.scanner.maven</groupId>
+ <artifactId>sonar-maven-plugin</artifactId>
+ <version>${sonar-maven-plugin.version}</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+ </profile>
+
</profiles>
</project>