HBASE-27685 Enable code coverage reporting to SonarQube in HBase (#5076)
(cherry picked from commit 72d5a46899
)
This commit is contained in:
parent
ad90a7b046
commit
e2e7968cb1
|
@ -0,0 +1,49 @@
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
# Code analysis
|
||||||
|
|
||||||
|
The `run-coverage.sh` script runs maven with the **jacoco** profile
|
||||||
|
which generates the test coverage data for the java classes.
|
||||||
|
If the required parameters are given it also runs the sonar code analysis
|
||||||
|
and uploads the results to the given SonarQube Server.
|
||||||
|
|
||||||
|
## Running code analysis
|
||||||
|
|
||||||
|
After running the script the reports generated by the JaCoCo
|
||||||
|
code coverage library can be found under the `/target/site/jacoco/` folder of
|
||||||
|
the related modules.
|
||||||
|
|
||||||
|
Here is how you can generate the code coverage report:
|
||||||
|
|
||||||
|
```sh dev/code-coverage/run-coverage.sh```
|
||||||
|
|
||||||
|
## Publishing coverage results to SonarQube
|
||||||
|
|
||||||
|
The required parameters for publishing the results 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:
|
||||||
|
|
||||||
|
`./dev/code-coverage/run-coverage.sh -l ProjectCredentials
|
||||||
|
-u https://exampleserver.com -k Project_Key -n Project_Name`
|
|
@ -0,0 +1,78 @@
|
||||||
|
#!/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 are:"
|
||||||
|
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"
|
||||||
|
|
||||||
|
echo "Running unit and integration tests with runAllTests profile"
|
||||||
|
|
||||||
|
mvn -B -e -f "${MAIN_POM}" clean test -PrunAllTests -Pjacoco -Pbuild-with-jdk11 -fn
|
||||||
|
|
||||||
|
echo "Starting verifying phase"
|
||||||
|
|
||||||
|
mvn -B -e -f "${MAIN_POM}" verify -DskipTests -DskipITs -Pjacoco -Pbuild-with-jdk11 -fn
|
||||||
|
|
||||||
|
echo "Starting sonar scanner analysis"
|
||||||
|
|
||||||
|
# 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 -f "${MAIN_POM}" sonar:sonar -Dsonar.host.url="$SONAR_URL" \
|
||||||
|
-Dsonar.login="$SONAR_LOGIN" -Dsonar.projectKey="$SONAR_PROJECT_KEY" \
|
||||||
|
-Dsonar.projectName="$SONAR_PROJECT_NAME" -Pjacoco
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Build finished"
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
|
@ -294,7 +294,7 @@
|
||||||
<forkedProcessTimeoutInSeconds>1800</forkedProcessTimeoutInSeconds>
|
<forkedProcessTimeoutInSeconds>1800</forkedProcessTimeoutInSeconds>
|
||||||
<argLine>-enableassertions -Xmx${failsafe.Xmx}
|
<argLine>-enableassertions -Xmx${failsafe.Xmx}
|
||||||
-Djava.security.egd=file:/dev/./urandom -XX:+CMSClassUnloadingEnabled
|
-Djava.security.egd=file:/dev/./urandom -XX:+CMSClassUnloadingEnabled
|
||||||
-verbose:gc -XX:+PrintCommandLineFlags -XX:+PrintFlagsFinal</argLine>
|
-verbose:gc -XX:+PrintCommandLineFlags -XX:+PrintFlagsFinal @{jacocoArgLine}</argLine>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
36
pom.xml
36
pom.xml
|
@ -633,6 +633,10 @@
|
||||||
<spotless.version>2.27.2</spotless.version>
|
<spotless.version>2.27.2</spotless.version>
|
||||||
<hbase-thirdparty.version>4.1.4</hbase-thirdparty.version>
|
<hbase-thirdparty.version>4.1.4</hbase-thirdparty.version>
|
||||||
<maven-site.version>3.12.0</maven-site.version>
|
<maven-site.version>3.12.0</maven-site.version>
|
||||||
|
<!-- Coverage properties -->
|
||||||
|
<jacoco.version>0.8.8</jacoco.version>
|
||||||
|
<jacocoArgLine/>
|
||||||
|
<sonar-maven-plugin.version>3.9.1.2184</sonar-maven-plugin.version>
|
||||||
<!-- Intraproject jar naming properties -->
|
<!-- Intraproject jar naming properties -->
|
||||||
<!-- TODO this is pretty ugly, but works for the moment.
|
<!-- TODO this is pretty ugly, but works for the moment.
|
||||||
Modules are pretty heavy-weight things, so doing this work isn't too bad. -->
|
Modules are pretty heavy-weight things, so doing this work isn't too bad. -->
|
||||||
|
@ -689,10 +693,10 @@
|
||||||
"-Djava.library.path=${hadoop.library.path};${java.library.path}"
|
"-Djava.library.path=${hadoop.library.path};${java.library.path}"
|
||||||
-Dorg.apache.hbase.thirdparty.io.netty.leakDetection.level=advanced</hbase-surefire.cygwin-argLine>
|
-Dorg.apache.hbase.thirdparty.io.netty.leakDetection.level=advanced</hbase-surefire.cygwin-argLine>
|
||||||
<!-- Surefire argLine defaults to Linux, cygwin argLine is used in the os.windows profile -->
|
<!-- Surefire argLine defaults to Linux, cygwin argLine is used in the os.windows profile -->
|
||||||
<argLine>${hbase-surefire.argLine}</argLine>
|
<argLine>${hbase-surefire.argLine} @{jacocoArgLine}</argLine>
|
||||||
<jacoco.version>0.7.5.201505241946</jacoco.version>
|
<jacoco.version>0.7.5.201505241946</jacoco.version>
|
||||||
<extra.enforcer.version>1.3</extra.enforcer.version>
|
<extra.enforcer.version>1.5.1</extra.enforcer.version>
|
||||||
<enforcer.version>3.0.0-M3</enforcer.version>
|
<enforcer.version>3.0.0</enforcer.version>
|
||||||
<restrict-imports.enforcer.version>0.14.0</restrict-imports.enforcer.version>
|
<restrict-imports.enforcer.version>0.14.0</restrict-imports.enforcer.version>
|
||||||
<!-- Location of test resources -->
|
<!-- Location of test resources -->
|
||||||
<test.build.classes>${project.build.directory}/test-classes</test.build.classes>
|
<test.build.classes>${project.build.directory}/test-classes</test.build.classes>
|
||||||
|
@ -2694,7 +2698,8 @@
|
||||||
--add-opens java.base/jdk.internal.util.random=ALL-UNNAMED
|
--add-opens java.base/jdk.internal.util.random=ALL-UNNAMED
|
||||||
--add-exports java.base/jdk.internal.misc=ALL-UNNAMED
|
--add-exports java.base/jdk.internal.misc=ALL-UNNAMED
|
||||||
--add-exports java.security.jgss/sun.security.krb5=ALL-UNNAMED
|
--add-exports java.security.jgss/sun.security.krb5=ALL-UNNAMED
|
||||||
${hbase-surefire.argLine}</argLine>
|
${hbase-surefire.argLine}
|
||||||
|
@{jacocoArgLine}</argLine>
|
||||||
<!-- We need a minimum HDFS version of 3.2.0 for HADOOP-12760 -->
|
<!-- We need a minimum HDFS version of 3.2.0 for HADOOP-12760 -->
|
||||||
<hadoop-three.version>3.2.0</hadoop-three.version>
|
<hadoop-three.version>3.2.0</hadoop-three.version>
|
||||||
<!--
|
<!--
|
||||||
|
@ -2804,6 +2809,12 @@
|
||||||
<activation>
|
<activation>
|
||||||
<activeByDefault>false</activeByDefault>
|
<activeByDefault>false</activeByDefault>
|
||||||
</activation>
|
</activation>
|
||||||
|
<properties>
|
||||||
|
<sonar.exclusions>**/generated/**/*</sonar.exclusions>
|
||||||
|
<sonar.coverage.exclusions>**/generated/**/*,hbase-it/**,**/hbase-logging/**/*,**/hbase-testing-util/**/*,
|
||||||
|
**/hbase-protocol-shaded/**/*,**/hbase-external-blockcache/**/*,**/hbase-examples/**/*,
|
||||||
|
**/hbase-archetypes/**/*</sonar.coverage.exclusions>
|
||||||
|
</properties>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -2811,11 +2822,8 @@
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
<version>${jacoco.version}</version>
|
<version>${jacoco.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<systemPropertyVariables>
|
|
||||||
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
|
|
||||||
</systemPropertyVariables>
|
|
||||||
<excludes>
|
<excludes>
|
||||||
<exclude>**/generated/**/*.class</exclude>
|
<exclude>**/generated/**/*</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
|
@ -2824,6 +2832,11 @@
|
||||||
<goals>
|
<goals>
|
||||||
<goal>prepare-agent</goal>
|
<goal>prepare-agent</goal>
|
||||||
</goals>
|
</goals>
|
||||||
|
<phase>initialize</phase>
|
||||||
|
<configuration>
|
||||||
|
<propertyName>jacocoArgLine</propertyName>
|
||||||
|
<append>true</append>
|
||||||
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
<execution>
|
<execution>
|
||||||
<id>report</id>
|
<id>report</id>
|
||||||
|
@ -2834,6 +2847,11 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||||
|
<artifactId>sonar-maven-plugin</artifactId>
|
||||||
|
<version>${sonar-maven-plugin.version}</version>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
|
@ -2869,7 +2887,7 @@
|
||||||
</activation>
|
</activation>
|
||||||
<properties>
|
<properties>
|
||||||
<build.platform>cygwin</build.platform>
|
<build.platform>cygwin</build.platform>
|
||||||
<argLine>${hbase-surefire.cygwin-argLine}</argLine>
|
<argLine>${hbase-surefire.cygwin-argLine} @{jacocoArgLine}</argLine>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
<!-- this profile should match the name of the release profile in the root asf pom -->
|
<!-- this profile should match the name of the release profile in the root asf pom -->
|
||||||
|
|
Loading…
Reference in New Issue