SonarQube安裝
準(zhǔn)備工作
1、已安裝JAVA環(huán)境
(Download Java for Mac OS X https://www.java.com/en/download/mac_download.jsp
http://www.oracle.com/technetwork/java/javase/downloads/index.html)
2、下載SonarQube與SonarQube Runner
下載地址:
3、運(yùn)行sonar
- 解壓sonarqube-6.7.1.zip
- 通過終端命令行cd到sonarqube解壓目錄下的/bin/macosx-universal-64文件夾
- 執(zhí)行
./sonar.sh startar-scanner - 瀏覽器訪問http://localhost:9000
-
出現(xiàn)以下頁面,表示安裝成功
about
SonarQube使用
sonarqube默認(rèn)支持的語言插件,在sonarqube-6.7.1/extensions/plugins 這個(gè)文件夾里可以看到。
plugins
其中的backelite-sonar-swift-plugin-0.3.5.jar是從這里下載的。
關(guān)于Open source Swift plugin for SonarQube的開源文件
具體操作步驟:
- 拷貝backelite-sonar-swift-plugin-0.3.5.jar文件到sonarqube-6.7.1/extensions/plugins里
- 下載run-sonar-swift.sh 文夾拷貝到swift項(xiàng)目的根目錄下(和你的projext.xcodeproj 文件同級)
- 下載sonar-project.properties文件拷貝到swift項(xiàng)目的根目錄下(和你的projext.xcodeproj 文件同級)
- 編輯sonar-project.properties文件,根據(jù)swift項(xiàng)目修改其中的參數(shù)
sonar-project.properties文件
##########################
# Required configuration #
##########################
# Project key will also be used for binary file
sonar.projectKey=prjKey
sonar.projectName=prjName
sonar.projectVersion=1.0
# Comment if you have a project with mixed ObjC / Swift
sonar.language=swift
# Project description
sonar.projectDescription=prjDescription
# Path to source directories
# 修改為swift的路徑
sonar.sources=SourceDir
# Path to test directories (comment if no test)
sonar.tests=TestDir
# Destination Simulator to run tests
# 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 6,OS=9.2
# 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
#指定 xcodeproj 或 xcodeproj + xcworkspace
#sonar.swift.project=MyPrj.xcodeproj
#sonar.swift.workspace=MyWrkSpc.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=myApp
# Scheme to build your application
sonar.swift.appScheme=MyScheme
# Configuration to use for your scheme. if you do not specify that the default will be Debug
sonar.swift.appConfiguration=MyConfiguration
# Encoding of the source code
sonar.sourceEncoding=UTF-8
sonar.swift.excludedPathsFromCoverage=.*Tests.*
sonar.swift.tailor.config=--max-line-length=100 --max-file-length=500 --max-name-length=40 --max-name-length=40 --min-name-length=4
- 終端命令行打開swift項(xiàng)目,執(zhí)行
sonar-scanner - 分析結(jié)束后,終端會(huì)顯示比如
INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/Kickstarter,打開提示的地址,可以看到分析結(jié)果。
report
參考文章