Oops Null Pointer

Java programming related

Monthly Archives: November 2010

Ant 1.7 to 1.8 .Net builds

I recently needed to upgrade to Ant 1.8 to use Gmail as a smtp service for the ant MailLogger (mails the results of builds). Ant 1.8 is required as Gmail (among others) requires a STARTTLS to be sent and Ant 1.8 fixes a bug in 1.7.

Ant 1.8 no longer supports .Net tasks as core tasks as they have been moved to the AntLib project. To get the old tasks running,

  • Add the ant-donet-1.0 .jar to the ant lib dir
  • Add the xmlns to the project node
  • Prefix the old tasks with the xmlns
  • Change the case of any commands that require it (e.g. WsdlToDotnet becomes wsdltodotnet)


<project name="aqua">
  <csc debug="true" optimize="true"  targettype="exe">


<project name="aqua" xmlns:dn="antlib:org.apache.ant.dotnet">
  <dn:csc debug="true" optimize="true"  targettype="exe">

Creating NUnit reports with Ant

The current project I’m working on is largely Java with a reasonable amount of Microsoft Office connectivity using C#, VB, with COM and JSON as the bridges to the Java server. To get continuous integration rolling I really wanted to end the NUnit GUI based tests and get the NUnit console results built into a HTML report via Ant.

Not having any experience with NAnt (all our .Net building is done via Ant) I needed some way to get Nunit results into JUnit format so I could run the junitreport task on them.

Here are the steps I took:
1) Run the NUnit tests with the nunit-console and create an xml file

2) Use a modified version of Hudson’s NUnit plugin’s nunit-to-junit.xsl file to create a JUnit file per assembly test suite
Hundon’s XSL creates one file for all the tests with a “testsuites” root node. The junitreport task needs one file per testsuite. Hudson has a java file to do this, while I used the XSL 2.0 result-document (with the saxon XSLT engine) to do this. I use Ant’s XSLT task to transform the results

The modified section of the nunit-to-junit.xsl looks like this:

<!-- I need to replace any non file system compatible chars with '_'-->
<xsl:variable name="assemblyName">
  <xsl:analyze-string select="$assembly" regex="[\*/:&lt;li&gt;\?\|;&quot;&apos;]+">
      <xsl:value-of select="." />
      <xsl:value-of select="." />

<xsl:result-document href="{$outputpath}/TEST-{$assemblyName}.xml" format="xml">
  <testsuite name="{$assemblyName}" ...>

3) Run Ant’s junitreport task on the result and voila: a junit-y looking HTML report for my NUnit tests.

The ant target is:

<target name="create-nunit-test-report" description="NUnit result into junit report">

  <delete dir="${test.nunit.reports.dir}" failonerror="false"/>
  <mkdir dir="${test.nunit.reports.dir}"/>

  <xslt in="${test.nunit.console.file}"
    style="${antBuild}\nunit-to-junit.xsl" force="true"

    <outputproperty name="method" value="xml"/>
    <outputproperty name="standalone" value="yes"/>
    <outputproperty name="encoding" value="iso8859_1"/>
    <outputproperty name="indent" value="yes"/>

    <classpath location="${vendor.lib.dir}/xslt/saxon9he.jar" />

    <!--Split file location for results-document XSLT function  -->
    <param name="outputpath" expression="file:///${full.path.test.nunit.results.dir}"/>

  <junitreport todir="${test.nunit.results.dir}">
    <fileset dir="${test.nunit.results.dir}">
      <include name="TEST-*.xml" />
    <report todir="${test.nunit.reports.dir}" />

Update 1/12/2010: Ant 1.8.1 has a bug that will cause the saxon jar not to be found and a “Unsupported XSL element” error.
I found the solution here http://stackoverflow.com/questions/919692/how-to-execute-xslt-2-0-with-ant/4211575#4211575
You need to add the following attribute to the xslt task: