ios利用OClint + SonarQube进行代码扫描

作者: shaneZhang 分类: ios技术 发布时间: 2015-08-15 17:10

前提

以上工具可自行安装,有些可通过brew进行安装

配置环境

以下是sonnar-runner的环境配置

#Configure here general information about the environment, such as SonarQube DB details for example
#No information about specific project should appear here

#----- Default SonarQube server
sonar.host.url=http://localhost:9000

#----- PostgreSQL
#sonar.jdbc.url=jdbc:postgresql://localhost/sonar

#----- MySQL
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8

#----- Oracle
#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE

#----- Microsoft SQLServer
#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor

#----- Global database settings
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar

#----- Default source code encoding
sonar.sourceEncoding=UTF-8

#----- Security (when 'sonar.forceAuthentication' is set to 'true')
sonar.login=admin
sonar.password=admin

在项目工程中添加一个sonar-project.properties文件,内容如下

##########################
# Required configuration #
##########################

sonar.projectKey=timeRadio
sonar.projectName=timeRadio
sonar.projectVersion=2.0
sonar.language=objc

# Project description
sonar.projectDescription=timeRadio

# Path to source directories 
sonar.sources=timeRadio
# Path to test directories (comment if no test)
#sonar.tests=testSrcDir


# Xcode project configuration (.xcodeproj or .xcworkspace)
# -> If you have a project: configure only sonar.objectivec.project
# -> If you have a workspace: configure sonar.objectivec.workspace and sonar.objectivec.project
# and use the later to specify which project(s) to include in the analysis (comma separated list)
#sonar.objectivec.project=myApplication.xcodeproj 
sonar.objectivec.workspace=timeRadio.xcworkspace

# Scheme to build your application
sonar.objectivec.appScheme=timeRadio
# Scheme to build and run your tests (comment following line of you don't have any tests)
#sonar.objectivec.testScheme=myApplicationTests

##########################
# Optional configuration #
##########################

# Encoding of the source code
sonar.sourceEncoding=UTF-8

# 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/

# Cobertura report generated by run-sonar.sh is stored in sonar-reports/coverage.xml
# Change it only if you generate the file on your own
# sonar.objectivec.coverage.reportPattern=sonar-reports/coverage*.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.objectivec.oclint.report=oclint.xml

# Paths to exclude from coverage report (tests, 3rd party libraries etc.)
# sonar.objectivec.excludedPathsFromCoverage=pattern1,pattern2
sonar.objectivec.excludedPathsFromCoverage=.*Tests.*

# Project SCM settings
# sonar.scm.enabled=true
# sonar.scm.url=scm:git:https://...

执行shell分析

xcodebuild -scheme timeRadio -workspace timeRadio.xcworkspace -configuration Debug clean build | tee xcodebuild.log
oclint-xcodebuild xcodebuild.log
oclint-json-compilation-database -- -report-type pmd -o sonar-reports/oclint.xml
/etc/sonar-runner/bin/sonar-runer

备忘插件

汉化插件和oc代码分析插件

传送门

如果觉得我的文章对您有用,请随意打赏。如果有其他问题请联系博主QQ(909491009)或者下方留言!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注