jvanzyl     2002/06/27 18:53:37

  Added:       src/plugins/junit-report junit.dvsl plugin.jelly
                        plugin.properties toolbox.props
  Log:
  Junit report plugin.
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-maven/src/plugins/junit-report/junit.dvsl
  
  Index: junit.dvsl
  ===================================================================
  #######################################################################
  ## J U N I T     D V S L     S T Y L E S H E E T                     ##
  #######################################################################
  
  ## This stylesheet is used to transform the output of JUnit's xml
  ## generator.  The XML is transformed into a standard xdoc that can
  ## then be transformed (yet again) using whatever stylesheet is used
  ## to format one's site.
  ##
  ## Based on the XSL stylesheet junit-noframes.xsl from Ant.
  ##
  ## Version: $Id: junit.dvsl,v 1.1 2002/06/28 01:53:37 jvanzyl Exp $
  
  #######################################################################
  ## G L O B A L    V A R I A B L E S                                  ##
  #######################################################################
  
  ## Used to facilitate quoting in the template.
  ##
  #set ($quote = '"')
  
  #######################################################################
  ## V E L O C I T Y    M A C R O S                                    ##
  #######################################################################
  
  ## Convert a string that represents a number using the specified
  ## pattern.  
  ##
  #macro (formatAsNumber $string $pattern)
      #set ($value = $context.toolbox.numbers.parse($string))
      $context.toolbox.formatter.formatNumber($value, $pattern)
  #end
  
  ## Prints a standard navbar for navigation.
  ##
  #macro (navbar)
        <p>
          [<a href="#Summary">summary</a>]
          [<a href="#Package List">package list</a>]
          [<a href="#Test Cases">test cases</a>]
        </p>
  #end
  
  ## Prints a standard header for a test suite.
  ##
  #macro (testSuiteHeader)
      <tr>
        <th>Name</th>
        <th>Tests</th>
        <th>Errors</th>
        <th>Failures</th>
        <th>Time(s)</th>
      </tr>
  #end
  
  ## Prints a standard header for a test case.
  ##
  #macro (testCaseHeader)
      <tr>
        <th>Name</th>
        <th>Status</th>
        <th>Type</th>
        <th>Time(s)</th>
      </tr>
  #end
  
  ## Prints the message from a failure.
  ##
  #macro (displayFailure $current)
      #if ($current.attribute("message"))
        $context.toolbox.htmlescape.getText($current.attribute("message"))
      #else
        N/A
      #end
      <p/>
      <code>
        $context.toolbox.htmlescape.getText($current.value())
      </code>
  #end
  
  ## Generates the report if unit tests were present.
  ##
  #macro (generateReport)
        #navbar ()
        <p>
          The following document contains the results of the <a
          href="http://www.junit.org";>JUnit</a> tests.  
        </p>
      </section>
  
      ###################################################################
      <section name="Summary">
        #navbar ()
        #set ($testCount    = $node.valueOf("sum(testsuite/@tests)"))
        #set ($errorCount   = $node.valueOf("sum(testsuite/@errors)"))
        #set ($failureCount = $node.valueOf("sum(testsuite/@failures)"))
        #set ($timeCount    = $node.valueOf("sum(testsuite/@time)"))
        #set ($successRate  = $node.valueOf("($testCount - ($failureCount + 
$errorCount)) div $testCount"))
        <table>
          <tr>
            <th>Tests</th>
            <th>Errors</th>
            <th>Failures</th>
            <th>Success rate</th>
            <th>Time(s)</th>
          </tr>
          <tr>
            <td>#formatAsNumber ($testCount    "0")</td>
            <td>#formatAsNumber ($errorCount   "0")</td>
            <td>#formatAsNumber ($failureCount "0")</td>
            <td>#formatAsNumber ($successRate  "0.00%")</td>
            <td>#formatAsNumber ($timeCount    "0.000")</td>
          </tr>
        </table>
        <p>
          Note: <i>failures</i> are anticipated and checked for with
          assertions while <i>errors</i> are unanticipated.
        </p>
      </section>
  
      ###################################################################
      <section name="Package List">
        #navbar ()
        <table>
            #testSuiteHeader ()
            #foreach ($testsuite in $node.selectNodes("./testsuite[not(./@package = 
preceding-sibling::testsuite/@package)]"))
            #set ($package = $testsuite.attribute('package'))
            #set ($quotedPackage = "$quote$package$quote")
            #set ($testCount     = $node.valueOf("sum(./testsuite[./@package = 
$quotedPackage]/@tests)"))
            #set ($errorCount    = $node.valueOf("sum(./testsuite[./@package = 
$quotedPackage]/@errors)"))
            #set ($failureCount  = $node.valueOf("sum(./testsuite[./@package = 
$quotedPackage]/@failures)"))
            #set ($timeCount     = $node.valueOf("sum(./testsuite[./@package = 
$quotedPackage]/@time)"))
          <tr>
            <td><a href="#$package">$package</a></td>
            <td>#formatAsNumber ($testCount    "0")</td>
            <td>#formatAsNumber ($failureCount "0")</td>
            <td>#formatAsNumber ($errorCount   "0")</td>
            <td>#formatAsNumber ($timeCount    "0.000")</td>
          </tr>
            #end
        </table>
        <p>
          Note: package statistics are not computed recursively, they only
          sum up all of its testsuites numbers.
        </p>
    
        #foreach ($testsuite in $node.selectNodes("./testsuite[not(./@package = 
preceding-sibling::testsuite/@package)]"))
        #set ($package = "$testsuite.attribute('package')")
        #set ($quotedPackage = "$quote$package$quote")
        <subsection name="$package">
          <table>
            #testSuiteHeader ()
            #foreach ($test in $node.selectNodes("/testsuites/testsuite[./@package = 
