Skip to content

Commit

Permalink
fix(sonarqube): support java projects with multiple modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Jian Zeng committed Jan 11, 2021
1 parent 48089c6 commit b3a4be4
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions build/cicd/sonarqube/entrypoint.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -e

USAGE=$(cat <<-END
Expand Down Expand Up @@ -67,37 +67,46 @@ curl -XPOST -u ${TOKEN}: "${SERVER}/api/qualitygates/select?gateId=${QUALITY_GAT
exit 1
}

params="-Dsonar.sourceEncoding=${ENCODING} \
-Dsonar.projectName=${PROJECT_NAME} \
-Dsonar.projectKey=${PROJECT_KEY} \
-Dsonar.sources=${SOURCE_PATH} \
-Dsonar.projectBaseDir=${SOURCE_PATH} \
-Dsonar.host.url=${SERVER} \
-Dsonar.login=${TOKEN}"
declare -A paramsMap=(
['sonar.sourceEncoding']="$ENCODING"
['sonar.projectName']="$PROJECT_NAME"
['sonar.projectKey']="$PROJECT_KEY"
['sonar.sources']="$SOURCE_PATH"
['sonar.projectBaseDir']="$SOURCE_PATH"
['sonar.host.url']="$SERVER"
['sonar.login']="$TOKEN"
)

params=''

case ${LANGUAGE} in
Go)
for key in "${!paramsMap[@]}"; do
params+=" -D${key}=${paramsMap[$key]}"
done
echo "Start to find go test reports."
testReportFile=$(find . -name "coverage.out" | tr '\n' ',')
if [[ -n ${testReportFile} ]]; then
params="$params -Dsonar.go.coverage.reportPaths=$testReportFile"
fi
;;
Java)
echo "Start to find java bin files."
binFiles=$({ find . -name "*.jar"; find . -name "*.war"; } | tr '\n' ',')
if [[ -n ${binFiles} ]]; then
params="$params -Dsonar.java.binaries=$binFiles"
fi

xmlFiles=$(find . -name "*.xml")
if [[ ${#xmlFiles[@]} -ne 0 ]]; then
reportXMLs=$(grep -l "<testsuite" ${xmlFiles} | tr '\n' ',')
fi

if [[ -n ${reportXMLs} ]]; then
params="$params -Dsonar.junit.reportPaths=$reportXMLs"
paramsMap['sonar.sources']='./src/main'
paramsMap['sonar.java.binaries']='./target/classes'
paramsMap['sonar.junit.reportPaths']='./target/surefire-reports'
if [[ -f ./sonar-project.properties ]]; then
while read -r line; do
# ignore the line starts with '#'
if [[ $line = \#* ]] || [[ -z $line ]]; then
continue
fi
IFS='=' read -r arg val <<< "$line"
paramsMap["$arg"]="$val"
done < ./sonar-project.properties
fi
for key in "${!paramsMap[@]}"; do
params+=" -D${key}=${paramsMap[$key]}"
done
;;
*)
;;
Expand Down

0 comments on commit b3a4be4

Please sign in to comment.