Mac下Sonar Swift的配置使用

SonarQube安装

准备工作

1、已安装JAVA环境
(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

下载地址:

SonarQube

SonarQube Scanner

3、运行sonar

  • 解压sonarqube-6.7.1.zip
  • 通过终端命令行cd到sonarqube解压目录下的/bin/macosx-universal-64文件夹
  • 执行./sonar.sh startar-scanner
  • 浏览器访问http://localhost:9000
  • 出现以下页面,表示安装成功


    about

SonarQube使用

sonarqube默认支持的语言插件,在sonarqube-6.7.1/extensions/plugins 这个文件夹里可以看到。

plugins

其中的backelite-sonar-swift-plugin-0.3.5.jar是从这里下载的。

关于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项目的根目录下(和你的projext.xcodeproj 文件同级)
  • 下载sonar-project.properties文件拷贝到swift项目的根目录下(和你的projext.xcodeproj 文件同级)
  • 编辑sonar-project.properties文件,根据swift项目修改其中的参数
    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项目,执行sonar-scanner
  • 分析结束后,终端会显示比如INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/Kickstarter,打开提示的地址,可以看到分析结果。
report

参考文章

Backelite/sonar-swift

Analyzing with SonarQube Scanner

Sonar Swift实践

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 新晋测试小白最近在研究sonarqube的静态代码检查,整理了关于sonarqube 如何在mac os x系统下...
    测试小白_stone阅读 1,981评论 0 1
  • 1.SonarQube Sonar的功能:是一个用于代码质量管理的开源平台,用于管理源代码的质量,可以从七个维度检...
    Broom阅读 9,454评论 0 6
  • CentOS MySQL SonarQube SonarQube Scanner 针对 Jacoco + Jenk...
    纳爱斯阅读 20,198评论 6 9
  • 夏日余热还没有散去,六人的宿舍风扇还在哗哗地响,偏偏大姨妈来了,痛得我紧紧裹着被子还满身冷汗,你答对了,我是那种会...
    蜗牛回家阅读 202评论 0 0
  • 儿时住在大杂院,清晨总是伴着炊烟和锅碗瓢盆的交响。老婶早早给汉舅舀起稠稠的2大碗白粥,汉舅吃早餐的时候,妈妈也开始...
    mimi播报阅读 363评论 4 4