iosswiftsonarqubesonarqube-scan

How to run Swift plugin from SonarQube for iOS application


I am for the first time trying to integrate SonarQube on a test iOS project on my local system. I have downloaded and successfully installed SonarQube and SonarScanner. I have also downloaded latest(0.4.6) bakelite Sonar Swift plugin from here.

Following is my Sonar Scanner file content:

sonar.host.url=http://localhost:9000
sonar.login=admin
sonar.password=Vivy@123

sonar.projectKey=testSonar1
sonar.projectName=testSonar

# Number version (can be found automatically in plist, just comment this line)
sonar.projectVersion=1.0
# Comment if you have a project with mixed ObjC / Swift
sonar.language=swift
# Project description
sonar.projectDescription=Project Description
# Path to source directories
sonar.sources=.
# Path to test directories (comment if no test)
sonar.tests=testSonarTests,testSonarUITests
sonar.test.inclusions=**/*Test*/**
sonar.test.inclusions=*.swift
sonar.exclusions=**/*.xml,Pods/**/*,Reports/**/*

# Destination Simulator to run surefire
# As string expected in destination argument of xcodebuild command
# Example = sonar.swift.simulator=platform=iOS Simulator,name=iPhone 6,OS=9.2
sonar.swift.simulator=platform=iOS Simulator,name=iPhone 8,OS=latest
# Xcode project configuration (.xcodeproj)
# and use the later to specify which project(s) to include in the analysis (comma separated list)
# Specify either xcodeproj or xcodeproj + xcworkspace
sonar.swift.project=testSonar.xcodeproj
#sonar.swift.workspace=testSonar.xcworkspace
# Specify your appname.
# This will be something like "myApp"
# Use when basename is different from targeted scheme.
# Or when slather fails with 'No product binary found'
sonar.swift.appName=testSonar
# Scheme to build your application
sonar.swift.appScheme=testSonar
# Configuration to use for your scheme. if you do not specify that the default will be Debug
sonar.swift.appConfiguration=Debug
##########################
# Optional configuration #
##########################
# Encoding of the source code
sonar.sourceEncoding=UTF-8
# SCM
# sonar.scm.enabled=true
# sonar.scm.url=scm:git:http://xxx
# JUnit report generated by run-sonar.sh is stored in sonar-reports/TEST-report.xml
# Change it only if you generate the file on your own
# The XML files have to be prefixed by TEST- otherwise they are not processed
sonar.junit.reportsPath=sonar-reports/
# Lizard report generated by run-sonar.sh is stored in sonar-reports/lizard-report.xml
# Change it only if you generate the file on your own
sonar.swift.lizard.report=sonar-reports/lizard-report.xml
# Cobertura report generated by run-sonar.sh is stored in sonar-reports/coverage-swift.xml
# Change it only if you generate the file on your own
sonar.swift.coverage.reportPattern=sonar-reports/cobertura.xml
# OCLint report generated by run-sonar.sh is stored in sonar-reports/oclint.xml
# Change it only if you generate the file on your own
sonar.swift.swiftlint.report=sonar-reports/swiftlint.txt
# Change it only if you generate the file on your own
#sonar.swift.tailor.report=sonar-reports/*tailor.txt
# Paths to exclude from coverage report (surefire, 3rd party libraries etc.)
sonar.swift.excludedPathsFromCoverage=build,DerivedData,fastlane,Pods,reports,testSonarTests,testSonarUITests,xcov_output
sonar.swift.excludedPathsFromCoverage=.*Tests.*
##########################
# Tailor configuration #
##########################
# Tailor configuration
# -l,--max-line-length=<0-999>                  maximum Line length (in characters)
#    --list-files                               display Swift source files to be analyzed
#    --max-class-length=<0-999>                 maximum Class length (in lines)
#    --max-closure-length=<0-999>               maximum Closure length (in lines)
#    --max-file-length=<0-999>                  maximum File length (in lines)
#    --max-function-length=<0-999>              maximum Function length (in lines)
#    --max-name-length=<0-999>                  maximum Identifier name length (in characters)
#    --max-severity=<error|warning (default)>   maximum severity
#    --max-struct-length=<0-999>                maximum Struct length (in lines)
#    --min-name-length=<1-999>                  minimum Identifier name length (in characters)
sonar.swift.tailor.config=--no-color --max-line-length=100 --max-file-length=500 --max-name-length=40 --max-name-length=40 --min-name-length=4

When I execute my sonar scanner I get Execution Success message. But when I go to my sonar console there I get bugs related to some html or python file. I am not getting anything related to Swift generated there. Please check the screenshots below:

enter image description here

enter image description here

enter image description here

I feel that somehow Sonar plugin is not getting mapped with SonarQube. Also, I can see that SonarFiles are generated as below:

enter image description here

How can I fix it in order to get my SonarQube running?


Solution

  • The script was fine. In addition to installing the sonarqube as mentioned above I had also installed another version from homebrew. so when I was trying to run Sonar I was actually running sonar from brew and not the above one. Sonar from brew did not contain any plugin so I was not able to scan my Swift code.