Reader small image

You're reading from  Sonar Code Quality Testing Essentials

Product typeBook
Published inAug 2012
Reading LevelIntermediate
PublisherPackt
ISBN-139781849517867
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Charalampos S Arapidis
Charalampos S Arapidis
author image
Charalampos S Arapidis

Charalampos Arapidis is a Senior Software Engineer located in Athens, Greece specializing in J2EE application design and implementation. His other notable interests include data-mining/visualization techniques and tuning continuous integrated environments. From a very early age, Charalampos showed particular interest in advanced Mathematics and software development and has been honored twice at the Panhellenic Mathematical Contest for providing prototype and innovative solutions. He graduated in Computer and Software Engineering from the Polytechnic school of the Aristotle University. After graduation he dynamically entered the enterprise field where he helped his organization make the transition from legacy client server ERP and CRM applications to full stack J2EE with JSF implementations all in a streamlined and integrated development environment. The development of the Proteus Web Document Management System for the Greek Public Sector and his solutions to Kallikratis - the largest data integration project ever conceived in the later years of Greece's public sector – are two of his most recognizable achievements nationwide. Charalampos currently works at Siemens Enterprise Communications as a Senior Software Applications Engineer, designing and implementing Unified Communications software at multinational level. When not working, he enjoys blogging, playing the classical guitar, and composing music, exploring new ways to translate polynomial equations to sound.
Read more about Charalampos S Arapidis

Right arrow

Chapter 11. Integrating Sonar

In this chapter, we will discuss continuous integration and inspection processes and set up a continuous integration environment to enable these practices. We will install Software Configuration Management (SCM), and learn how to import and manage the source code hosted in it. Then, we will install the Jenkins Continuous Integration server (Jenkins CI) and connect a project in the repository to the build server to automate the build process. Finally, we will install the Jenkins Sonar plugin and configure a build job in Jenkins so as to automatically execute a Sonar analysis after each build.

In this chapter, we cover:

  • The Continuous Inspection paradigm

  • Installing Subversion

  • Setting up a Subversion server

  • Installing Jenkins CI Server

  • Configuring Jenkins

  • Creating a build job

  • Installing the Sonar plugin

  • Building and monitoring your project

The Continuous Inspection paradigm


Continuous integration is a software development practice where team developers integrate their code frequently. Each time a change is committed to the source code a new build is provided, usually through an automated process. The project grows incrementally, a stable build is always available for every iteration, and build errors can be identified by team members quickly.

Continuous inspection expands and builds upon this practice, adding a layer of quality analysis at each iteration. While continuous integration ensures stability and minimizes the effort of merging source code within the project, continuous inspection tracks quality requirements in an effort to control the quality of the final product. To enable continuous inspection, data collection and analysis is required after each build is produced by the build server.

Continuous integration servers

A continuous integration server or build server is responsible for executing build jobs and storing...

Installing Subversion


Subversion is a version control system developed by the Apache Software Foundation. A central Subversion server manages different versions of files/projects, while developers connect to the server via command line or GUI tools to commit their changes to the code. For more information on Subversion, visit the project's home page at http://subversion.apache.org/.

For the needs of the book, we will only use basic commands to import a project into Subversion and commit changes to files. To learn more about Subversion, download the free book Version Control with Subversion from http://svnbook.red-bean.com/ or visit Apache's Subversion documentation page at http://subversion.apache.org/docs/.

Next, we will install the Subversion server and its client on Linux and Windows.

Ubuntu/Debian Subversion installation

Ubuntu and Debian distributions maintain Subversion projects and are available within the Synaptic Package Manager tool. To install both the Subversion server and client...

Setting up a Subversion server


Next, we will create a repository for our projects, configure a user named svnpackt to have access to the repository, and import a dummy Maven project named packt-app into the repository. The process is the same for Linux and Windows.

Creating a Subversion repository

A Subversion repository is simply a directory in the filesystem containing repository configuration files and our project's files. To create a repository, open a terminal and enter the following command:

$ svnadmin create $PATH_REPO

Replace $PATH_REPO with a directory, for example, /home/dev/repo.

To verify the creation of the repository, navigate to $PATH_REPO. The following directories should have been created:

  • conf: Subversion configuration files

  • db: Project data files and revisions

  • hooks: Templates for useful automation commands

  • locks: Logs of locked files, checked out and modified by developers

  • format (file): Contains information about the repository's layout

  • README.txt (file): Getting started...

Installing the Jenkins CI server


The Jenkins Continuous Integration server, formerly known as Hudson before the renaming of the project took place, has been created by Kohsuke Kawaguchi. The official site of the project is available at http://jenkins-ci.org/. At the end of the installation process, you will have a running Jenkins server at http://localhost:8080/.

