Showing posts with label SonarQube. Show all posts
Showing posts with label SonarQube. Show all posts

Thursday 23 November 2017

How to configure Jacoco plugin in Maven

Guys, for getting the unit test coverage report in SonarQube for code quality and analysis, let us look into how to use the Jacoco plugin for the same. In this post we'll see how to configure Maven with the Jacoco plugin. FYI Jacoco is a free code coverage tool for Java


In your main parent POM, let us enter the Sonar properties firstly, as follows :

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Sonar -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
<drools.version>5.5.0.Final</drools.version> 
</properties> 

Now in the <pluginManagement> section, let us enter the configuration for the Jacoco plugin.

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

Hope it helps guys. Until next time, ciao!

Automate regular backups of SonarQube's DB using bash script

Guys, this post will be useful if you are using SonarQube for code analysis and quality control. In today's post we will look into how to automate taking regular backups of SonarQube's back-end database.


For illustration, we will use MySql DB to store SonarQube's metadata which includes analysis parameters like code smells, bugs, code coverage, unit test coverage etc. In this case we host Sonar on a linux machine, so we write a bash script to take regular backups of the MySql DB. Take a look at a simple sample script below :

#!/bin/bash
# script for taking database dump of sonar

user="root";
hostname="localhost";
db_name="sonar";
dateformat=`date +%d-%m-%y`;

mysqldump --defaults-extra-file="/usr/local/cron_scripts/.my.cnf" -u $user -h $hostname sonar | gzip > /usr/local/mysql_dumps/sonar_dump_$dateformat.sql.gz

chmod 755 /usr/local/mysql_dumps/sonar_dump_$dateformat.sql.gz

As you see, we have used mysqldump to take dump of the database, zip it, append it with the current date and store it at the said location.

Taking dumps of Sonar can be extremely useful for the purpose of importing and exporting of a Sonar instance from one machine to another without losing the analysis history.

Tuesday 10 October 2017

LDAP authentication for SonarQube 5.6

Guys, if your project uses SonarQube for analyzing and improving the code quality, this is the post you should be interested in. In this post, we look into how to configure the organization-specific LDAP settings for SonarQube version 5.6

First of all, before we proceed, in order to enable LDAP authentication in SonarQube, you will have to install the LDAP plugin from the update center. In this illustration, we have the LDAP plugin version 1.4 installed. Newer versions of the plugin will be available periodically.



Now, navigate through your SonarQube installation directory => conf folder to find the sonar.properties file.

In this file, you'll able to configure LDAP details to enable LDAP user authentication. In case you're not aware of the specific credentials, kindly check the same from an authorized  administrator.

A sample illustration below will give you the look and feel of how the LDAP settings should look like.

#-------------------------------------------------------------------------------------------------
# LDAP related settings
sonar.security.realm=LDAP
sonar.security.updateUserAttributes=false
ldap.url=ldap://17.16.10.14:389
ldap.bindDn=CN=BUILDER,OU=USERS,OU=AdminPRivilege,DC=company,DC=com
ldap.bindPassword=ldap-password-here
ldap.user.baseDn=dc=company,dc=com
ldap.user.request=(&(sAMAccountName={login}))

Note that the above values are just an example and will vary for each organization. For more information, kindly check the LDAP plugin page here.
Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker