So, now we have a build server including source control, a mechanism to monitor our source code and trigger builds and a utility in place to allow us to automate actions like compiling, running unit tests, deploying files. We can also look at the Cruise Control web application to track our builds, their progress, success, failure.
This time, we'll take a look at a package called StatSvn which tracks the changes made to your code base and generates informative reports from what it sees. Let's dig right in to setting it up.
First, you'll need to download the software from here. You'll be downloading a zip file which needs to be expanded into a directory on your build server. In that directory, you'll find a jar file, so you know right away you need to install the Java runtime on the build server. You can find the runtime here. After insuring the runtime is installed, you'll need to create a new directory on the server to contain a running current version of your code base. StatSvn will be using the code in this directory to generate its reports from. After creating the directory, check the current version of the code base into it.
We'll be calling StatSvn from our build script. Since there are several steps to working with StatSvn, I create a bat file containing all the steps and then call it from the build script. So, create a new bat file (Stats.bat) on the root of a drive on the build server. It should contain something like the following.
c:
cd c:\stats
del *.html
del *.png
cd "c:\StatCode"
svn up
svn log --xml -v > svn.log
cd c:\stats\
java -jar statsvn.jar "c:\StatCode\svn.log" "c:\StatCode"
Here, I'm changing the current drive to c: and then changing the current path to where I unzipped the StatSvn jar file. When the jar is executed, it creates several html and ping files in its current directory. I start, then, by deleting all these from the last run. Next, I change the current path to point to the directory into which I checked out the current version of my code base. I then call the Subversion command line utility, svn, and pass it a parameter or "up". This tells subversion to update the local copy of my code with what's on the server. Now, I call the Subversion command line, again, and ask it to create a log file for me, called svn.log, in XML format. This file will be created in the same folder my source code is in. Last, I change the local path back to where I unzipped the StatSvn archive and execute the jar file telling it where my log file and code base is. The result of this is the creation of html and image files in the StatSvn folder containing reports about my source code. Let's tie this process into the build script.
Last time, we looked at using the <exec> element in our NAnt script to execute command line statements. To add the batch file to our build, therefore, all we need to do to add a call to our batch file is to either create a new target or use an existing target and add this task inside it.
<exec program="C:\stats.bat"></exec>
Now, how do we view the generated reports? Generally, you'll want to make sure IIS is installed on your build server and create a virtual directory that points to the StatSvn folder. Be sure to set the default page to index.html. Once you do this, you'll be able to navigate all the generated content with your browser. There are examples of the generated reports on the StatSvn web site for you to check out.