@@ -166,6 +166,7 @@ destinationSimulator=''; readParameter destinationSimulator 'sonar.objectivec.si
166166# Your .xcworkspace/.xcodeproj filename
167167workspaceFile=' ' ; readParameter workspaceFile ' sonar.objectivec.workspace'
168168projectFile=' ' ; readParameter projectFile ' sonar.objectivec.project'
169+ projectVersion=' ' ; readParameter projectVersion ' sonar.projectVersion'
169170
170171# Count projects
171172projectCount=$( 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
210211fi
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+
212218if [ " $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
237243echo -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 )
239250if [[ ! -z " $destinationSimulator " ]]; then
240251 buildCmd+=(-destination " $destinationSimulator " -destination-timeout 360)
241252fi
@@ -246,7 +257,7 @@ oclint-xcodebuild # Transform the xcodebuild.log file into a compile_command.jso
246257# Unit tests and coverage
247258if [ " $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
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
420431
421432# SonarQube
422433echo -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
426437stopProgress
427438
0 commit comments