You are on page 1of 2

Static code analysis using Sonar

Contributed by Khurshidali Shaikh on 6 Jun 2011

Sonar is a static code analysis tool that covers below aspects of code quality. 1. 2. 3. 4. 5. 6. 7. Architecture & design Code comments Coding rules for mainly using checkstyle Potential bugs Code complexity Unit tests and code coverage Code Duplications

Download and install Sonar Assuming you have java already installed 1. Download the latest version from this page - http://www.sonarsource.org/downloads/ 2. Unzip the package to a folder. Thats it Starting Sonar 1. Go to sonar installation directorys bin folder 2. Based on your platform and architecture go to the corresponding directory under bin and run the sonar.sh start (for *nix platform) or StartSonar.bat start (for windows platform) 3. For windows there are also scripts to make Sonar as a windows service. 4. Once Sonar is started it will be accessible at this ulr http://localhost:9000 . For remote access replace localhost with the address of the sonar server. Also 9000 is the default port and can be changed from conf/sonar.properties Analyzing project using Sonar Until recently it was only possible to use maven along with Sonar. From sonar 2.6 an ANT Task is available to use Sonar in ANT based projects. Below are the steps to use Sonar from ANT. 1. Download the Sonar ANT Task and copy in your ANT_HOME/lib directory 2. Open your projects build.xml and add the below xml to it Neev Information Technologies Pvt. Ltd. www.neevtech.com sales@neevtech.com

Once the above is done run ant sonar This will run sonar on your code and push the metrics to the sonar server. Once the ant task is completed launch your sonar server (http://localhost:9000 or whatever) and view the reports. Sonar Configuration Sonar can be customized by changing settings in conf/sonar.properties file. Things you may typically want to change. 1. Port, ip at which sonar should run 2. Database settings to make Sonar run on a database like MySQL, Postgres , etc instead of the default derby database More. Sonar has some interesting plugins to enhance the features of Sonar and to facilitate analysis of code written in languages other than java. The complete plugin list is available here http://docs.codehaus.org/display/SONAR/Sonar+Plugin+Library For more reading visit -http://docs.codehaus.org/display/SONAR/Use+Sonar

Neev Information Technologies Pvt. Ltd.

www.neevtech.com

sales@neevtech.com

You might also like