Put your technical
debt under control
SonarQube is an open source software quality management tool,
dedicated to continuously analyze and measure source code quality. Using
SonarQube throughout the whole development project life cycle drastically
improves visibility for every stakeholder. This gained visibility allows to
manage risks, reduce maintenance costs and improve agility by implementing a
real quality first approach. Teams can now seamlessly embrace quality with fun.
Installing
SonarQube
|
Download and unzip the SonarQube
distribution
wget http://dist.sonar.codehaus.org/sonarqube-4.0.zip -O
/var/lib/sonar-4.0.zip
cd /var/lib/
unzip sonar-4.0.zip
mv sonarqube-4.0 sonar
cd /var/lib/sonar/conf/
vim sonar.properties
#----- Credentials
# Permissions to create tables and indexes must be granted to JDBC user. # The schema must be created first. change this password according to your database password. sonar.jdbc.username: sonar sonar.jdbc.password: sonar
# Comment the embedded database and uncomment the following line to use
MySQL
sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
#----- Connection pool settings
sonar.jdbc.maxActive: 20 sonar.jdbc.maxIdle: 5 sonar.jdbc.minIdle: 2 sonar.jdbc.maxWait: 5000 sonar.jdbc.minEvictableIdleTimeMillis: 600000 sonar.jdbc.timeBetweenEvictionRunsMillis: 30000
# Delay (in seconds) between processing of notification queue
sonar.notifications.delay=60 |
Install Sonar PHP
Plugin
|
wget http://repository.codehaus.org/org/codehaus/sonar-plugins/sonar-php-plugin/0.2/sonar-php-plugin-0.2.jar
cp sonar-php-plugin-0.2.jar /var/lib/sonar/extensions/plugins
Installing SonarQube Runner :
Follow the below steps for configuring
SonarQube Runner to analyze your source code.
unzip sonar-runner-dist-2.3.zip
mv sonar-runner-2.3 /var/lib/sonar-runner/
vim sonar-runner.properties
#Configure here general information about the environment, such as
SonarQube DB details for example
#No information about specific project should appear here
#----- Default SonarQube server
sonar.host.url=http://localhost:9000
#----- PostgreSQL
#sonar.jdbc.url=jdbc:postgresql://localhost/sonar
#----- MySQL
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
#----- Oracle
#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE
#----- Microsoft SQLServer
#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor
#----- Global database settings
sonar.jdbc.username=sonar sonar.jdbc.password=sonar
#----- Default source code encoding
sonar.sourceEncoding=UTF-8
#----- Security (when 'sonar.forceAuthentication' is set to 'true')
#sonar.login=admin #sonar.password=admin |
N.B. Default sonar web user/password :
admin/admin
Link your project
|
Go to your project's root directory and add a new file with this
name sonar-project.properties and add the below text and change according
to your project. In my case project root directory is /var/www/myproject
# Required metadata
sonar.projectKey=myproject sonar.projectName=My project sonar.projectVersion=
# Path to the parent source code directory.
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. # Since SonarQube 4.2, this property is optional. If not set, SonarQube starts looking for source code # from the directory containing the sonar-project.properties file. sonar.sources=profiles/myprofile
# The value of the property must be the key of the language.
sonar.language=php
# Encoding of the source code
sonar.sourceEncoding=UTF-8
# Additional parameters
sonar.my.property=value |
After creating
"sonar-project.properties" file run sonar-runner as shown below (make
sure sonar is running) --
/var/lib/sonar-runner/bin/sonar-runner start
-X
In case you are facing any issue then try with
the below command --
/var/lib/sonar-runner/bin/sonar-runner -Dsonar.projectKey=myproject
-Dsonar.projectName=MyProject -Dsonar.projectVersion=1.0-SNAPSHOT -Dsonar.sources=/var/www/myproject/profiles/myprofile -Dsonar.language=php -X
Start/Stop SonarQube
cd /var/lib/sonar/bin/linux-x86-64/
./sonar.sh stop
./sonar.sh start
Browse the results at http://<ip>:9000
N.B. SONAR is becoming
SONARQUBE
Reference Pages
|
Requirements : http://docs.codehaus.org/display/SONAR/Requirements
Installing : http://docs.codehaus.org/display/SONAR/Installing
Upgrading : http://docs.codehaus.org/display/SONAR/Upgrading
Analyze Code : http://docs.codehaus.org/display/SONAR/Analyzing+Source+Code
Analyzing with SonarQube Runner : http://docs.codehaus.org/display/SONAR/Analyzing+with+SonarQube+Runner
|
If this post is useful to you then please give a comments. Thanks.