在 Xcode 中使用 Sonarqube

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29910721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:05:20  来源:igfitidea点击:

Using Sonarqube with Xcode

objective-cxcodesonarqube

提问by Devang

I am following thisarticle to integrate SonarQube with Xcode and analyse Objective-C code. Though the setup is functional and getting no error/warnings after running the shell script, no violations are shown in the Dashboard. All i get to see is basic metrics like no. of lines of code, no. of files, etc. Is there anyone who has tried this and guide me further. enter image description here

我正在关注这篇文章以将 SonarQube 与 Xcode 集成并分析 Objective-C 代码。尽管设置是正常的,并且在运行 shell 脚本后没有收到错误/警告,但仪表板中没有显示任何违规行为。我所看到的只是基本的指标,比如没有。代码行数,没有。文件等。有没有人试过这个并进一步指导我。 在此处输入图片说明

回答by Pavithra Duraisamy

In addition to the article you have specified above, I have few additions to that. You can follow the steps below,

除了您在上面指定的文章之外,我还有一些补充内容。您可以按照以下步骤操作,

Prerequisites:

先决条件

  • Sonar
  • Sonar-runner
  • SonarQube Objective-C plugin (Licensed)
  • XCTool
  • OCLint (violations) and gcovr (code coverage)
  • MySql and JDK
  • 声纳
  • 声纳转轮
  • SonarQube Objective-C 插件(已授权)
  • XC工具
  • OCLint(违规)和 gcovr(代码覆盖率)
  • MySql 和 JDK

Installation Steps:

安装步骤:

  • Download and install MySql dmg. And then start the MySQL server from the System Preferences or via the command line or if restarted it has to be command line.
  • To start - sudo /usr/local/mysql/support-files/mysql.server start
  • To restart - sudo /usr/local/mysql/support-files/mysql.server restart
  • To stop - sudo /usr/local/mysql/support-files/mysql.server stop

  • Download and install latest JDK version.

  • Go to the terminal and enter the following commands to install the prerequisites. (Homebrew is the package management system for Mac Operating System. to install homebrew, enter the command -

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)")
    
  • Sonar - brew install sonar

  • Sonar-runner - brew install sonar-runner
  • XCTool - brew install xctool
  • OCLint - brew install oclintor

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

  • 下载并安装 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 操作系统的包管理系统。要安装 Homebrew,输入命令 -

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)")
    
  • 声纳—— 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))
    
  • gcovr - brew install gcovr

Configuration:

配置:

- Set environment path of the Sonar:

- 设置声纳的环境路径:

export SONAR_HOME=/usr/local/Cellar/sonar-runner/2.4/libexec
export SONAR=$SONAR_HOME/bin
export PATH=$SONAR:$PATH

finally the command echo $SONAR_HOMEshould return the path - /usr/local/Cellar/sonar-runner/2.4/libexec

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

- Set up MySql DB:

- 设置 MySQL 数据库:

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

- Set Sonar configuration settings:

- 设置声纳配置设置:

vi /usr/local/Cellar/sonar/5.1.2/libexec/conf/sonar.properties

You can comment out most options except credentials and mysql and make sure that you enter the correct database name.

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

eg:

例如:

sonar.jdbc.url=jdbc:mysql://localhost:3306/**sonar_firstdb**?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true

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

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

You can comment out most options except credentials and mysql and make sure that you enter the correct database name.

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

eg:

例如:

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar_firstdb?useUnicode=true&characterEncoding=utf8
  • Start sonar using the command-

    sonar start
    
  • 使用命令启动声纳-

    sonar start
    

The command will launch sonar so navigate to http://localhost:9000in your browser of choice. Login (admin/admin) and have a look around.

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

  • Now you have to install the Objective-C or Swift plugin.
  • 现在你必须安装 Objective-C 或 Swift 插件。

Move to Settings -> System -> Update Center -> Available Plugins (install the required plugin).

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

You have to restart the sonar to complete the installation once the pligin is added, And add license key once the plugin is installed.

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

  • through terminal go to the root directory of a project you want sonar to inspect, and create a project specific properties file with the following command:

    vi sonar-project.properties
    
  • 通过终端转到您希望声纳检查的项目的根目录,并使用以下命令创建项目特定的属性文件:

    vi sonar-project.properties
    

Add the following project specific properties and edit the bolded sections as per your project.

添加以下项目特定属性并根据您的项目编辑粗体部分。

// 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://...
  • Save the file and you can reuse the same for other projects.
  • In the project root directory run the command - sonar-runner
  • 保存文件,您可以将其重复用于其他项目。
  • 在项目根目录中运行命令 - sonar-runner

回答by Cyupa

You should try it with an older version of SonarQube (< 4.0 usually works).

您应该尝试使用较旧版本的 SonarQube(< 4.0 通常有效)。