Even if we know everything about code quality, the human error factor will still persist. There is always a chance of making some error, as we are human after all.
Some, if not all such errors can be brought to notice using some quality management tool. There are several such tools/plugin which can be integrated into eclipse. All such tools can assist a developer with a code review, just like a peer code review. e.g.
- Java Analyzer
To know more read this..
Taking a big leap forward in learning code quality. I researched a bit and found about sonar. This is a standalone service which acts as a source quality management analyzer. Instead of being a single tool for code quality analysis. It has various components integrated in it. For details on sonar which is hosted at ‘codehaus’ visit sonar’s offcial website.
Setting up sonar to analyze maven projects.
- Download sonar from here. (I downloaded v3.4)
- Extract it to some folder.
- Open ‘sonar.properties’ situated in /conf folder and update the following properties –
– sonar.web.host: 127.0.0.1 // default host
– sonar.web.port: 9000 // default port where you can access sonar interface using a browser
– sonar.web.context: /
– sonar.jdbc.username: sonar // the admin username
– sonar.jdbc.password: sonar // the admin password
- By default the sonar service uses an in memory db H2. Default port is 9092 with URL ‘jdbc:h2:tcp://localhost:9092/sonar’.
However, a custom db should be used when using professionally for obvious reasons. One the following db can be used-
– MSSQLPlease note that for educational purposes, you may conveniently skip Step 4.
- Now, you’ll have to run the standalone service situated in bin folder.
e.g. if using windows (64bit) just run StartSonar.bat situated in binwindows-x86-64.
- To view the interface, open http://localhost:9000 in a browser.
- I’m sure you loved what you saw.
- Lets start analyzing
Now, to hit the nail on the head, simple run mvn sonar:sonar to analyze the code.
- Once you’ve run the analysis, view the results @ http://localhost:9000.
Voila, now you know a lot more about the code you’ve run the analysis for.
For those who are familiar with hudson and jenkins, just go ahead and integrate sonar into your hudson. You simply have to follow the given steps-
- Install sonar plugin into hudson.
- Restart hudson.
- In manage hudson/jenkins page, you’ll find a sonar section. Add provide your sonar setup info.
- To configure a sonar step in your jobs, add a post-build action to jobs. ‘Stand Alone Sonar’.
- And its done. 🙂