The preceding chapter illustrated how to generate baseline reports using Perl and the ClearCase command line. Amending these scripts to generate XML output instead of simple text output is relatively simple. For example, you could change one of the Perl print statements to output an XML activity element: print "<activity name=\"$act_id\", headline=\"$act_title\">\n"; However, this would require a lot of work to verify that the XML you were hard-coding into the print statements was correct and well formed. A better approach would be to use an existing library to generate valid XML. Since Java already has such a set of libraries, and because I have illustrated how to create Ant tasks in Java, it makes sense to adopt a Java-based approach and create a new Ant task. Fortunately, such tasks have already been created and are available in the clearantlib library. Using clearantlib to Generate Label and Baseline ReportsThe clearantlib library has a number of tasks for reporting on ClearCase labels and baselines. There are two tasks (<cclabelreport> and <ccblreport>) to generate a report on the content of a label or baseline, as well as two tasks (<ccdifflabelreport> and <ccdiffblreport>) to generate a report on the difference (in terms of activities or versions) between labels or baselines. For example, if you wanted to produce a report on the contents of the Base ClearCase label RATLBANKMODEL_02_INT and send the output to the file cclabelreport.xml, you could write an Ant target similar to the following: <target name="label-report"> <ca:cclabelreport labelselector="RATLBANKMODEL_02_INT" outfile="cclabelreport.xml" dtduri="file:///C:/Views/RatlBankModel_bld/JavaTools/libs/baseline.dtd"/> </target> As you can see from this example, <ccblreport> takes three attributes. Two of them are mandatory: the name of the label to report on via the labelselector attribute, and the XML output file to create via the outfile attribute. The third attribute, the location of the DTD for validation, is optional. It is useful if you will use the XML file as an input to some other tool or process. Here's an example of the XML file that would be created by this target:
You report on the content of a ClearCase baseline in a similar way. For example, if you wanted to produce a baseline report on the UCM baseline RATLBANKMODEL_02_INT and send the output to the file ccbaselinereport.xml, you could write an Ant target similar to the following: <target name="baseline-report"> <ca:ccblreport baselineselector="RATLBANKMODEL_02_INT@\ ÂRatlBankProjects" outfile="ccbaselinereport.xml" dtduri="file:///C:/Views/RatlBankModel_bld/JavaTools/ Âlibs/baseline.dtd"/> </target> As you can see, this example is very similar to the first. However, rather than a labelselector attribute, it has a baselineselector attribute and a corresponding output file. Here's an example of the XML file that would be created by this target:
Creating an XSLT StylesheetTo generate an HTML file from XML, you need to create an XSLT stylesheet file. An XSLT stylesheet basically contains the instructions for the transformation you want to perform on an XML file. In this case the transformation is to HTML, but it could be to another XML file. XSLT stylesheets are built on structures called templates. A template specifies what to look for in a source tree (such as the XML input document) and what to output to the result tree (such as the HTML output document). Here's a very basic template: <xsl:template match="baseline"> <b><xsl:value-of select="@name"/></b> </xsl:template> This example finds the baseline element in the XML input document and outputs the value of its name attribute in bold, as shown in the following: RATLBANKMODEL_02_INT@\RatlBankProjects You can use a number of capabilities in XSLT stylesheets. For example, you can apply a set of formatting instructions to a complete set of child elements using <xsl:for-each> or sort elements based on an attribute field using <xsl:sort>. A complete description of the XSLT language is beyond the scope of this book, but for more information refer to Hunter [Hunter04]. Listing 9.1 shows a complete example of an XSLT stylesheet for taking an XML baseline report generated by the <ccblreport> task and transforming it into HTML. Listing 9.1. ccblreport.xsl Stylesheet
This example has a built-in Cascading Style Sheets (CSS) definition (between the <style> elements at the top of the file). These are used to set the default look and feel of the HTML tables that the report will use. Another point to note is that all the activities are sorted according to the date they were created via the XSLT instruction: <xsl:sort select="@date" order="descending"/> Finally, all the contributors to an activity are offset using a <td align="right"> instruction and are presented in a different table background color. This makes it clear that they are aligned with a particular integration activity. To transform an XML baseline or label into HTML, you can use the Ant <style> task: <target name="baseline-report"> <ca:ccblreport baselineselector="RATLBANKMODEL_02_INT@\RatlBankProjects" outfile="ccbaselinereport.xml" dtduri="file:///C:/Views/RatlBankModel_bld/JavaTools/libs/baseline.dtd"/> <style in="ccbaselinereport.xml" out="ccbaselinereport.html" style="ccblreport.xsl"/> </target> This example takes the XML baseline report file ccbaselinereport.xml and transforms it into the HTML file ccbaselinereport.html using the XSLT stylesheet ccblreport.xsl from Listing 9.1. Figure 9.2 shows a baseline report that this stylesheet can create. Figure 9.2. HTML baseline reportSimilarly, Figure 9.3 shows a Base ClearCase label report that this same stylesheet can create. Figure 9.3. HTML label reportThe clearantlib library comes with a similar but more complex XSLT stylesheet. In particular, this stylesheet allows you to show or hide which element versions were changed for each activity. This report was illustrated in Figure 9.1. |