Introduction
I have finally finished putting the last pieces in place for automating the documentation for CruiseControl.NET. This means that once Dave has put the pieces onto the server, the documentation will be automatically generated every time the code is updated
This post is a quick summary of what is involved on the server side. The following posts describe what I have already built for the documentation generator:
And in this post I will describe how I added the tool to CruiseControl.NET.
Some Tidying Up
First off, I did some tidying up within the documentation generator. Previously it expected the arguments in a set order. Unfortunately this made it harder to integrate with CC.NET. Additionally, it did not generate any log file – it just displayed all the details to the console.
The first change was to use the OptionSet class from the Remote project (this actually came from Mono originally). This allowed me to quickly and easily add argument parsing to the tool. Now all of the arguments have a prefix and can be specified in any order.
For example, the generation command line went from:
Console.exe generate ..\..\..\..\..\project\Remote\bin\Debug\ThoughtWorks.CruiseControl.Remote.dll documentation
to
Console.exe -c=generate -s=..\..\..\..\..\project\Remote\bin\Debug\ThoughtWorks.CruiseControl.Remote.dll -o=documentation –xsd
While this is now a bit longer, it means the arguments can be specified in any order!
Second, I added a switch to generate a log file. When this switch is set the output will be sent to a log file (in an XML format) instead of the console. This log file also contains the type of information (debug, info, warning or error) plus the date and time.
With these changes, the tool is now ready to be integrated with the main build.
Preprocessing
Before the tool can be run there needs to be some pre-processing. First, the tool needs to be compiled – it is only included as source code in the repository. This is done using a NAnt build script and is very similar to how the main solution is built.
Additionally the NAnt script also does some clean up. This clean up involves deleting the previous log files. If this step is omitted then a failed build would get the logs from the previous successful build!
Finally the NAnt script moves the pages.xml file from the project trunk to the location where the tool expects it.
Now with all this done, the tool can generate and publish the documentation.
Calling the Tool
Calling the tool is really easy, just need to use the exec task. The following is how this task has been configured for generation:
<exec>
<description>Generate the documentation for the Remote project</description>
<executable>Tools\docGenerator\Console\bin\Debug\Console.exe</executable>
<buildArgs>-c=generate -s=Build\Remote\ThoughtWorks.CruiseControl.Remote.dll -o=wiki -l=doc-remote.log</buildArgs>
</exec>
The baseDirectory setting has been omitted, so this will default to the project working directory (more on this below). This means all the paths are relative to the repository trunk.
The executable element tells CC.NET where to find the tool – since it has been compiled previously we tell it to look in the debug folder.
The buildArgs element is the arguments that I described above, except with the log file specified. The log file is being used so we can import the results into the build log.
And that’s all there is to it. The other exec tasks are similar, expect with different buildArgs. The only one that is very different is the publishing. This is because it requires a password and username and we don’t want everyone to see it! To get around this we added a batch file with the password and username in it, and all the rest of the arguments are passed though (I’ll write a post on this in future.)
The Final Touches
The final touches (or first depending on your thinking) is to add the project to the configuration. I decided to add this as a new project, so it can run independent of the main build.
The project has the same workingDirectory as the build project, but is in a different queue and has a different artefactDirectory (the different artefactDirectory is required to prevent cross-contamination of the build logs!) There is no source control block, as the code will have already been downloaded by the main project. It contains the NAnt script task and the four exec tasks. Finally, the publishers section merges the external logs and generates the build log (via xmlLogger).
And to trigger the project I added a forcebuild task to the main project. This will fire the documentation project when the build has finished (but before the publishers.)
And that’s all there is to it! In all, it took me a couple of hours to set this all up, but that also involved committing changes to the repository and generating entire builds of CC.NET (not a fast process!)
So, in the end, this is the completed project:
<project name="CCNet-Doc">
<queue>Documentation</queue>
<workingDirectory>e:\sourcecontrols\sourceforge\ccnet</workingDirectory>
<artifactDirectory>e:\download-area\CCNet-Documentation\1.5.0</artifactDirectory>
<tasks>
<!-- Prepare for the documentation -->
<nant>
<description>Setup for documentation generation</description>
<executable>Tools\NAnt\NAnt.exe</executable>
<buildFile>docPrep.build</buildFile>
<buildArgs>-listener:CCNetListener,CCNetListener</buildArgs>
<targetList>
<target>all</target>
</targetList>
<buildTimeoutSeconds>1000</buildTimeoutSeconds>
</nant>
<!-- Generate the documentation for the three projects -->
<exec>
<description>Generate the documentation for the Remote project</description>
<executable>Tools\docGenerator\Console\bin\Debug\Console.exe</executable>
<buildArgs>-c=generate -s=Build\Remote\ThoughtWorks.CruiseControl.Remote.dll -o=wiki -l=doc-remote.log</buildArgs>
</exec>
<exec>
<description>Generate the documentation for the Core project</description>
<executable>Tools\docGenerator\Console\bin\Debug\Console.exe</executable>
<buildArgs>-c=generate -s=Build\Core\ThoughtWorks.CruiseControl.Core.dll -o=wiki -l=doc-core.log</buildArgs>
</exec>
<exec>
<description>Generate the documentation for the WebDashboard project</description>
<executable>Tools\docGenerator\Console\bin\Debug\Console.exe</executable>
<buildArgs>-c=generate -s=Build\WebDashboard\ThoughtWorks.CruiseControl.WebDashboard.dll -o=wiki -l=doc-dashboard.log</buildArgs>
</exec>
<exec>
<description>Publish the documentation</description>
<executable>E:\tools\docGen.bat</executable>
<buildArgs>-c=publish -o=http://confluence.public.thoughtworks.org/rpc/soap-axis/confluenceservice-v1 -s=wiki\pages.xml -l=doc-publish.log</buildArgs>
</exec>
</tasks>
<publishers>
<!-- Merge all the files -->
<merge>
<files>
<file>doc-remote.log</file>
<file>doc-core.log</file>
<file>doc-dashboard.log</file>
<file>doc-publish.log</file>
</files>
</merge>
<xmllogger/>
</publishers>
</project>
Hopefully this will be helpful to someone else as well