Mac 配置jenkins集成OCLint代码检测
一 .安装oclint
1.Homebrew安装OCLint
brew tap oclint/formulae
brew install oclint
输入oclint,验证
$ oclint
oclint: Not enough positional command line arguments specified!
Must specify at least 1 positional arguments: See: oclint -help
证明安装成功.
2、安装包安装
下载安装包source code(tar.gz) Git连接
二.安装xcpretty
sudo gem install -n /usr/local/bin xcpretty
三.Xcode中代码检测
1.xcode 添加Run Script执行脚本
点击加号
创建一个新的Target,选择Aggregate
添加Run Script
Xcode上Shell脚本,没有Pods的脚本编写代码:
source ~/.bash_profile
cd ${SRCROOT}
xcodebuild clean
xcodebuild build | tee xcodebuild.log | xcpretty -r json-compilation-database -o compile_commands.json
oclint-json-compilation-database -- -report-type Xcode
如果有cocoapods
source ~/.bash_profile
cd ${SRCROOT}
xcodebuild clean
xcodebuild -workspace MISTSTrainer.xcworkspace -scheme MISTSTrainer | xcpretty -r json-compilation-database --output compile_commands.json
oclint-json-compilation-database -v \
-e Pods \
oclint_args -- -report-type xcode \
-disable-rule ObjCAssignIvarOutsideAccessors \
-disable-rule ShortVariableName \
-rc=MINIMUM_CASES_IN_SWITCH=3 \
-rc=CYCLOMATIC_COMPLEXITY=10 \
-rc=LONG_CLASS=700 \
-rc=LONG_LINE=200 \
-rc=NCSS_METHOD=40 \
-rc=NESTED_BLOCK_DEPTH=5 \
-rc=TOO_MANY_FIELDS=20 \
-rc=TOO_MANY_METHODS=30 \
-rc=TOO_MANY_PARAMETERS=6
exit
2.用shell脚本终端执行
进入工程文件夹下,在终端执行 vi oclint.sh
添加代码:
#!/bin/bash
# 指定编码
export LANG="zh_CN.UTF-8"
export LC_COLLATE="zh_CN.UTF-8"
export LC_CTYPE="zh_CN.UTF-8"
export LC_MESSAGES="zh_CN.UTF-8"
export LC_MONETARY="zh_CN.UTF-8"
export LC_NUMERIC="zh_CN.UTF-8"
export LC_TIME="zh_CN.UTF-8"
function checkDepend () {
command -v xcpretty >/dev/null 2>&1 || {
echo >&2 "I require xcpretty but it's not installed. Install:gem install xcpretty";
exit
}
command -v oclint-json-compilation-database >/dev/null 2>&1 || {
echo >&2 "I require oclint-json-compilation-database but it's not installed. Install:brew install oclint";
exit
}
}
function oclintForProject () {
# 检测依赖
checkDepend
projectName=$1
scheme=$2
reportType=$3
REPORT_PMD="pmd"
REPORT_XCODE="xcode"
mywork