Issue #216

Install Sonarqube

https://docs.sonarqube.org/latest/setup/get-started-2-minutes/

  • Download Sonarqube for macOS https://www.sonarqube.org/downloads/
  • Put it in ~/sonarqube
  • Run localhost server ~/sonarqube/bin/macosx-universal-64/sonar.sh console
  • Login http://localhost:9000 with admin/admin
  • Create new project

Install Sonar scanner

https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner

  • Download for macOS 64 bit
  • Put it in ~/sonarscanner
  • export PATH=$PATH:/Users/khoa/sonarscanner/bin
  • Go to project, create sonar-project.properties
# must be unique in a given SonarQube instance
sonar.projectKey=my-app
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=My App
sonar.projectVersion=1.0
 
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set. 
sonar.sources=.
 
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
  • Run sonar-scanner

Install swift plugin

https://github.com/Backelite/sonar-swift

Skip some tools

Modify run-sonar-swift.sh

vflag=""
nflag=""
unittests="on"
swiftlint="on"
tailor="off"
lizard="on"
oclint="off"
fauxpas="off"
sonarscanner=""

Git ignore

.scannerwork/
sonar-reports/
compile_commands.json

run-sonar-swift.sh

  • Update sonar-project.properties
sonar.swift.appScheme=MyApp Staging
sonar.swift.project=MyApp.xcodeproj
sonar.swift.workspace=MyApp.xcworkspace
sonar.swift.simulator=platform=iOS Simulator,name=iPhone Xส€
  • Run chmod +x run-sonar-swift.sh
  • Run ./run-sonar-swift.sh

Troubleshooting

failed with error code: 64 https://github.com/Backelite/sonar-swift/issues/222

When run ./run-sonar-swift.sh

xcodebuild: error: ''MyApp.xcodeproj'' does not exist.
2019-04-29 12:10:17.486 defaults[4134:569992]
Domain CFBundleShortVersionString does not exist
.Extracting Xcode project informationxcodebuild: error: option 'Destination' requires at least one parameter of the form 'key=value'

๐Ÿ‘‰ Remove quotes in sonar-project.properties ๐Ÿ‘‰ Modify run-sonar-swift.sh, add these before Check for mandatory parameters section

Surround by double quotes

projectFile="\"$projectFile\""
workspaceFile="\"$workspaceFile\""
appScheme="\"$appScheme\""
destinationSimulator="\"$destinationSimulator\""

๐Ÿ˜ข Does not work ๐Ÿ‘‰ Need to create a scheme name without space

Error code 65

๐Ÿ‘‰Specify team in Xcode project

destination

Need double quotes

destinationSimulator="\"$destinationSimulator\""

Use equal sign =

-destination="$destinationSimulator"

instead of space ’ '

-destination "$destinationSimulator"

Metric ‘files’ should not be computed by a Sensor

When run sonar-scanner https://github.com/Backelite/sonar-swift/issues/212

11:01:14.406 INFO: Sensor JaCoCo XML Report Importer [jacoco]
11:01:14.409 DEBUG: No reports found
11:01:14.409 INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=3ms
11:01:14.409 INFO: Sensor SwiftLint [backelitesonarswiftplugin]
11:01:14.417 INFO: Sensor SwiftLint [backelitesonarswiftplugin] (done) | time=8ms
11:01:14.417 INFO: Sensor Tailor [backelitesonarswiftplugin]
11:01:14.418 INFO: Sensor Tailor [backelitesonarswiftplugin] (done) | time=1ms
11:01:14.418 INFO: Sensor OCLint [backelitesonarswiftplugin]
11:01:14.419 INFO: Sensor OCLint [backelitesonarswiftplugin] (done) | time=1ms
11:01:14.419 INFO: Sensor FauxPas [backelitesonarswiftplugin]
11:01:14.419 INFO: Sensor FauxPas [backelitesonarswiftplugin] (done) | time=0ms
11:01:14.419 INFO: Sensor Swift Squid [backelitesonarswiftplugin]
11:01:14.526 INFO: ------------------------------------------------------------------------
11:01:14.526 INFO: EXECUTION FAILURE
11:01:14.526 INFO: ------------------------------------------------------------------------
11:01:14.527 INFO: Total time: 6.180s
11:01:14.603 INFO: Final Memory: 25M/566M
11:01:14.603 INFO: ------------------------------------------------------------------------
11:01:14.603 ERROR: Error during SonarQube Scanner execution
java.lang.UnsupportedOperationException: Metric 'files' should not be computed by a Sensor
	at org.sonar.scanner.sensor.DefaultSensorStorage.saveMeasure(DefaultSensorStorage.java:168)

๐Ÿ‘‰Install maven https://maven.apache.org/download.cgi Edit ObjectiveCSquidSensor.java and SwiftSquidSensor, remove line with CoreMetrics.FILES Run export PATH=$PATH:/Users/khoa/apache-maven/bin Run ./build-and-deploy.sh Or ~/apache-maven/bin/mvn clean install

๐ŸŽ‰ Built jar is in sonar-swift-plugin/target/backelite-sonar-swift-plugin-0.4.4.jar, copy back to extensions/plugins

How to enable SwiftLint as default profile ๐Ÿค”

๐Ÿ‘‰ Need to close current Sonar tab and restart server

Testing failed: unable to attach DB

Modify run-sonar-swift.sh to add -UseModernBuildSystem=NO to buildCmd+=(-destination

slather No coverage directory found

Try running

slather coverage --input-format profdata --cobertura-xml --output-directory sonar-reports --workspace MyApp.xcworkspace --scheme MyAppStaging MyApp.xcodeproj

๐Ÿ‘‰ Enable coverage option in scheme -> Test

Optional: declare .slather.yml file https://github.com/SlatherOrg/slather

Unable to execute SonarQube

14:53:23.251 ERROR: Error during SonarQube Scanner execution
org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarQube
	at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)

๐Ÿ‘‰Start sonar server

LizardReportParser$SwiftFunction cannot be cast

Error during SonarQube Scanner execution
java.lang.ClassCastException: com.backelite.sonarqube.swift.complexity.LizardReportParser$SwiftFunction cannot be cast to org.sonar.api.batch.fs.internal.DefaultInputComponent

๐Ÿ‘‰ Run lizard manually

lizard --xml sonar-reports/lizard-report.xml