Skip to content
This repository was archived by the owner on Aug 24, 2019. It is now read-only.

Commit 6681be9

Browse files
committed
Fixing issues in run-sonar.sh
1. Fixing handling of sonar.objectivec.testScheme parameter 2. Fixing handling of sonar.objectivec.project parameter 3. Making it possible to read the sonar.projectVersion parameter from the app bundle
1 parent 2a6b4cd commit 6681be9

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/main/shell/run-sonar.sh

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ destinationSimulator=''; readParameter destinationSimulator 'sonar.objectivec.si
166166
# Your .xcworkspace/.xcodeproj filename
167167
workspaceFile=''; readParameter workspaceFile 'sonar.objectivec.workspace'
168168
projectFile=''; readParameter projectFile 'sonar.objectivec.project'
169+
projectVersion=''; readParameter projectVersion 'sonar.projectVersion'
169170

170171
# Count projects
171172
projectCount=$(echo $projectFile | sed -n 1'p' | tr ',' '\n' | wc -l | tr -d '[[:space:]]')
@@ -209,6 +210,11 @@ if [ -z "$destinationSimulator" -o "$destinationSimulator" = " " ]; then
209210
exit 1
210211
fi
211212

213+
# If project version is not set in the sonar-project.properties, read it from the project bundle
214+
if [[ "$projectVersion" = "" ]] ; then
215+
projectVersion=$(agvtool what-marketing-version -terse1)
216+
fi
217+
212218
if [ "$vflag" = "on" ]; then
213219
echo "Xcode workspace file is: $workspaceFile"
214220
echo "Xcode project file is: $projectFile"
@@ -235,7 +241,12 @@ mkdir sonar-reports
235241

236242
# Extracting project information needed later
237243
echo -n 'Extracting Xcode project information'
238-
buildCmd=(xcodebuild clean build -workspace $workspaceFile -scheme $appScheme)
244+
if [[ "$workspaceFile" != "" ]] ; then
245+
buildCmdPrefix="-workspace $workspaceFile"
246+
else
247+
buildCmdPrefix="-project $projectFile"
248+
fi
249+
buildCmd=(xcodebuild clean build $buildCmdPrefix -scheme $appScheme)
239250
if [[ ! -z "$destinationSimulator" ]]; then
240251
buildCmd+=(-destination "$destinationSimulator" -destination-timeout 360)
241252
fi
@@ -246,7 +257,7 @@ oclint-xcodebuild # Transform the xcodebuild.log file into a compile_command.jso
246257
# Unit tests and coverage
247258
if [ "$testScheme" = "" ]; then
248259
echo 'Skipping tests as no test scheme has been provided!'
249-
260+
250261
# Put default xml files with no tests and no coverage...
251262
echo "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><testsuites name='AllTestUnits'></testsuites>" > sonar-reports/TEST-report.xml
252263
echo "<?xml version='1.0' ?><!DOCTYPE coverage SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'><coverage><sources></sources><packages></packages></coverage>" > sonar-reports/coverage.xml
@@ -256,10 +267,10 @@ else
256267

257268
if [ "$coverageType" = "profdata" -o "$coverageType" = "" ]; then
258269
# profdata
259-
buildCmd=(xcodebuild clean build test -workspace $workspaceFile -scheme $appScheme -configuration Debug -enableCodeCoverage YES)
270+
buildCmd=(xcodebuild test $buildCmdPrefix -scheme "$testScheme" -configuration Debug -enableCodeCoverage YES)
260271
else
261272
# Legacy coverage
262-
buildCmd=(xcodebuild clean build test -workspace $workspaceFile -scheme $appScheme -configuration Debug)
273+
buildCmd=(xcodebuild test $buildCmdPrefix -scheme "$testScheme" -configuration Debug)
263274
fi
264275

265276
if [[ ! -z "$destinationSimulator" ]]; then
@@ -292,7 +303,7 @@ else
292303

293304
projectArray=(${projectFile//,/ })
294305
firstProject=${projectArray[0]}
295-
runCommand /dev/stdout $SLATHER_CMD coverage --input-format profdata $excludedCommandLineFlags --cobertura-xml --output-directory sonar-reports --scheme $appScheme $firstProject
306+
runCommand /dev/stdout $SLATHER_CMD coverage --input-format profdata $excludedCommandLineFlags --cobertura-xml --output-directory sonar-reports --scheme "$testScheme" $firstProject
296307
mv sonar-reports/cobertura.xml sonar-reports/coverage.xml
297308

298309
else
@@ -420,8 +431,8 @@ fi
420431

421432
# SonarQube
422433
echo -n 'Running SonarQube using SonarQube Runner'
423-
runCommand /dev/stdout sonar-runner
424-
434+
runCommand /dev/stdout sonar-runner -Dsonar.projectVersion=$projectVersion
435+
425436
# Kill progress indicator
426437
stopProgress
427438

0 commit comments

Comments
 (0)