$quotedPackage]"))
            <tr>
              <td><a href="#$test.attribute('name')">$test.attribute('name')</a></td>
              <td>#formatAsNumber ($test.attribute('tests')    "0")</td>
              <td>#formatAsNumber ($test.attribute('errors')   "0")</td>
              <td>#formatAsNumber ($test.attribute('failures') "0")</td>
              <td>#formatAsNumber ($test.attribute('time')     "0.000")</td>
            </tr>
            #end
          </table>
        </subsection>
        #end
      </section>
  
      ###################################################################
      <section name="Test Cases">       
        #navbar ()
        #foreach ($testsuite in $node.selectNodes("./testsuite"))
        <subsection name="$testsuite.attribute('name')">
          <table>
            #testCaseHeader ()
  
            ## test can even not be started at all (failure to load the class)
            ## so report the error directly
            ##
            #foreach ($error in $testsuite.selectNodes("./error"))
            <tr> <td colspan="4"> #displayFailure ($error) </td> </tr>
            #end
  
            #foreach ($testcase in $testsuite.selectNodes("./testcase"))
            <tr>
              <td>$testcase.attribute("name")</td>
              #if ($testcase.get("failure"))
              <td>Failure</td>
              <td> #displayFailure ($testcase.selectSingleNode("failure")) </td>
              #elseif ($testcase.get("error"))
              <td>Error</td>
              <td> #displayFailure ($testcase.selectSingleNode("error")) </td>
              #else
              <td>Success</td>
              <td></td>
              #end
              #if ($testcase.attribute("time"))
              <td>#formatAsNumber ($testcase.attribute("time") "0.000")</td>
              #else
              <td></td>
              #end
            </tr>
            #end
          </table>
        </subsection>
        #end
      </section>
  #end
  
  #######################################################################
  ## T E M P L A T E    D E F I N I T I O N S                          ## 
  ####################################################################### 
  
  ## Matches the root element of the JUnit XML report.
  ##
  #match ("testsuites")
  <?xml version="1.0"?>
  <document>
  
    <properties>
      <title>JUnit Test Results</title>
    </properties>
  
    <body>
      <section name="Unit Test Results">
  
      #if (! $node.get("testsuite"))
        <p>
          This project does not have contain any unit tests.
        </p>
      </section>
      #else
          #generateReport()
      #end
  
    </body>
  </document>
  #end
  
  
  
  
  1.1                  jakarta-turbine-maven/src/plugins/junit-report/plugin.jelly
  
  Index: plugin.jelly
  ===================================================================
  <?xml version="1.0"?>
  
  <project xmlns:j="jelly:core">
    
    <!-- ================================================================== -->
    <!-- C R E A T E  J U N I T  X M L  R E P O R T                         -->
    <!-- ================================================================== -->
  
    <taskdef
      name="dvsl"
      classname="org.apache.tools.dvsl.DVSLTask">
      <classpath refid="maven-classpath"/>
    </taskdef>
  
    <goal
      name="junit-xml">
  
      <j:if test="${unitTestSourcesPresent == 'true'}">
  
      <mkdir dir="${maven.test.reportsDirectory}"/>
  
      <!-- Consolidate the reports into a single -->
      <junitreport todir="${maven.test.reportsDirectory}">
        <fileset dir="${maven.test.reportsDirectory}">
          <include name="TEST-*.xml"/>
        </fileset>
      </junitreport>
  
      <!-- Convert single report into an xdoc -->
      <dvsl
        basedir="${basedir}"
        style="${maven.home}/plugins/junit-report/junit.dvsl"
        toolboxfile="${maven.home}/plugins/junit-report/toolbox.props"
        in="${maven.test.reportsDirectory}/TESTS-TestSuites.xml"
        out="${maven.gen.docs}/junit-report.xml">
        <classpath>
          <path refid="maven-classpath"/>
        </classpath>
      </dvsl>
      
      </j:if>
      
    </goal>
  
  </project>
  
  
  
  1.1                  jakarta-turbine-maven/src/plugins/junit-report/plugin.properties
  
  Index: plugin.properties
  ===================================================================
  # -------------------------------------------------------------------
  # P L U G I N  P R O P E R I E S
  # -------------------------------------------------------------------
  # JUnit report plugin.
  # -------------------------------------------------------------------
  
  maven.src.dir = ${basedir}/src
  maven.conf.dir = ${basedir}/conf
  maven.build.dir = ${basedir}/target
  maven.build.src = ${maven.build.dir}/src
  maven.build.dest = ${maven.build.dir}/classes
  
  maven.docs.src = ${basedir}/xdocs
  maven.docs.dest = ${maven.build.dir}/docs
  maven.docs.outputencoding = ISO-8859-1
  maven.gen.docs = ${maven.build.dir}/generated-xdocs
  
  maven.junit.fork = no 
  maven.junit.dir = ${basedir}
  maven.junit.usefile = true
  maven.test.dest = ${maven.build.dir}/test-classes
  maven.test.reportsDirectory = ${maven.build.dir}/test-reports
  
  
  
  1.1                  jakarta-turbine-maven/src/plugins/junit-report/toolbox.props
  
  Index: toolbox.props
  ===================================================================
  toolbox.contextname = toolbox
  toolbox.tool.htmlescape = org.apache.velocity.anakia.Escape
  toolbox.tool.numbers = java.text.DecimalFormat
  toolbox.tool.fileutil = org.apache.velocity.texen.util.FileUtil
  toolbox.tool.strings = org.apache.commons.lang.Strings
  toolbox.tool.formatter = org.apache.maven.DVSLFormatter
  toolbox.tool.pathtool = org.apache.maven.DVSLPathTool
  toolbox.tool.maven = org.apache.maven.MavenTool
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to