Static Code Analysis Using Sonar
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 check style Potential bugs Code complexity Unit tests and code coverage Code Duplications
Download and install Sonar Assuming you has java already installed, 1. Download the latest version from this page - http://www.sonarsource.org/downloads/ 2. Unzip the package to a folder. That’s it Starting Sonar 1. Go to sonar installation directory’s 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 URL 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
Neev Information Technologies Pvt. Ltd.
www.neevtech.com
sales@neevtech.com
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 project’s build.xml and add the below xml to it Once this 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 Click here for more info. (This blog was authored by Mr. Khurshidali Shaikh, Chief Architect at Neev Technologies) Visit us at Neevtech.com to know more about our offerings.
Neev Information Technologies Pvt. Ltd.
www.neevtech.com
sales@neevtech.com