8

I am using SVN as a version management tool for my project, and am planning to use sonar for project analysis.

How do I make sonar project analysis run every time code is checked into SVN?

Fenton
  • 241,084
  • 71
  • 387
  • 401
samarth
  • 3,866
  • 7
  • 45
  • 60

2 Answers2

13

Do not do complex stuff as a pre-commit hook! When a user does a commit, control does not return to the user until after the pre-commit hook has completed. Since Sonar has to compile your code, your users will have to wait on every commit for the following:

  • Checking out the code
  • Compiling the code
  • Running all of the tests and checks that Sonar performs
  • Waiting for Sonar to complete its reporting and updating its database

How long will all of this take? 10 minutes? 20 minutes? 5 minutes? Let's assume that your code is small or your compiler is very fast, so it takes a mere 4 minutes. Do your users want to wait 4 minutes each and every time they perform a commit in order to start their work again?

Instead, get a continuous build server like Jenkins. Jenkins is fast and simple to setup. It's a simple *.war file. You simply run:

$ java -jar jenkins.war

And, you're up and running. Once Hudson is up, you define a "job". Just enter in the required information, and save. Every time, someone does a commit in Subversion, Hudson will build in the background.

Where all the fun comes in are the dozens (and maybe hundreds) of third party plugins that can extend Jenkins. For example, there's a Sonar plugin that will run your Sonar tasks, update your database, and produce some nice looking reports.

If there are problems, Jenkins will email the person responsible and the entire development team. (Plugins allow Jenkins to IM, Tweet, and even change a stoplight from green to red). This immediate feedback and public knowledge will get your developers to do their own tests before doing a commit.

David W.
  • 105,218
  • 39
  • 216
  • 337
  • Thank you so much.....I have installed the COLLABNET SUBVERSION Edge,and have running sonar,but not in integration.As you are telling i will be requiring Hudson and jenkins,but m not aware of both.will u plz help me building a small demo? – samarth Aug 23 '11 at 13:00
  • Jenkins and Hudson are sort of the same thing. Originally, it was Hudson, but the guy who wrote it left Oracle and continued the project under Jenkins. Most of the dev team now does Jenkins, but Oracle is still supporting Hudson. I use Jenkins. Download [Jenkins](http://jenkins-ci.org) and give it a try. It's really easy to use. Jenkins _integrates_ with Sonar. There are plugins for Jenkins and one is a Sonar plugin. Basically, you tell Jenkins where to find the Sonar generated reports, and Jenkins makes them all pretty looking. If you have Sonar working, you're already 90% of the way there. – David W. Aug 23 '11 at 14:33
0

You could investigate Hudson. There is a Sonar plugin for it.

Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453