NDepend and CruiseControl.NET
A while back Patrick Smacchia from NDepend did an analysis of the code in CruiseControl.NET (read it here). I sent him an e-mail thanking him, and one thing lead to another, and before you know it I had volunteered myself to help integrate NDepend better with CruiseControl.NET.
You Did What? Why?
Now you’re probably wondering why I volunteered my time (yes, I don’t get paid to work on CruiseControl.NET). There’s a very simple reason behind it – I think NDepend is a awesome tool for getting information on what’s happening in your project.
Anyone who has worked in software development for a while knows about spaghetti code. This is code that has become some convoluted and twisted that it is a nightmare to maintain! Now, as a developer, I know we all code with the best of intentions, but sometimes code just seems to get “spaghetti”ed, and it’s even worse when we start talking about open source projects.
NDepend helps open a picture on what is happening in the codebase. It shows many different aspects where code can become twisted (I’m still learning about them) and Patrick has written several blog posts about how to use this information to clean up the code. Additionally, it can also provide an historical analysis. So not only can you see what your code is like, you can also see how well you are doing in making it better!
As you might have guessed, I’m very impressed with NDepend and the details it provides. If you are interested in finding out more, take a look at their website: http://www.ndepend.com/.
While it has always been possible to integrate NDepend into CruiseControl.NET it was a bit of a convoluted process. First, you needed to call NDepend from either Nant or MSBuild. Then you needed to merge the results from NDepend. And finally the dashboard needed to be set up. And to top it all off, it wasn’t possible to view the images from NDepend!
What I have done is added a new NDepend task. This will run the NDepend application (same as the Nant or MSBuild tasks), but directly from a ccnet.config. The added value comes after the execution – the new task will automatically publish the NDepend results, and merge the XML files. This means NDepend now only needs the single task within ccnet.config – instead of modifying the build script and then adding a merge publisher into ccnet.config.
I’ve also put together a package for the dashboard. This simplifies the administrator’s work in adding the results to the dashboard. All the administrator needs to do is go to the admin plug-in and load and install the package. No more messing about with copying files, changing configuration settings and restarting IIS!
As well as the NDepend-specific work, I’ve also fixed a more generic issue – displaying images in the dashboard.
First, a bit of background. CruiseControl.NET is divided into two parts – the CI server and the web dashboard. These can run on the same machine, or totally different machines, so we can’t assume that the dashboard can access any files that the CI server can. Therefore some way is needed to transfer files from one application to another.
To keep things simple, I added a new file transfer mechanism to the CI server. This means a remote client can now request files from the CI Server and they will be transferred using .NET Remoting (not the best way, but .NET Remoting is the only transport channel that the server currently has.) So now there is a way to transfer files, even if they are on different machines.
The second part is to add a new action to the dashboard that uses this file transfer. This is a simple project-based action that takes in a query string parameter saying which file to be transferred. When the action is processed, the file is fetched from the CI server and downloaded to the browser (all via streams, so nothing is stored locally).
To display the images, all I needed to do was to modify the XSL-T template to use the new action (it’s called RetrieveFile.aspx) and pass in the name of the file to display. Now the NDepend reports display all the text data and the images as well!
Tell Me More
The good news is this task made the cut for 1.4.4. So when 1.4.4 is released, the new task, package and image work will be available!
Full details on the new task are available at http://confluence.public.thoughtworks.org/display/CCNET/NDepend+Task. There are some instructions on how to integrate NDepend at http://confluence.public.thoughtworks.org/display/CCNET/Using+CruiseControl.NET+with+NDepend – this covers both the new and the old ways of integration.
Finally, I’m going to write a full tutorial on how to use NDepend and CruiseControl.NET together sometime. This will include a walk-through on how to do this, plus a full example.
And, as a final note, we’re looking to start using NDepend with CruiseControl.NET to tidy up our own code. As I play around with it and figure out things I’ll include them in my blog. (But I’m still catching up on things, so these blog posts might be take a while!)