Monday, May 13, 2013

Optimize java code with SONAR



Sonar setup in eclipse


How to check quality of code using sonar?

        I.            Start sonar server
Download sonar
Inside bin folder there is a file named StartSonar.bash file,Double click on that file to start server.
sonar-3.3\sonar-3.3\bin\windows-x86-32  à StartSonar.bash

      II.            Download sonar runner
Set the class path for that sonar runner.
For eg;
  Set path= D:\Amal\Softwares\sonar-runner-2.0\sonar-runner-2.0\bin;%PATH%

    III.            Create sonar-project.properties file inside the eclipse project(root).
Contents:
# required metadata
sonar.projectKey=my:MRUnit
sonar.projectName=MRUnit
sonar.projectVersion=1.0
# path to source directories (required)
sonar.sources=src
# The value of the property must be the key of the language.
sonar.language=java

 IV.            Go to the root directory of project in command line and type sonar-runner
This will convert the eclipse project to sonar project.
     V.            Go to eclipse.Right click on the particular project. Go to configure. Select Associate with sonar. Tick the project you want to find on server. Click the button find on server. The group ID and artifact ID that we will automatically come.
  VI.            Right click on the particular project again. Go to Sonar and select open the project in sonar server. Now we can see all the details of that project in that UI.
Fig 1: Projects in sonar server.

 
Fig 2: Violations in project


Fig 3: Violations in detail

Alternatively you can check these details in the below given link

No comments:

Post a Comment