Running Sonarqube on Mac

Good morning, Guys!

Welcome back! 🙂 Finally i have time to write something on my wordpress again 😀

So, this time i’m going to write about Sonarqube and install it on my mac. First of all, what is Sonarqube? Sonarqube is one of open source platform for continuous inspection of code quality. Sonarqube has some features that could make our development will run better, for more information about its features you may check here.

Next, You can install Sonarqube on your Mac, Windows, or linux system. You can check the requirements here. To download Sonarqube you can check here.

After download the archive file and extract it, go to your Sonarqube home directory /bin/[your environment]/

To run Sonarqube service, you can run ./sonar.sh start if everything is ok, it will start the service and run on port 9000. Now you can try to open browser and access it.

Screen Shot 2017-04-18 at 10.00.41 AM.png

So that is just the Sonarqube service that can show your code quality. Now, we need a sonar-scanner to scan our code and some sample project.

Go here to download the scanner and follow the instruction there to install it.

Now, you can try to open to your project directory and add the sonar-project.properties file in it. After that, run sonar-scanner to run the scanning process.

Here my sample project from sonarqube’s website:

javascript-sonar-runner-lcov sudo sonar-scanner
Password:
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /Users/rezasetiadi/Documents/setiadi/sonarqube/SonarSource-sonar-examples-07a1bd5/projects/languages/javascript/javascript-sonar-runner-lcov/sonar-project.properties
INFO: SonarQube Scanner 3.0.0.702
INFO: Java 1.8.0_121 Oracle Corporation (64-bit)
INFO: Mac OS X 10.12.3 x86_64
INFO: User cache: /var/root/.sonar/cache
INFO: Load global settings
INFO: Load global settings (done) | time=111ms
INFO: User cache: /var/root/.sonar/cache
INFO: Load plugins index
INFO: Load plugins index (done) | time=16ms
INFO: Download sonar-csharp-plugin-5.7.0.612.jar
INFO: Download sonar-java-plugin-4.5.0.8398.jar
INFO: Download sonar-flex-plugin-2.3.jar
INFO: Download sonar-php-plugin-2.9.2.1744.jar
INFO: Download sonar-scm-svn-plugin-1.4.0.522.jar
INFO: Download sonar-javascript-plugin-2.20.0.4207.jar
INFO: SonarQube server 6.3.1
INFO: Default locale: “en_US”, source code encoding: “UTF-8”
INFO: Process project properties
INFO: Load project repositories
INFO: Load project repositories (done) | time=16ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=132ms
INFO: Load active rules
INFO: Load active rules (done) | time=972ms
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=87ms
WARN: SCM provider autodetection failed. No SCM provider claims to support this project. Please use sonar.scm.provider to define SCM of your project.
INFO: Publish mode
INFO: Project key: org.sonarqube:javascript-lcov-sq-scanner
INFO: ————- Scan JavaScript :: Coverage LCOV :: SonarQube Scanner
INFO: Load server rules
INFO: Load server rules (done) | time=162ms
INFO: Language is forced to js
INFO: Initializer GenericCoverageSensor
INFO: Initializer GenericCoverageSensor (done) | time=0ms
INFO: Base dir: /Users/rezasetiadi/Documents/setiadi/sonarqube/SonarSource-sonar-examples-07a1bd5/projects/languages/javascript/javascript-sonar-runner-lcov
INFO: Working dir: /Users/rezasetiadi/Documents/setiadi/sonarqube/SonarSource-sonar-examples-07a1bd5/projects/languages/javascript/javascript-sonar-runner-lcov/.scannerwork
INFO: Source paths: sources
INFO: Test paths: tests
INFO: Source encoding: UTF-8, default locale: en_US
INFO: Index files
INFO: 6 files indexed
INFO: Quality profile for js: Sonar way
INFO: Sensor NoSonar Sensor [php]
INFO: Sensor NoSonar Sensor [php] (done) | time=1ms
INFO: Sensor Coverage Report Import [csharp]
INFO: Sensor Coverage Report Import [csharp] (done) | time=0ms
INFO: Sensor Coverage Report Import [csharp]
INFO: Sensor Coverage Report Import [csharp] (done) | time=0ms
INFO: Sensor Unit Test Results Import [csharp]
INFO: Sensor Unit Test Results Import [csharp] (done) | time=0ms
INFO: Sensor XmlFileSensor [java]
INFO: Sensor XmlFileSensor [java] (done) | time=0ms
INFO: Sensor Analyzer for “php.ini” files [php]
INFO: Sensor Analyzer for “php.ini” files [php] (done) | time=3ms
INFO: Sensor JavaScript Squid Sensor [javascript]
INFO: 4 source files to be analyzed
WARN: Since SonarQube 6.2 property ‘sonar.javascript.lcov.reportPath’ is deprecated. Use ‘sonar.javascript.lcov.reportPaths’ instead.INFO: 4/4 source files have been analyzed

INFO: Unit Test Coverage Sensor is started
INFO: Analysing [/Users/rezasetiadi/Documents/setiadi/sonarqube/SonarSource-sonar-examples-07a1bd5/projects/languages/javascript/javascript-sonar-runner-lcov/report/lcov.dat]
INFO: Integration Test Coverage Sensor is started
INFO: Overall Coverage Sensor is started
INFO: Analysing [/Users/rezasetiadi/Documents/setiadi/sonarqube/SonarSource-sonar-examples-07a1bd5/projects/languages/javascript/javascript-sonar-runner-lcov/report/lcov.dat]
INFO: Sensor JavaScript Squid Sensor [javascript] (done) | time=503ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=15ms
INFO: Sensor Code Colorizer Sensor
INFO: Sensor Code Colorizer Sensor (done) | time=1ms
INFO: Sensor CPD Block Indexer
INFO: [email protected] is used for js
INFO: Sensor CPD Block Indexer (done) | time=1ms
INFO: No SCM system was detected. You can use the ‘sonar.scm.provider’ property to explicitly specify it.
INFO: Calculating CPD for 4 files
INFO: CPD calculation finished
INFO: Analysis report generated in 115ms, dir size=31 KB
INFO: Analysis reports compressed in 19ms, zip size=15 KB
INFO: Analysis report uploaded in 284ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/org.sonarqube:javascript-lcov-sq-scanner
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AVt_C73HBpklGzlph9bP
INFO: Task total time: 4.003 s
INFO: ————————————————————————
INFO: EXECUTION SUCCESS
INFO: ————————————————————————
INFO: Total time: 11.533s
INFO: Final Memory: 50M/343M
INFO: ————————————————————————

After execution is success, now let’s check our Sonarqube website:

Screen Shot 2017-04-18 at 10.14.24 AM.png

You can see that our sample project is passed the quality gate provided by Sonarqube. You can see each detail of the scan result. If you find something wrong with the code or your code is not passed the test, go tell your developer to fix it 😀 🙂

So, guys, that’s all for today. Next time i will try to make a post about integrate Sonarqube with Jenkins Server so we could make a better continuous integration in our development.

збогом.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *