You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ri...@apache.org on 2022/08/30 15:17:50 UTC
[phoenix-omid] branch master updated: PHOENIX-6775 Enable code coverage reporting to SonarQube in Phoenix-Omid (#116)
This is an automated email from the ASF dual-hosted git repository.
richardantal pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix-omid.git
The following commit(s) were added to refs/heads/master by this push:
new 8da8c013 PHOENIX-6775 Enable code coverage reporting to SonarQube in Phoenix-Omid (#116)
8da8c013 is described below
commit 8da8c013c4ebb87e320e32e900416ad41ba724b6
Author: Horváth Dóra <ho...@gmail.com>
AuthorDate: Tue Aug 30 17:17:45 2022 +0200
PHOENIX-6775 Enable code coverage reporting to SonarQube in Phoenix-Omid (#116)
* PHOENIX-6775 Enable code coverage reporting to SonarQube in Phoenix-Omid
---
dev/code-coverage/README.md | 40 ++++++++++++++++++++++
dev/code-coverage/run-coverage.sh | 72 +++++++++++++++++++++++++++++++++++++++
pom.xml | 55 ++++++++++++++++++++++++++++++
3 files changed, 167 insertions(+)
diff --git a/dev/code-coverage/README.md b/dev/code-coverage/README.md
new file mode 100644
index 00000000..a6c2d00f
--- /dev/null
+++ b/dev/code-coverage/README.md
@@ -0,0 +1,40 @@
+<!--
+ Licensed 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 code-coverage profile which generates
+the clover code analysis data.
+If the necessary parameters are given it also 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:
+
+```./dev/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:
+
+`./dev/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/code-coverage/run-coverage.sh b/dev/code-coverage/run-coverage.sh
new file mode 100755
index 00000000..7ed4b825
--- /dev/null
+++ b/dev/code-coverage/run-coverage.sh
@@ -0,0 +1,72 @@
+#!/usr/bin/env bash
+# Licensed 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 " -t Number of threads (example: 1 or 2C)."
+ 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"
+ # Check the syntax for the THREAD_COUNT variable
+ if [[ "$THREAD_COUNT" =~ ^[0-9]+([.][0-9]+)?$ ]] || [[ "$THREAD_COUNT" =~ ^[0-9]+([.][0-9]+)+[C]?$ ]]; then
+ THREADS="${THREAD_COUNT}"
+ else
+ THREADS=1
+ fi
+
+ mvn -B -e -Pcode-coverage -f "$MAIN_POM" clean install -Dparallel-tests -Dscale -fn -T "$THREADS"
+ mvn -B -e -Pcode-coverage -f "$MAIN_POM" clover:aggregate clover:clover -T "$THREADS"
+
+ # 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 -Pcode-coverage -f "$MAIN_POM" sonar:sonar -Dsonar.projectName="$SONAR_PROJECT_NAME" \
+ -Dsonar.host.url="$SONAR_URL" -Dsonar.login="$SONAR_LOGIN" -Dsonar.projectKey="$SONAR_PROJECT_KEY" -T "$THREADS"
+ fi
+}
+
+while getopts ":u:l:k:n:t:h" option; do
+ case $option in
+ u) SONAR_URL=${OPTARG:-} ;;
+ l) SONAR_LOGIN=${OPTARG:-} ;;
+ k) SONAR_PROJECT_KEY=${OPTARG:-} ;;
+ n) SONAR_PROJECT_NAME=${OPTARG:-} ;;
+ t) THREAD_COUNT=${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 38e41b6d..1335ffcc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -193,6 +193,9 @@
<maven-jxr-plugin.version>2.3</maven-jxr-plugin.version>
<maven-findbugs-maven-plugin.version>3.0.1</maven-findbugs-maven-plugin.version>
<maven-owasp-plugin.version>6.5.3</maven-owasp-plugin.version>
+ <!-- Code coverage properties -->
+ <maven-clover-plugin.version>4.4.1</maven-clover-plugin.version>
+ <maven-sonar-plugin.version>3.9.1.2184</maven-sonar-plugin.version>
<!-- Licensing properties (for license-maven-plugins) -->
<license.header>misc/header.txt</license.header>
@@ -635,6 +638,58 @@
<protoc.version>2.5.0.2</protoc.version>
</properties>
</profile>
+
+ <profile>
+ <id>code-coverage</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <properties>
+ <cloverDatabase>${project.build.directory}/clover/code-coverage.db</cloverDatabase>
+ <sonar.core.codeCoveragePlugin>clover</sonar.core.codeCoveragePlugin>
+ <sonar.clover.version>${maven-clover-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.openclover</groupId>
+ <artifactId>clover-maven-plugin</artifactId>
+ <version>${maven-clover-plugin.version}</version>
+ <configuration>
+ <cloverDatabase>${cloverDatabase}</cloverDatabase>
+ <cloverMergeDatabase>${cloverDatabase}</cloverMergeDatabase>
+ <outputDirectory>${project.build.directory}/clover</outputDirectory>
+ <alwaysReport>true</alwaysReport>
+ <generateHistorical>false</generateHistorical>
+ <generateHtml>true</generateHtml>
+ <generateXml>true</generateXml>
+ <includesTestSourceRoots>true</includesTestSourceRoots>
+ <includesAllSourceRoots>true</includesAllSourceRoots>
+ <includes>
+ <include>**/org/apache/**/*.java</include>
+ </includes>
+ </configuration>
+ <executions>
+ <execution>
+ <id>clover-setup</id>
+ <goals>
+ <goal>setup</goal>
+ </goals>
+ <phase>process-sources</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.sonarsource.scanner.maven</groupId>
+ <artifactId>sonar-maven-plugin</artifactId>
+ <version>${maven-sonar-plugin.version}</version>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
</profiles>
<dependencyManagement>