Eden Ridgway's Blog

.Net and Web Development Information

  Home :: Contact :: Syndication  :: Login
  105 Posts :: 1 Stories :: 78 Comments :: 3 Trackbacks

Search

Article Categories

Archives

Post Categories

Development

General

The ideas in this post were inspired by the work done by Robin Curry in his post Integrating SourceMonitor Code Metrics Into An NAnt / CruiseControl.NET Build. He did some great work and I would like to express my gratitude.

Unfortunately I found that those CruiseControl stylesheets gave me far too much information. The summary data that SourceMonitor produces also is not as useful as it could be. What I wanted on my build server was a way to quickly glance at the state of the code on a project and to identify code that needed to be reviewed or refactored. At the end of the day the only information I was really interested in was the code complexity and how deeply nested the code blocks were.

The other problem with the SourceMonitor output is that, depending on the size of the project, it could be between 100K and 300K and if you multiply that by the number of projects and checkins on your build server it quickly adds up. At my company it would amount to about 20MB a day. I therefore decided to take Grant Drake’s NCoverExplorer approach and summarise the output before integrating it with CruiseControl. To do this I created a simple stylesheet that is run after creating a detailed SourceMonitor report.

The end result of all that work is a report that looks like this:

To get all this to work you need to do the following:

  1. Copy the file SourceMonitor.xsl (2.88 KB) into your CruiseControl.Net\webdashboard\xsl folder.
  2. Add the following line to the dashboard.config (in CruiseControl.Net\webdashboard).
<buildPlugins>
<!-- Summary reports -->
<buildLogBuildPlugin />
<!-- Other detail reports -->
<xslReportBuildPlugin description="SourceMonitor Report" actionName="SourceMonitorReport" xslFileName="xsl\SourceMonitor.xsl" />
</
buildPlugins>
  1. Copy the file SourceMonitorSummaryGeneration.xsl (2.18 KB) to your build script folder or a common location.
  2. Ensure that you have installed MsBuild Community Tasks available at http://msbuildtasks.tigris.org/. You also need to ensure that you have imported the Community Task targets in your build file:
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
  1. Add the following to your MsBuild script and call the RunSourceMonitor target. Substitute the paths depending on your project directory structure and the location of the xsl file above.
<!-- Source Monitor Command File -->
<PropertyGroup>
<SourceMonitorCommand>
<![CDATA[
<?xml version='1.0' encoding='UTF-8' ?>
<sourcemonitor_commands>
<write_log>false</write_log>
<command>
<project_file>TempProject.smp</project_file>
<project_language>CSharp</project_language>
<source_directory>..\</source_directory>
<include_subdirectories>true</include_subdirectories>
<export>
<export_file>..\SourceMonitorDetailedOutput.xml</export_file>
<export_type>2</export_type>
</export>
</command>
</sourcemonitor_commands>
]]>
</SourceMonitorCommand>
</PropertyGroup>

<!-- Runs the source monitor metrics program and creates a summarised report for CruiseControl-->
<Target Name="RunSourceMonitor">

<!-- Create the command file -->
<WriteLinesToFile
File
="SourceMonitorCommands.xml"
Lines
="$(SourceMonitorCommand)"
Overwrite
="true" />

<!-- SourceMonitor Metrics -->
<Exec
Command="&quote;C:\Program Files\SourceMonitor\SourceMonitor.exe&quote; /C SourceMonitorCommands.xml" />

<!-- Convert the SourceMonitor Output into a more usable summarised version -->
<Xslt
Inputs
="..\SourceMonitorDetailedOutput.xml"
Xsl
="SourceMonitorSummaryGeneration.xsl"
Output
="..\SourceMonitorResults.xml" />

<!-- Remove the intermediate files -->
<Delete Files="..\SourceMonitorDetailedOutput.xml;TempProject.smp;SourceMonitorCommands.xml" />

</
Target>
  1. Make sure you are integrating the XML output into your CruiseControl report. I set it up so that all files ending with Results.xml are included.
<publishers>
<merge>
<files>
<file>*Results.xml</file>
</files>
</merge>
</publishers>

And viola you should have your summarised SourceMonitor view of the 15 most complex and deeply nested pieces of code for your current system.

I hope that you find this useful.

posted on Tuesday, November 28, 2006 3:09 AM

Feedback

# re: Useful SourceMonitor Reports in CruiseControl 1/19/2007 12:53 AM Richard Banks
Hi Eden. Great work :-) and a big thank you!!

I've posted a follow up to this on my blog showing how to get the same result using NAnt tasks instead of MSBuild.

It's at http://richardsbraindump.blogspot.com/2007/01/sourcemonitor-and-cruisecontrol-top-15.html


# re: Useful SourceMonitor Reports in CruiseControl 1/19/2007 7:32 AM Eden Ridgway
Hi Richard. Thank you very much for your kind words. And thanks for spotting the bug in the summary generation that meant that the 9+ nested code blocks were ignored. I have fixed that.

# re: Useful SourceMonitor Reports in CruiseControl 1/20/2007 7:32 AM Eden Ridgway
Another change I've made is that the CruiseControl Summary stylesheet no longer has a hard coded value for the number of method and block summary rows in case you choose to customize the summary generation.

Comments have been closed on this topic.