Quality analysis using Sonarqube®
Introduction
Sonarqube® is a code quality analyser. It is available here.
This document make the assumption Sonarqube® is installed and operational with the Java, JavaScript, CSS and HTML code plugins. The easiest way to start a Sonarqube® server is to use the official Sonarqube® Docker image.
For instance you can use the following Docker compose file:
services:
sonarqube:
image: sonarqube:community
restart: always
ports:
- "127.0.0.1:9191:9000"
environment:
SONARQUBE_JDBC_URL: jdbc:postgresql://db:5432/sonar
SONARQUBE_JDBC_USERNAME: sonar
SONARQUBE_JDBC_PASSWORD: sonar
volumes:
- sonarqube_conf:/opt/sonarqube/conf
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_bundled-plugins:/opt/sonarqube/lib/bundled-plugins
db:
image: postgres:latest
restart: always
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar
POSTGRES_DB: sonar
volumes:
- postgresql_data:/var/lib/postgresql/data
volumes:
sonarqube_conf:
sonarqube_data:
sonarqube_extensions:
sonarqube_bundled-plugins:
postgresql_data:
This document only applies if you export your Simplicité modules as Git repositories. See this document for details.
In the rest of the document <sonar options>
corresponds to the options you use with your Sonarqube® installation and/or your repositories.
For instance it can be the server's custom URL and its credential: -Dsonar.host.url=http://localhost:9191 [-Dsonar.login=<login or toke > [-Dsonar.password=<password>]]
.
These common options can also be stored in environment variables and , see below.
Modules using Java
In this case the Simplicité module is considered as a Java module by Sonarqube®. As of Version 4.0.P22 this is straightforward as the Git repository of the Simplicité module is structured as an Apache Maven® project which is directly managed by Sonarqube®.
Prerequisites
You need to have Apache Maven® installed.
You may also want to set the Simplicite way profile as default Java profile in SonarQube to avoid useless issues in the context of a Simplicité module.
Usage
After cloning/pulling your module's Git repository you can launch the analysis by:
mvn clean compile org.sonarsource.scanner.maven:sonar-maven-plugin:RELEASE:sonar [<sonar options>]
The common options <sonar options>
can be stored in the MAVEN_OPTS
environment variable.
The other options (exclusions, ...) are generated by the Git export in the pom.xml
file's <properties>
section.
Note: if you module contains client-side JavaScript and CSS/LESS stylesheets they will also be analysed.
Modules using Rhino scripting
In this case the Simplicité module is considered as a JavaScript module by Sonarqube®. You need some additionals components (see below).
Prerequisite
You need to have Node.js installed, then you need to install the Sonarqube scanner additional NPM module:
sudo su -
npm install -g sonarqube-scanner
exit
Usage
After cloning/pulling your module's Git repository you can launch the analysis by:
sonar-scanner [<sonar options>]
The common options <sonar options>
can be stored in the SONAR_SCANNER_OPTS
environment variable.
The other options (exclusions, ...) are generated by the Git export in the sonar-project.properties
file.
Note: if you module contains also client-side JavaScript and CSS/LESS stylesheets they will also be analysed.