To use JarDiff from an ant build script, is relatively trivial, here is an example:
<project name="jardiff" default="jardiff" basedir=".">
<!-- Lib directory (this is where your jar files live) -->
<property name="lib" value="libs"/>
<!-- Classpath for jardiff -->
<property name="jardifflibs" value="${lib}/jardiff-0.2.jar:${lib}/asm-2.1.jar:${lib}/asm-commons-2.1.jar"/>
<!-- Define jardiff and jdxslt tasks from properties file in jar -->
<typedef resource="ant/jardiff.properties" classpath="${jardifflibs}"/>
<!-- Location of jardiff xslt stylesheets -->
<whichresource classpath="${jardifflibs}" property="jardiff-html" resource="style/jardiff-html.xsl"/>
<whichresource classpath="${jardifflibs}" property="jardiff-xhtml" resource="style/jardiff-xhtml.xsl"/>
<whichresource classpath="${jardifflibs}" property="jardiff-text" resource="style/jardiff-text.xsl"/>
<target name="jardiff">
<jardiff fromjar="jardiff-0.1.jar" tojar="jardiff-0.2.jar"
out="jardiff-0.1-0.2.xml"/>
<jdxslt in="jardiff-0.1-0.2.xml" out="jardiff-0.1-0.2.html" styleurl="${jardiff-xhtml}">
<param name="stylesheet" expression="diff.css"/>
<param name="from-api"
expression="http://dist.osjava.org/releases/multidoc-jnr/jardiff/0.1"/>
<param name="to-api"
expression="http://dist.osjava.org/releases/multidoc-jnr/jardiff/0.2"/>
</jdxslt>
</target>
</project>
There is a fully functional ant build script in src/examples in the distribution.
The jardiff task generates an xml document describing the changes between two jar files.
The jardiff task takes the following options:
| Attribute | Type | Meaning | Required | default |
|---|---|---|---|---|
| fromjar | file | From jar file | Yes | none |
| tojar | file | To jar file | Yes | none |
| out | file | Output xml file | Yes | none |
| fromname | string | Name of from version | No | fromjar filename |
| toname | string | Name of to version | No | tojar filename |
| force | boolean | Overwrite output file if it already exists, and is newer than both source jar files. | No | No |
The jdxslt task is an extension of the built in and xslt task, which allows a stylesheet to be specified as a URL (in the example, we use an xslt contained in the jardiff jar file, which can be resolved to a url, and then passed into an xslt task as the style).
It is fine to use the built in ant xslt task, as the only modification I made was to allow specifying the stylesheet as a url, as I see no reason to have to extract a stylesheet from a jarfile before using it.
The jdxslt task takes exactly the same arguments as the xslt core task with the following modifications.
| Attribute | Type | Meaning | Required | default |
|---|---|---|---|---|
| style | file | Stylesheet to use | Yes, or styleurl | none |
| styleurl | string | URL of stylesheet to use | Yes, or style | none |