|
|
Ant example source code file (junit-frames.xsl)
This example Ant source code file (junit-frames.xsl) is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.
The junit-frames.xsl source code
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:lxslt="http://xml.apache.org/xslt"
xmlns:redirect="http://xml.apache.org/xalan/redirect"
xmlns:stringutils="xalan://org.apache.tools.ant.util.StringUtils"
extension-element-prefixes="redirect">
<xsl:output method="html" indent="yes" encoding="US-ASCII"/>
<xsl:decimal-format decimal-separator="." grouping-separator=","/>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Sample stylesheet to be used with Ant JUnitReport output.
It creates a set of HTML files a la javadoc where you can browse easily
through all directories and projects.
-->
<xsl:param name="output.dir" select="'.'"/>
<xsl:template match="testsuites">
<!-- create the index.html -->
<redirect:write file="{$output.dir}/index.html">
<xsl:call-template name="index.html"/>
</redirect:write>
<!-- create the stylesheet.css -->
<redirect:write file="{$output.dir}/stylesheet.css">
<xsl:call-template name="stylesheet.css"/>
</redirect:write>
<!-- create the overview-directories.html at the root -->
<redirect:write file="{$output.dir}/overview-summary.html">
<xsl:apply-templates select="." mode="overview.directories"/>
</redirect:write>
<!-- create the all-directories.html at the root -->
<redirect:write file="{$output.dir}/overview-frame.html">
<xsl:apply-templates select="." mode="all.directories"/>
</redirect:write>
<!-- create the all-projects.html at the root -->
<redirect:write file="{$output.dir}/allprojects-frame.html">
<xsl:apply-templates select="." mode="all.projects"/>
</redirect:write>
<!-- create the all-tests.html at the root -->
<redirect:write file="{$output.dir}/all-tests.html">
<xsl:apply-templates select="." mode="all.tests"/>
</redirect:write>
<!-- create the alltests-fails.html at the root -->
<redirect:write file="{$output.dir}/alltests-fails.html">
<xsl:apply-templates select="." mode="all.tests">
<xsl:with-param name="type" select="'fails'"/>
</xsl:apply-templates>
</redirect:write>
<!-- create the alltests-errors.html at the root -->
<redirect:write file="{$output.dir}/alltests-errors.html">
<xsl:apply-templates select="." mode="all.tests">
<xsl:with-param name="type" select="'errors'"/>
</xsl:apply-templates>
</redirect:write>
<!-- process all directories -->
<xsl:for-each select="./testsuite[not(./@package = preceding-sibling::testsuite/@package)]">
<xsl:call-template name="directory">
<xsl:with-param name="name" select="@package"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="directory">
<xsl:param name="name"/>
<xsl:variable name="directory.dir">
<xsl:if test="not($name = '')">
<xsl:if test="$name = ''">.
</xsl:variable>
<!--Processing directory -->
<!-- create a projects-list.html in the directory directory -->
<redirect:write file="{$output.dir}/{$directory.dir}/directory-frame.html">
<xsl:call-template name="projects.list">
<xsl:with-param name="name" select="$name"/>
</xsl:call-template>
</redirect:write>
<!-- create a directory-summary.html in the directory directory -->
<redirect:write file="{$output.dir}/{$directory.dir}/directory-summary.html">
<xsl:call-template name="directory.summary">
<xsl:with-param name="name" select="$name"/>
</xsl:call-template>
</redirect:write>
<!-- for each project, creates a @name.html -->
<!-- @bug there will be a problem with inner projects having the same name, it will be overwritten -->
<xsl:for-each select="/testsuites/testsuite[@package = $name]">
<redirect:write file="{$output.dir}/{$directory.dir}/{@id}_{@name}.html">
<xsl:apply-templates select="." mode="project.details"/>
</redirect:write>
<xsl:if test="string-length(./system-out)!=0">
<redirect:write file="{$output.dir}/{$directory.dir}/{@id}_{@name}-out.txt">
<xsl:value-of disable-output-escaping="yes" select="./system-out"/>
</redirect:write>
</xsl:if>
<xsl:if test="string-length(./system-err)!=0">
<redirect:write file="{$output.dir}/{$directory.dir}/{@id}_{@name}-err.txt">
<xsl:value-of disable-output-escaping="yes" select="./system-err"/>
</redirect:write>
</xsl:if>
<xsl:if test="failures/text() != 0">
<redirect:write file="{$output.dir}/{$directory.dir}/{@id}_{@name}-fails.html">
<xsl:apply-templates select="." mode="project.details">
<xsl:with-param name="type" select="'fails'"/>
</xsl:apply-templates>
</redirect:write>
</xsl:if>
<xsl:if test="errors/text() != 0">
<redirect:write file="{$output.dir}/{$directory.dir}/{@id}_{@name}-errors.html">
<xsl:apply-templates select="." mode="project.details">
<xsl:with-param name="type" select="'errors'"/>
</xsl:apply-templates>
</redirect:write>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="index.html">
<html>
<head>
<title>AntUnit Test Results.
</head>
<frameset cols="20%,80%">
<frameset rows="30%,70%">
<frame src="overview-frame.html" name="directoryListFrame"/>
<frame src="allprojects-frame.html" name="projectListFrame"/>
</frameset>
<frame src="overview-summary.html" name="projectFrame"/>
<noframes>
<h2>Frame Alert
<p>
This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client.
</p>
</noframes>
</frameset>
</html>
</xsl:template>
<!-- this is the stylesheet css to use for nearly everything -->
<xsl:template name="stylesheet.css">
body {
font:normal 68% verdana,arial,helvetica;
color:#000000;
}
table tr td, table tr th {
font-size: 68%;
}
table.details tr th{
font-weight: bold;
text-align:left;
background:#a6caf0;
}
table.details tr td{
background:#eeeee0;
}
p {
line-height:1.5em;
margin-top:0.5em; margin-bottom:1.0em;
}
h1 {
margin: 0px 0px 5px; font: 165% verdana,arial,helvetica
}
h2 {
margin-top: 1em; margin-bottom: 0.5em; font: bold 125% verdana,arial,helvetica
}
h3 {
margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica
}
h4 {
margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica
}
h5 {
margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica
}
h6 {
margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica
}
.Error {
font-weight:bold; color:red;
}
.Failure {
font-weight:bold; color:purple;
}
.Properties {
text-align:right;
}
</xsl:template>
<!-- Create list of all/failed/errored tests -->
<xsl:template match="testsuites" mode="all.tests">
<xsl:param name="type" select="'all'"/>
<html>
<xsl:variable name="title">
<xsl:choose>
<xsl:when test="$type = 'fails'">
<xsl:text>All Failures
</xsl:when>
<xsl:when test="$type = 'errors'">
<xsl:text>All Errors
</xsl:when>
<xsl:otherwise>
<xsl:text>All Tests
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<head>
<title>AntUnit Test Results:
<xsl:call-template name="create.stylesheet.link">
<xsl:with-param name="directory.name"/>
</xsl:call-template>
</head>
<body>
<xsl:attribute name="onload">open('allprojects-frame.html','projectListFrame')
<xsl:call-template name="pageHeader"/>
<h2>
<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
<xsl:call-template name="testcase.test.header">
<xsl:with-param name="show.project" select="'yes'"/>
</xsl:call-template>
<!--
test can even not be started at all (failure to load the project)
so report the error directly
-->
<xsl:if test="./error">
<tr class="Error">
<td colspan="4">
<xsl:apply-templates select="./error"/>
</td>
</tr>
</xsl:if>
<xsl:choose>
<xsl:when test="$type = 'fails'">
<xsl:apply-templates select=".//testcase[failure]" mode="print.test">
<xsl:with-param name="show.project" select="'yes'"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$type = 'errors'">
<xsl:apply-templates select=".//testcase[error]" mode="print.test">
<xsl:with-param name="show.project" select="'yes'"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select=".//testcase" mode="print.test">
<xsl:with-param name="show.project" select="'yes'"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</table>
</body>
</html>
</xsl:template>
<!-- ======================================================================
This page is created for every testsuite project.
It prints a summary of the testsuite and detailed information about
testcase methods.
====================================================================== -->
<xsl:template match="testsuite" mode="project.details">
<xsl:param name="type" select="'all'"/>
<xsl:variable name="directory.name" select="@package"/>
<xsl:variable name="project.name">.
<html>
<head>
<title>AntUnit Test Results:
<xsl:call-template name="create.stylesheet.link">
<xsl:with-param name="directory.name" select="$directory.name"/>
</xsl:call-template>
<script type="text/javascript" language="JavaScript">
var TestCases = new Array();
var cur;
<xsl:apply-templates select="properties"/>
</script>
<script type="text/javascript" language="JavaScript">Properties of " + name + "");
doc.write("<style type=\"text/css\">");
doc.write("body {font:normal 68% verdana,arial,helvetica; color:#000000; }");
doc.write("table tr td, table tr th { font-size: 68%; }");
doc.write("table.properties { border-collapse:collapse; border-left:solid 1 #cccccc; border-top:solid 1 #cccccc; padding:5px; }");
doc.write("table.properties th { text-align:left; border-right:solid 1 #cccccc; border-bottom:solid 1 #cccccc; background-color:#eeeeee; }");
doc.write("table.properties td { font:normal; text-align:left; border-right:solid 1 #cccccc; border-bottom:solid 1 #cccccc; background-color:#fffffff; }");
doc.write("h3 { margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica }");
doc.write("</style>");
doc.write("</head>");
doc.write("<h3>Properties of " + name + "");
doc.write("<div align=\"right\">Close ");
doc.write("<table class='properties'>");
doc.write("<tr> | Name | Value |
");
for (prop in TestCases[name]) {
doc.write("<tr>