I've had this project rumbling around in the back of my head for 2 years now to find a way of doing code analysis as part of our continuous integration build server. This started at a business of software conference I attended in San Jose and one of the presenters basically showed a project that broke down the cyclomatic complexity of a codebase to help understand which areas of it are fragile. Cyclomatic complexity sounds scary but it's basically just an algorithm for determining how complex a function is.
Well, being as it's christmas week and it's kinda slow around here I decided to give this a go and thank goodness google turned up a couple gems...
http://www.richard-banks.org/2007/01/sourcemonitor-and-cruisecontrol-top-15.html
http://www.ridgway.co.za/archive/2006/11/28/usefulsourcemonitorreportsincruisecontrol.aspx
The basic theory behind both these posts is to use a freeware tool called Source Monitor to generate a code analysis which shows you complexity along with a few other metrics. Richard does this using nant and Eden does it using msbuild but the output is basically the same.
Source Monitor has an internal file format but allows you to call it from the command line with parameters to export its data into a number of different file formats. I pass these through a couple of XSLT's to generate nicely formatted data for my stats. The nant commands to generate the formatted files look like this…
${sourcemonitor.project}
VB.NET
true
${module.base}
true
1
${build.folder}\sourcemonitor.summary.xml
1
${sourcemonitor.project}
1
${build.folder}\sourcemonitor.detail.xml
2
]]>