Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Sonarqube with Xcode

I am following this article 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

like image 702
Devang Avatar asked Apr 28 '15 05:04

Devang


People also ask

Can SonarQube be integrated with build?

You can add the SonarQube plugin in your maven build to analyze your code. To show the results in your build server (hudson/jenkins/bamboo), you also need the SonarQube integration plugin for your build server.

Can SonarQube be integrated with ALM tools?

The following schema shows how SonarQube integrates with other ALM tools and where the various components of SonarQube are used. Developers code in their IDEs and use SonarLint to run local analysis. Developers push their code into their favourite SCM : git, SVN, TFVC, ...


1 Answers

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

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 oclint or

    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_HOME should return the path - /usr/local/Cellar/sonar-runner/2.4/libexec

- Set up 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

- 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.

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

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

eg:

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

    sonar start
    

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

  • Now you have to install the Objective-C or Swift plugin.

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.

  • 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
    

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
like image 98
Pavithra Duraisamy Avatar answered Nov 11 '22 23:11

Pavithra Duraisamy