code-coverage.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. usage() {
  18. echo
  19. echo "options:"
  20. echo "-h Display help"
  21. echo "-u SonarQube Host URL"
  22. echo "-l SonarQube Login Credentials"
  23. echo "-k SonarQube Project Key"
  24. echo "-n SonarQube Project Name"
  25. echo
  26. echo "Important:"
  27. echo " The required parameters for publishing the coverage results to SonarQube:"
  28. echo " - Host URL"
  29. echo " - Login Credentials"
  30. echo " - Project Key"
  31. echo
  32. }
  33. execute() {
  34. SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
  35. MAIN_POM="${SCRIPT_DIR}/../../pom.xml"
  36. mvn -B -e -Pclover -f "$MAIN_POM" clean install -DskipTests -DskipShade
  37. mvn -B -e -Pclover -f "$MAIN_POM" test -Dparallel-tests -DtestsThreadCount=8 -Dscale
  38. mvn -B -e -Pclover -f "$MAIN_POM" clover:aggregate clover:clover
  39. # If the required parameters are given, the code coverage results are uploaded to the SonarQube Server
  40. if [ -n "$SONAR_LOGIN" ] && [ -n "$SONAR_PROJECT_KEY" ] && [ -n "$SONAR_URL" ]; then
  41. mvn -B -e -Pclover -f "$MAIN_POM" sonar:sonar -Dsonar.clover.reportPath=./target/clover/clover.xml \
  42. -Dsonar.host.url="$SONAR_URL" -Dsonar.login="$SONAR_LOGIN" -Dsonar.projectKey="$SONAR_PROJECT_KEY" -Dsonar.projectName="$SONAR_PROJECT_NAME"
  43. fi
  44. }
  45. while getopts ":u:l:k:n:h" option; do
  46. case $option in
  47. u) SONAR_URL=${OPTARG:-} ;;
  48. l) SONAR_LOGIN=${OPTARG:-} ;;
  49. k) SONAR_PROJECT_KEY=${OPTARG:-} ;;
  50. n) SONAR_PROJECT_NAME=${OPTARG:-} ;;
  51. h) # Display usage
  52. usage
  53. exit
  54. ;;
  55. \?) # Invalid option
  56. echo "Error: Invalid option"
  57. exit
  58. ;;
  59. esac
  60. done
  61. # Start code analysis
  62. execute