Setting up Sonarqube to Analyze Xcode on Mac OSX
August 27, 2014Sonarqube is a web application platform, installable on Linux, Windows or OSX, which helps teams manage & fix code quality issues – things like ensuring coding standards are maintained, sufficient commenting, unit test coverage, functional test coverage, etc.
These were the basic steps in setting up a Mac OSX machine to run as a continuous integration agent to fire off Sonarqube (the artist formerly known as “Sonar”) analysis runs against the Xcode project, using Gradle as a build mechanism.
These instructions were used to install Sonar on a Mac Mini Server and a new Mac Pro, both running Mac OS X Mavericks 10.9.4.
- Sonar Setup:
- Download Sonar: I used the Sonarqube LTS version (3.7.4) rather than the latest version (4.4). Reason being, the fact that the way to call Sonar from Gradle (its sonarRunner plugin) has embedded an older version of the API than the bleeding-edge Sonarqube currently supports. So, whilst you can hack it and make it eventually work, better to go with the long-terms support version that actually works.
- Install Sonarqube to /opt/sonarqube-3.7.4
- Install Mysql: Installed MySQL 5.7 from http://dev.mysql.com/doc/refman/5.7/en/macosx-installation.html
- Set up Sonar DB in MySQL:
CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; CREATE USER 'sonar' IDENTIFIED BY 'sonar'; GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar'; GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar'; FLUSH PRIVILEGES;
- Uncomment the line in /opt/sonarqube-3.7.4/conf/sonar.properties to tell it to use the local mysql db:
#----- MySQL 5.x # Comment the embedded database and uncomment the following line to use MySQL sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
- Download & install Groovy and Objective C plugins for Sonar. Download the jar for each and put into /opt/sonarqube-4.4/extensions/plugins
- NOTE: Whilst the Groovy plugin for Sonar is free, the Objective-C/C++ plugin is positively not. Price at this writing was about $6500, though they will let you eval it for 14 days. You’ll have to get a trial license key from their sales reps, and insert it into http://[sonarserver]:9000/settings?category=licenses
- Restart Sonar, and when done, plugins are visible.
Hi, I’m trying to use Sonarqube, but I’ve many problems.
I’ve tried this way https://github.com/octo-technology/sonar-objective-c, but it not work.
Always appear this message:
“Skipping tests as no test scheme has been provided!
-n Running OCLint…
-n .
-n Running SonarQube using SonarQube Runner
run-sonar.sh: line 98: sonar-runner: command not found
ERROR – Command ‘sonar-runner ‘ failed with error code: ”
I followed your tutorial, but I need to do some before right?
Can you help me?
I can try to be of some help. What are you using to call Sonar?
Mine’s being done with Gradle, and I’m presently using the SonarSource Objective-C plugin, rather than the one from Octo. I’ve gotten it working just fine, all except the ingest of gcov files to generate the test coverage metrics, which I still have yet to get done properly. I’ll post what I did to get it running in Gradle shortly.
I’m using “sh run-sonar.sh”. When i try with “sudo bash run-sonar.sh”
Appears
2014-09-08 13:35:13.602 xctool[18774:2807] Warning: error running xcodebuild -showBuildSettings: xcodebuild: error: The project ‘POCAlert’ does not contain a scheme named ‘POCAlert’.
2014-09-08 13:35:14.023 xctool[18774:2807] Warning: error running xcodebuild -showBuildSettings: xcodebuild: error: The project ‘POCAlert’ does not contain a scheme named ‘POCAlert’.
2014-09-08 13:35:14.024 xctool[18774:2807] *** Assertion failure in -[XcodeSubjectInfo buildSettingsForATarget], /tmp/xctool-1VWq/xctool-0.1.16/xctool/xctool/XcodeSubjectInfo.m:819
2014-09-08 13:35:14.215 xctool[18774:2807] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Failed while trying to gather build settings for your scheme; tried with actions: build, test, analyze’
*** First throw call stack:
(
0 CoreFoundation 0x00007fff8c51f25c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff89d67e75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8c51f038 +[NSException raise:format:arguments:] + 104
3 Foundation 0x00007fff8e56dd41 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
4 xctool 0x000000010c3b4af7 -[XcodeSubjectInfo buildSettingsForATarget] + 556
5 xctool 0x000000010c3b581f -[XcodeSubjectInfo loadSubjectInfo] + 150
6 xctool 0x000000010c3aa951 -[Options validateAndReturnXcodeSubjectInfo:errorMessage:] + 4054
7 xctool 0x000000010c3a0da2 -[XCTool run] + 1372
8 xctool 0x000000010c39ff85 main + 542
9 xctool 0x000000010c39dda4 start + 52
10 ??? 0x000000000000000c 0x0 + 12
)
libc++abi.dylib: terminating with uncaught exception of type NSException
run-sonar.sh: line 44: 18774 Abort trap: 6 $command “$@” > /dev/null
ERROR – Command ‘xctool -project POCAlert.xcodeproj -sdk iphonesimulator ARCHS=i386 VALID_ARCHS=i386 CURRENT_ARCH=i386 ONLY_ACTIVE_ARCH=NO -scheme POCAlert clean’ failed with error code:
Hm. I’m invoking Sonar entirely differently from you. Just put in how I’m invoking it here:
http://www.jetteroheller.com/running-sonar-on-ios-objective-c-projects-with-gradle/
Not sure if that’ll be of any help. I know the SonarSource Obj-C plugin is fairly spendy, but you may want to try an eval of it just to see if you can get her working.
[…] getting the basics out of the way on setting up Sonarqube on Mac OSX, one has to invoke it somehow. We settled on building our iOS project with Gradle, and as such, […]