1 <?xml version="1.0"?> 2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 3 xmlns:lxslt="http://xml.apache.org/xslt" 4 xmlns:redirect="org.apache.xalan.lib.Redirect" 5 extension-element-prefixes="redirect"> 6 <xsl:output method="html" indent="yes"/> 7 <xsl:decimal-format decimal-separator="." grouping-separator="," /> 8 <!-- 9 Licensed to the Apache Software Foundation (ASF) under one or more 10 contributor license agreements. See the NOTICE file distributed with 11 this work for additional information regarding copyright ownership. 12 The ASF licenses this file to You under the Apache License, Version 2.0 13 (the "License"); you may not use this file except in compliance with 14 the License. You may obtain a copy of the License at 15 16 http://www.apache.org/licenses/LICENSE-2.0 17 18 Unless required by applicable law or agreed to in writing, software 19 distributed under the License is distributed on an "AS IS" BASIS, 20 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 See the License for the specific language governing permissions and 22 limitations under the License. 23 --> 24 25 <!-- 26 27 Sample stylesheet to be used with JProbe 3.0 XML output. 28 29 It creates a set of HTML files a la javadoc where you can browse easily 30 through all packages and classes. 31 32 It is best used with JProbe Coverage Ant task that gives you the benefit 33 of a reference classpath so that you have the list of classes/methods 34 that are not used at all in a given classpath. 35 36 @author Stephane Bailliez <a href="mailto:sbailliez (a] apache.org"/> 37 38 --> 39 40 <!-- default output directory is current directory --> 41 <xsl:param name="output.dir" select="'.'"/> 42 43 <!-- ====================================================================== 44 Root element 45 ======================================================================= --> 46 <xsl:template match="/snapshot"> 47 <!-- create the index.html --> 48 <redirect:write file="{$output.dir}/index.html"> 49 <xsl:call-template name="index.html"/> 50 </redirect:write> 51 52 <!-- create the stylesheet.css --> 53 <redirect:write file="{$output.dir}/stylesheet.css"> 54 <xsl:call-template name="stylesheet.css"/> 55 </redirect:write> 56 57 <!-- create the overview-packages.html at the root --> 58 <redirect:write file="{$output.dir}/overview-summary.html"> 59 <xsl:apply-templates select="." mode="overview.packages"/> 60 </redirect:write> 61 62 <!-- create the all-packages.html at the root --> 63 <redirect:write file="{$output.dir}/overview-frame.html"> 64 <xsl:apply-templates select="." mode="all.packages"/> 65 </redirect:write> 66 67 <!-- create the all-classes.html at the root --> 68 <redirect:write file="{$output.dir}/allclasses-frame.html"> 69 <xsl:apply-templates select="." mode="all.classes"/> 70 </redirect:write> 71 72 <!-- process all packages --> 73 <xsl:apply-templates select="./package" mode="write"/> 74 </xsl:template> 75 76 <!-- ======================================================================= 77 Frameset definition. Entry point for the report. 78 3 frames: packageListFrame, classListFrame, classFrame 79 ======================================================================= --> 80 <xsl:template name="index.html"> 81 <html> 82 <head><title>Coverage Results.</title></head> 83 <frameset cols="20%,80%"> 84 <frameset rows="30%,70%"> 85 <frame src="overview-frame.html" name="packageListFrame"/> 86 <frame src="allclasses-frame.html" name="classListFrame"/> 87 </frameset> 88 <frame src="overview-summary.html" name="classFrame"/> 89 </frameset> 90 <noframes> 91 <h2>Frame Alert</h2> 92 <p> 93 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. 94 </p> 95 </noframes> 96 </html> 97 </xsl:template> 98 99 <!-- ======================================================================= 100 Stylesheet CSS used 101 ======================================================================= --> 102 <!-- this is the stylesheet css to use for nearly everything --> 103 <xsl:template name="stylesheet.css"> 104 .bannercell { 105 border: 0px; 106 padding: 0px; 107 } 108 body { 109 margin-left: 10; 110 margin-right: 10; 111 font:normal 80% arial,helvetica,sanserif; 112 background-color:#FFFFFF; 113 color:#000000; 114 } 115 .a td { 116 background: #efefef; 117 } 118 .b td { 119 background: #fff; 120 } 121 th, td { 122 text-align: left; 123 vertical-align: top; 124 } 125 th { 126 font-weight:bold; 127 background: #ccc; 128 color: black; 129 } 130 table, th, td { 131 font-size:100%; 132 border: none 133 } 134 table.log tr td, tr th { 135 136 } 137 h2 { 138 font-weight:bold; 139 font-size:140%; 140 margin-bottom: 5; 141 } 142 h3 { 143 font-size:100%; 144 font-weight:bold; 145 background: #525D76; 146 color: white; 147 text-decoration: none; 148 padding: 5px; 149 margin-right: 2px; 150 margin-left: 2px; 151 margin-bottom: 0; 152 } 153 </xsl:template> 154 155 <!-- ======================================================================= 156 List of all classes in all packages 157 This will be the first page in the classListFrame 158 ======================================================================= --> 159 <xsl:template match="snapshot" mode="all.classes"> 160 <html> 161 <head> 162 <xsl:call-template name="create.stylesheet.link"/> 163 </head> 164 <body> 165 <h2>Classes</h2> 166 <table width="100%"> 167 <xsl:for-each select="package/class"> 168 <xsl:sort select="@name"/> 169 <xsl:variable name="package.name" select="(ancestor::package)[last()]/@name"/> 170 <xsl:variable name="link"> 171 <xsl:if test="not($package.name='')"> 172 <xsl:value-of select="translate($package.name,'.','/')"/><xsl:text>/</xsl:text> 173 </xsl:if><xsl:value-of select="@name"/><xsl:text>.html</xsl:text> 174 </xsl:variable> 175 <tr> 176 <td nowrap="nowrap"> 177 <a target="classFrame" href="{$link}"><xsl:value-of select="@name"/></a> 178 </td> 179 </tr> 180 </xsl:for-each> 181 </table> 182 </body> 183 </html> 184 </xsl:template> 185 186 <!-- list of all packages --> 187 <xsl:template match="snapshot" mode="all.packages"> 188 <html> 189 <head> 190 <xsl:call-template name="create.stylesheet.link"/> 191 </head> 192 <body> 193 <h2><a href="overview-summary.html" target="classFrame">Home</a></h2> 194 <h2>Packages</h2> 195 <table width="100%"> 196 <xsl:for-each select="package"> 197 <xsl:sort select="@name" order="ascending"/> 198 <tr> 199 <td nowrap="nowrap"> 200 <a href="{translate(@name,'.','/')}/package-summary.html" target="classFrame"> 201 <xsl:value-of select="@name"/> 202 </a> 203 </td> 204 </tr> 205 </xsl:for-each> 206 </table> 207 </body> 208 </html> 209 </xsl:template> 210 211 <!-- overview of statistics in packages --> 212 <xsl:template match="snapshot" mode="overview.packages"> 213 <html> 214 <head> 215 <xsl:call-template name="create.stylesheet.link"/> 216 </head> 217 <body onload="open('allclasses-frame.html','classListFrame')"> 218 <xsl:call-template name="pageHeader"/> 219 <h3>Summary</h3> 220 <table class="log" cellpadding="5" cellspacing="2" width="100%"> 221 <tr> 222 <!--th width="10%" nowrap="nowrap">Date</th> 223 <th width="10%" nowrap="nowrap">Elapsed time</th--> 224 <th width="10%" nowrap="nowrap">Reported Classes</th> 225 <th width="10%" nowrap="nowrap">Methods Hit</th> 226 <th width="10%" nowrap="nowrap">Lines Hit</th> 227 </tr> 228 <tr class="a"> 229 <!--td nowrap="nowrap"><xsl:value-of select="execution_log/@program_start"/></td> 230 <td><xsl:value-of select="format-number(execution_log/@elapsed_time div 1000,'0.0')"/>secs</td--> 231 <td><xsl:value-of select="count(package/class)"/></td> 232 <td><xsl:value-of select="format-number(cov.data/@hit_methods div cov.data/@total_methods,'0.0%')"/></td> 233 <td><xsl:value-of select="format-number(cov.data/@hit_lines div cov.data/@total_lines,'0.0%')"/></td> 234 </tr> 235 </table> 236 <table border="0" width="100%"> 237 <tr> 238 <td style="text-align: justify;"> 239 To ensure accurate test runs on Java applications, developers need to know how much of 240 the code has been tested, and where to find any untested code. Coverage helps you 241 locate untested code, and measure precisely how much code has been exercised. 242 The result is a higher quality application in a shorter period of time. 243 <p/> 244 </td> 245 </tr> 246 </table> 247 248 <h3>Packages</h3> 249 <table class="log" cellpadding="5" cellspacing="2" width="100%"> 250 <xsl:apply-templates select="package[1]" mode="stats.header"/> 251 <!-- display packages and sort them via their coverage rate --> 252 <xsl:for-each select="package"> 253 <xsl:sort data-type="number" select="cov.data/@hit_lines div cov.data/@total_lines"/> 254 <tr> 255 <xsl:call-template name="alternate-row"/> 256 <td><a href="{translate(@name,'.','/')}/package-summary.html"><xsl:value-of select="@name"/></a></td> 257 <td><xsl:value-of select="format-number(cov.data/@hit_methods div cov.data/@total_methods,'0.0%')"/></td> 258 <td><xsl:value-of select="format-number(cov.data/@hit_lines div cov.data/@total_lines,'0.0%')"/></td> 259 </tr> 260 </xsl:for-each> 261 </table> 262 <xsl:call-template name="pageFooter"/> 263 </body> 264 </html> 265 </xsl:template> 266 267 <!-- 268 detailed info for a package. It will output the list of classes 269 , the summary page, and the info for each class 270 --> 271 <xsl:template match="package" mode="write"> 272 <xsl:variable name="package.dir"> 273 <xsl:if test="not(@name = '')"><xsl:value-of select="translate(@name,'.','/')"/></xsl:if> 274 <xsl:if test="@name = ''">.</xsl:if> 275 </xsl:variable> 276 277 <!-- create a classes-list.html in the package directory --> 278 <redirect:write file="{$output.dir}/{$package.dir}/package-frame.html"> 279 <xsl:apply-templates select="." mode="classes.list"/> 280 </redirect:write> 281 282 <!-- create a package-summary.html in the package directory --> 283 <redirect:write file="{$output.dir}/{$package.dir}/package-summary.html"> 284 <xsl:apply-templates select="." mode="package.summary"/> 285 </redirect:write> 286 287 <!-- for each class, creates a @name.html --> 288 <xsl:for-each select="class"> 289 <redirect:write file="{$output.dir}/{$package.dir}/{@name}.html"> 290 <xsl:apply-templates select="." mode="class.details"/> 291 </redirect:write> 292 </xsl:for-each> 293 </xsl:template> 294 295 <!-- list of classes in a package --> 296 <xsl:template match="package" mode="classes.list"> 297 <html> 298 <HEAD> 299 <xsl:call-template name="create.stylesheet.link"> 300 <xsl:with-param name="package.name" select="@name"/> 301 </xsl:call-template> 302 </HEAD> 303 <BODY> 304 <table width="100%"> 305 <tr> 306 <td nowrap="nowrap"> 307 <H2><a href="package-summary.html" target="classFrame"><xsl:value-of select="@name"/></a></H2> 308 </td> 309 </tr> 310 </table> 311 312 <H2>Classes</H2> 313 <TABLE WIDTH="100%"> 314 <xsl:for-each select="class"> 315 <xsl:sort select="@name"/> 316 <tr> 317 <td nowrap="nowrap"> 318 <a href="{@name}.html" target="classFrame"><xsl:value-of select="@name"/></a> 319 </td> 320 </tr> 321 </xsl:for-each> 322 </TABLE> 323 </BODY> 324 </html> 325 </xsl:template> 326 327 <!-- summary of a package --> 328 <xsl:template match="package" mode="package.summary"> 329 <HTML> 330 <HEAD> 331 <xsl:call-template name="create.stylesheet.link"> 332 <xsl:with-param name="package.name" select="@name"/> 333 </xsl:call-template> 334 </HEAD> 335 <!-- when loading this package, it will open the classes into the frame --> 336 <BODY onload="open('package-frame.html','classListFrame')"> 337 <xsl:call-template name="pageHeader"/> 338 <h3>Package <xsl:value-of select="@name"/></h3> 339 <table class="log" cellpadding="5" cellspacing="2" width="100%"> 340 <xsl:apply-templates select="." mode="stats.header"/> 341 <xsl:apply-templates select="." mode="stats"/> 342 </table> 343 344 <xsl:if test="count(class) > 0"> 345 <H3>Classes</H3> 346 <table class="log" cellpadding="5" cellspacing="2" width="100%"> 347 <xsl:apply-templates select="." mode="stats.header"/> 348 <xsl:apply-templates select="class" mode="stats"> 349 <xsl:sort data-type="number" select="cov.data/@hit_lines div cov.data/@total_lines"/> 350 </xsl:apply-templates> 351 </table> 352 </xsl:if> 353 <xsl:call-template name="pageFooter"/> 354 </BODY> 355 </HTML> 356 </xsl:template> 357 358 <!-- details of a class --> 359 <xsl:template match="class" mode="class.details"> 360 <xsl:variable name="package.name" select="(ancestor::package)[last()]/@name"/> 361 <HTML> 362 <HEAD> 363 <xsl:call-template name="create.stylesheet.link"> 364 <xsl:with-param name="package.name" select="$package.name"/> 365 </xsl:call-template> 366 </HEAD> 367 <BODY> 368 <xsl:call-template name="pageHeader"/> 369 <H3>Class <xsl:if test="not($package.name = '')"><xsl:value-of select="$package.name"/>.</xsl:if><xsl:value-of select="@name"/></H3> 370 371 <!-- class summary --> 372 <table class="log" cellpadding="5" cellspacing="2" width="100%"> 373 <xsl:apply-templates select="." mode="stats.header"/> 374 <xsl:apply-templates select="." mode="stats"/> 375 </table> 376 377 <!-- details of methods --> 378 <H3>Methods</H3> 379 <table class="log" cellpadding="5" cellspacing="2" width="100%"> 380 <xsl:apply-templates select="method[1]" mode="stats.header"/> 381 <xsl:apply-templates select="method" mode="stats"> 382 <xsl:sort data-type="number" select="cov.data/@hit_lines div cov.data/@total_lines"/> 383 </xsl:apply-templates> 384 </table> 385 <xsl:call-template name="pageFooter"/> 386 </BODY> 387 </HTML> 388 389 </xsl:template> 390 391 <!-- Page Header --> 392 <xsl:template name="pageHeader"> 393 <!-- jakarta logo --> 394 <table border="0" cellpadding="0" cellspacing="0" width="100%"> 395 <tr> 396 <td class="bannercell" rowspan="2"> 397 <a href="http://jakarta.apache.org/"> 398 <img src="http://jakarta.apache.org/images/jakarta-logo.gif" alt="http://jakarta.apache.org" align="left" border="0"/> 399 </a> 400 </td> 401 <td style="text-align:right"><h2>Source Code Coverage</h2></td> 402 </tr> 403 <tr> 404 <td style="text-align:right">Designed for use with <a href='http://www.sitraka.com/jprobe'>Sitraka JProbe</a> and <a href='http://jakarta.apache.org'>Ant</a>.</td> 405 </tr> 406 </table> 407 <hr size="1"/> 408 </xsl:template> 409 410 <!-- Page Footer --> 411 <xsl:template name="pageFooter"> 412 </xsl:template> 413 414 415 <xsl:template name="table.header"> 416 <tr> 417 <th width="80%">Name</th> 418 <th width="10%" nowrap="nowrap">Methods Hit</th> 419 <th width="10%" nowrap="nowrap">Lines Hit</th> 420 </tr> 421 </xsl:template> 422 423 <xsl:template match="method" mode="stats.header"> 424 <tr> 425 <th width="90%">Name</th> 426 <th width="10%" nowrap="nowrap">Lines Hit</th> 427 </tr> 428 </xsl:template> 429 <xsl:template match="method" mode="stats"> 430 <tr> 431 <xsl:call-template name="alternate-row"/> 432 <td><xsl:value-of select="@name"/></td> 433 <td> 434 <xsl:value-of select="format-number(cov.data/@hit_lines div cov.data/@total_lines,'0.0%')"/> 435 </td> 436 </tr> 437 </xsl:template> 438 439 <xsl:template match="package|class" mode="stats.header"> 440 <tr> 441 <th width="80%">Name</th> 442 <th width="10%" nowrap="nowrap">Methods Hit</th> 443 <th width="10%" nowrap="nowrap">Lines Hit</th> 444 </tr> 445 </xsl:template> 446 <xsl:template match="package|class" mode="stats"> 447 <tr> 448 <xsl:call-template name="alternate-row"/> 449 <td><xsl:value-of select="@name"/></td> 450 <td><xsl:value-of select="format-number(cov.data/@hit_methods div cov.data/@total_methods,'0.0%')"/></td> 451 <td><xsl:value-of select="format-number(cov.data/@hit_lines div cov.data/@total_lines,'0.0%')"/></td> 452 </tr> 453 </xsl:template> 454 455 <!-- 456 transform string like a.b.c to ../../../ 457 @param path the path to transform into a descending directory path 458 --> 459 <xsl:template name="path"> 460 <xsl:param name="path"/> 461 <xsl:if test="contains($path,'.')"> 462 <xsl:text>../</xsl:text> 463 <xsl:call-template name="path"> 464 <xsl:with-param name="path"><xsl:value-of select="substring-after($path,'.')"/></xsl:with-param> 465 </xsl:call-template> 466 </xsl:if> 467 <xsl:if test="not(contains($path,'.')) and not($path = '')"> 468 <xsl:text>../</xsl:text> 469 </xsl:if> 470 </xsl:template> 471 472 473 <!-- create the link to the stylesheet based on the package name --> 474 <xsl:template name="create.stylesheet.link"> 475 <xsl:param name="package.name"/> 476 <LINK REL ="stylesheet" TYPE="text/css" TITLE="Style"><xsl:attribute name="href"><xsl:if test="not($package.name = 'unnamed package')"><xsl:call-template name="path"><xsl:with-param name="path" select="$package.name"/></xsl:call-template></xsl:if>stylesheet.css</xsl:attribute></LINK> 477 </xsl:template> 478 479 <!-- alternated row style --> 480 <xsl:template name="alternate-row"> 481 <xsl:attribute name="class"> 482 <xsl:if test="position() mod 2 = 1">a</xsl:if> 483 <xsl:if test="position() mod 2 = 0">b</xsl:if> 484 </xsl:attribute> 485 </xsl:template> 486 487 </xsl:stylesheet> 488 489 490