code-coverage.sh 2.4 KB

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