Since version 1.6.1, Ant, the java build tool, has a core task called “cvschangelog“. It is quite useful to use this task to grab a list of recent changes committed to the CVS repository. The output of this task is in XML format. Something like the following:
<changelog>
<entry>
<date>2009-09-02</date>
<time>12:00</time>
<author>robin</author>
<file>
<name>test/ant/task/ChangeLog.txt</name>
<revision>1.2</revision>
<prevrevision>1.1</prevrevision>
</file>
<msg><![CDATA[A commit message]]></msg>
</entry>
<entry>
…
</entry>
…
</changelog>
To transform the xml formatted changelog into a human friendly html, you can do an XSL transformation with a XSL file. There is a default one in the Ant distribution, so you can use the following task to get a change log in html format.
<style in=”changelog.xml”
out=”changelog.html”
style=”${ant.home}/etc/changelog.xsl”>
<param name=”title” expression=”Ant ChangeLog”/>
<param name=”module” expression=”the_module”/>
<param name=”cvsweb” expression=”the_url”/>
</style>
The default generated html lists each commit change one by one. In some cases, we want to group the commit changes by dates. To do so, we have to change the default xsl file.
It seems that the new XSLT version 2.0 has specified a group functionality. However, it turns out only a few XSLT tools support this new feature. Fortunately, There is a way that allows us to do the grouping using XSLT version 1.0. By applying this method, we have the following looking xsl code for the HTML <BODY> part.
<body>
<h1>
<a name=”top”><xsl:value-of select=”$title”/></a>
</h1>
<p style=”text-align: right”>Designed for use with <a href=”http://ant.apache.org/”>Apache Ant</a>.</p>
<hr/>
<xsl:key name=”log-by-date” match=”entry” use=”date” />
<xsl:template match=”changelog”>
<xsl:for-each select=”entry[count(. | key('log-by-date', date)[1]) = 1]”>
<xsl:sort select=”date” order=”descending” />
<h2><xsl:value-of select=”date”/><xsl:text></xsl:text></h2>
<xsl:for-each select=”key(’log-by-date’, date)”>
<xsl:sort select=”time” order=”descending” />
<table border=”0″ width=”100%” cellspacing=”1″>
<tr>
<td class=”dateAndAuthor”>
<!– <xsl:value-of select=”date”/><xsl:text> </xsl:text> –>
<xsl:value-of select=”time”/><xsl:text> </xsl:text><xsl:value-of select=”author”/>
</td>
</tr>
<tr>
<td>
<pre><xsl:apply-templates select=”msg”/></pre>
<ul>
<xsl:apply-templates select=”file”/>
</ul>
</td>
</tr>
</table>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</body>
Use the above code to replace the <body> part in the original changelog.xsl file, then it will allow you to group the change logs by date.
.gif)