使用Sonarqube和Xcode

Dev*_*ang 8 xcode objective-c sonarqube

我正在按照这篇文章将SonarQube与Xcode集成并分析Objective-C代码.虽然设置功能正常,并且在运行shell脚本后没有出现错误/警告,但仪表板中不会显示任何违规.我所看到的只是基本指标.代码行,没有.文件等等.是否有人试过这个并进一步指导我. 在此输入图像描述

小智 11

除了您上面指定的文章之外,我对此几乎没有补充.您可以按照以下步骤操作,

先决条件:

  • 声纳
  • 声纳亚军
  • SonarQube Objective-C插件(许可)
  • XCTool
  • OCLint(违规)和gcovr(代码覆盖)
  • MySql和JDK

安装步骤:

  • 下载并安装MySql dmg.然后从系统偏好设置或通过命令行启动MySQL服务器,或者如果重新启动它必须是命令行.
  • 开始 - sudo /usr/local/mysql/support-files/mysql.server start
  • 重启 - sudo /usr/local/mysql/support-files/mysql.server restart
  • 停止 - sudo /usr/local/mysql/support-files/mysql.server stop

  • 下载并安装最新的JDK版本.

  • 转到终端并输入以下命令以安装必备组件.(Homebrew是Mac操作系统的软件包管理系统.安装自制软件,输入命令 -

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)")
    
    Run Code Online (Sandbox Code Playgroud)
  • 声纳 - brew install sonar

  • 声纳 - 跑步者 - brew install sonar-runner
  • XCTool - brew install xctool
  • OCLint - brew install oclint

    brew install https://gist.githubusercontent.com/TonyAnhTran/e1522b93853c5a456b74/raw/157549c7a77261e906fb88bc5606afd8bd727a73/oclint.rb for version 0.8.1(updated))
    
    Run Code Online (Sandbox Code Playgroud)
  • gcovr - brew install gcovr

组态:

- 设置声纳的环境路径:

export SONAR_HOME=/usr/local/Cellar/sonar-runner/2.4/libexec
export SONAR=$SONAR_HOME/bin
export PATH=$SONAR:$PATH
Run Code Online (Sandbox Code Playgroud)

最后命令echo $SONAR_HOME应该返回路径 -/usr/local/Cellar/sonar-runner/2.4/libexec

- 设置MySql DB:

export PATH=${PATH}:/usr/local/mysql/bin
mysql -u root;
CREATE DATABASE sonar_firstdb;
CREATE USER 'sonar'@'localhost' IDENTIFIED BY 'sonar';
GRANT ALL PRIVILEGES ON sonar_firstdb.* TO 'sonar'@'localhost';
FLUSH PRIVILEGES;
exit
Run Code Online (Sandbox Code Playgroud)

- 设置声纳配置设置:

vi /usr/local/Cellar/sonar/5.1.2/libexec/conf/sonar.properties
Run Code Online (Sandbox Code Playgroud)

您可以注释掉除凭据和mysql之外的大多数选项,并确保输入正确的数据库名称.

例如:

sonar.jdbc.url=jdbc:mysql://localhost:3306/**sonar_firstdb**?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
Run Code Online (Sandbox Code Playgroud)

.vi /usr/local/Cellar/sonar-runner/2.4/libexec/conf/sonar-runner.properties

您可以注释掉除凭据和mysql之外的大多数选项,并确保输入正确的数据库名称.

例如:

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar_firstdb?useUnicode=true&characterEncoding=utf8
Run Code Online (Sandbox Code Playgroud)

该命令将启动声纳,因此在您选择的浏览器中导航到http:// localhost:9000.登录(admin/admin)并浏览一下.

  • 现在你必须安装Objective-C或Swift插件.

移至设置 - >系统 - >更新中心 - >可用插件(安装所需的插件).

添加pligin后,必须重新启动声纳才能完成安装,并在安装插件后添加许可证密钥.

添加以下项目特定属性,并根据项目编辑粗体部分.

// Required configuration 

sonar.projectKey=**com.payoda.wordsudoku**
sonar.projectName=**DragDrop**
sonar.projectVersion=**1.0**
sonar.language=**objc**

// Project description
sonar.projectDescription=**Sample description**

// Path to source directories
sonar.sources=**~/path to your project**
// 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=**DragDrop.xcodeproj**
// sonar.objectivec.workspace=myApplication.xcworkspace

// Scheme to build your application
sonar.objectivec.appScheme=**DragDrop**
// 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
// 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=sonar-reports/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://...
Run Code Online (Sandbox Code Playgroud)
  • 保存文件,您可以将其重用于其他项目.
  • 在项目根目录中运行命令 - sonar-runner


Cyu*_*upa 0

您应该尝试使用旧版本的 SonarQube(< 4.0 通常可以使用)。