Here is how the welcome page looks:

Ubuntu/Debian Jenkins installation

Enter the following command to add the necessary key for the Jenkins Debian package repository:

$ wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -

To add the repository, add the following APT line entry in your /etc/apt/ sources.list:

deb http://pkg.jenkins-ci.org/debian binary/

Alternatively, you can run the Synaptic Package Manager tool and select Repositories from the Settings menu. Select the Third-Party Software tab and click on the Add button to enter the repository's APT line. Click on Add Source and Close to close the...

Configuring Jenkins


Ensure that the Jenkins service is running and go to http://localhost:8080/. From there, click on the Manage Jenkins link on the left menu to view the list of links leading to different configuration pages. Click on the top one, Configure System, to navigate to the configuration dashboard. This dashboard features many different sections which we will configure one by one.

JDK configuration

Click on the Add JDK button to expand this section. If your installed JDK has not been auto-detected by Jenkins, you have to enter it manually in the Name field. Unless, of course, you want Jenkins to install JDK automatically for you, in which case you check the Install automatically checkbox.

Maven configuration

Click on the Add Maven button and fill in the Name and MAVEN_HOME fields to match your own Maven installation. Jenkins will use this Maven installation to execute builds. Alternatively, you can check the Install automatically checkbox and have Jenkins install it automatically...

Creating a build job


Next, we will create a new build job for the packt-app Maven project. Log in to Jenkins and click on the New Job link from the left. Enter a job name and select the maven2/3 radio button. Then, click on OK to proceed to the job's configuration screen.

Click on the Subversion radio button and enter the Repository URL of the packt project. Remember to replace the $PATH_REPO environment variable with the repository directory as it is configured in your own system. Leave the rest of the fields to their default values.

Configure the Build Triggers section as shown in the following screenshot:

The Poll SCM value 5 * * * * is a cron expression and means that Jenkins will poll the Subversion server every five minutes and if any changes are detected, it will update the source code to pull the changes and automatically execute the packt-app build job. Click on the question mark beside the Poll SCM field for more configuration options.

Cron expression and scheduling

Cron is a time...

Installing the Sonar plugin


Before we test our new job, let's install the Sonar plugin. The Sonar plugin enables Jenkins to initiate a Sonar analysis after each build. From the Jenkins home page http://localhost:8080/, click on the Manage Jenkins link, and Manage Plugins from the next screen. Click on the Available tab and search (Ctrl + F) for Sonar to find and select the Sonar plugin. Then, click on the Install without restart button to start the installation process.

While Jenkins is downloading and installing the plugin, make sure to check the Restart Jenkins option as shown in the following screenshot. This will ensure that Jenkins restarts immediately once the installation is complete.

With the Sonar plugin installed, go to Manage Jenkins | Configure System and scroll down to the Sonar section. Provide a name for the Sonar server and click on Save. If the Sonar server is installed at a URL other than the default one (http://localhost:9000/), click on the Advanced... button and enter...

Summary


In this chapter, we went through the process of setting up and configuring an integrated build and quality analysis environment. We installed Subversion, Jenkins Continuous Integration server, and the necessary Sonar plugin.

We configured Jenkins to poll the source code repository and execute a build process and Sonar analysis whenever changes are detected. From now on, every time a developer commits a change to the repository, a new build and Sonar analysis will be available.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Sonar Code Quality Testing Essentials
Published in: Aug 2012Publisher: PacktISBN-13: 9781849517867
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Charalampos S Arapidis

Charalampos Arapidis is a Senior Software Engineer located in Athens, Greece specializing in J2EE application design and implementation. His other notable interests include data-mining/visualization techniques and tuning continuous integrated environments. From a very early age, Charalampos showed particular interest in advanced Mathematics and software development and has been honored twice at the Panhellenic Mathematical Contest for providing prototype and innovative solutions. He graduated in Computer and Software Engineering from the Polytechnic school of the Aristotle University. After graduation he dynamically entered the enterprise field where he helped his organization make the transition from legacy client server ERP and CRM applications to full stack J2EE with JSF implementations all in a streamlined and integrated development environment. The development of the Proteus Web Document Management System for the Greek Public Sector and his solutions to Kallikratis - the largest data integration project ever conceived in the later years of Greece's public sector – are two of his most recognizable achievements nationwide. Charalampos currently works at Siemens Enterprise Communications as a Senior Software Applications Engineer, designing and implementing Unified Communications software at multinational level. When not working, he enjoys blogging, playing the classical guitar, and composing music, exploring new ways to translate polynomial equations to sound.
Read more about Charalampos S Arapidis