Author: jdillon Date: Mon Feb 5 18:00:29 2007 New Revision: 503955 URL: http://svn.apache.org/viewvc?view=rev&rev=503955 Log: Replaced velocity with groovy's SimpleTemplateEngine for templating, as velocity does not dereference some of the more magical groovy objects (like proxies and expando) Updated the testcase template to include all details and render into package directory Added: geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/config/projects/Geronimo_CTS/report/resources/testcase.tmpl (with props) Removed: geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/config/projects/Geronimo_CTS/report/resources/macros.vm geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/config/projects/Geronimo_CTS/report/resources/testcase.vm Modified: geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/config/projects/Geronimo_CTS/report/ReportGenerator.groovy geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/util/Template.groovy geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/util/TemplateEngine.groovy Modified: geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/config/projects/Geronimo_CTS/report/ReportGenerator.groovy URL: http://svn.apache.org/viewvc/geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/config/projects/Geronimo_CTS/report/ReportGenerator.groovy?view=diff&rev=503955&r1=503954&r2=503955 ============================================================================== --- geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/config/projects/Geronimo_CTS/report/ReportGenerator.groovy (original) +++ geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/config/projects/Geronimo_CTS/report/ReportGenerator.groovy Mon Feb 5 18:00:29 2007 @@ -23,8 +23,6 @@ package gbuild.config.projects.Geronimo_CTS.report -import groovy.xml.MarkupBuilder - import gbuild.system.LogSupport import gbuild.system.util.LazyProxy import gbuild.system.util.Sorting @@ -80,7 +78,6 @@ // Setup the template engine def engine = new TemplateEngine('gbuild/config/projects/Geronimo_CTS/report/resources') - engine.libraries = [ 'macros.vm' ] // Process each result archive archives.each { archive -> @@ -134,13 +131,12 @@ def renderTestCase = { testCase -> log.info "Processing testcase: $testCase.name" - def template = engine.getTemplate('testcase.vm') + def template = engine.getTemplate('testcase.tmpl') template.params.testCase = testCase - def basedir = new File(targetDir, testCase.name.replace('.', '/').replace('#', '_')) - ant.mkdir(dir: basedir) + def file = new File(targetDir, testCase.name.replace('.', '/').replace('#', '_') + '.html') + ant.mkdir(dir: file.parentFile) - def file = new File(basedir, 'index.html') template.render(file) } Added: geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/config/projects/Geronimo_CTS/report/resources/testcase.tmpl URL: http://svn.apache.org/viewvc/geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/config/projects/Geronimo_CTS/report/resources/testcase.tmpl?view=auto&rev=503955 ============================================================================== --- geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/config/projects/Geronimo_CTS/report/resources/testcase.tmpl (added) +++ geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/config/projects/Geronimo_CTS/report/resources/testcase.tmpl Mon Feb 5 18:00:29 2007 @@ -0,0 +1,133 @@ +<% +/* + * 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. + */ + +// +// $Id$ +// +%> + + + $testCase.name + + +
+

TestCase: $testCase.name

+ + + + + +
+

Summary

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <% if (!testCase.status.passed) { %> + + + + + <% } %> +
Name:$testCase.name
Class:$testCase.className
Test:$testCase.testName
Started:$testCase.started
Ended:$testCase.ended
Duration:$testCase.duration
Status:$testCase.status.text
Passed:$testCase.status.passed
Failure Reason:$testCase.status.reason
+
+ + <% def renderProperties = { name -> %> + + <% for (entry in testCase.result[name]) { %> + + + + + <% } %> +
$entry.key$entry.value
+ <% } %> + +
+

Details

+ +

Test Description

+ + <% renderProperties('testdescription') %> + +

Environment

+ + <% renderProperties('environment') %> + +

Test Result

+ + <% renderProperties('testresult') %> + +

Sections

+ + <% + testCase.result.sections.each { name, section -> + out.println "

$name

" + + section.streams.each { ignore, stream -> + out.println "

$stream.name ($stream.lines lines, $stream.chars chars)

" + if (stream.lines > 0) { + out.println "
$stream.data
" + } + // + // TODO: else print some warning about no data + // + } + } + %> +
+
+ + + + + Propchange: geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/config/projects/Geronimo_CTS/report/resources/testcase.tmpl ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/config/projects/Geronimo_CTS/report/resources/testcase.tmpl ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/config/projects/Geronimo_CTS/report/resources/testcase.tmpl ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/util/Template.groovy URL: http://svn.apache.org/viewvc/geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/util/Template.groovy?view=diff&rev=503955&r1=503954&r2=503955 ============================================================================== --- geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/util/Template.groovy (original) +++ geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/util/Template.groovy Mon Feb 5 18:00:29 2007 @@ -33,7 +33,7 @@ import org.apache.velocity.VelocityContext /** - * Wrapper around a Velocity template. + * Helper to render a template. */ class Template extends LogSupport { @@ -41,9 +41,9 @@ Map params = [:] - private org.apache.velocity.Template template + private groovy.text.Template template - def Template(String name, org.apache.velocity.Template template) { + def Template(String name, groovy.text.Template template) { assert name assert template @@ -56,16 +56,10 @@ log.debug "Rendering template: $name" - def context = new VelocityContext() - - params.each { - context.put(it.key, it.value) - } - def watch = new StopWatch() watch.start() - template.merge(context, writer) + template.make(params).writeTo(writer) log.debug "Rendered template in $watch" } Modified: geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/util/TemplateEngine.groovy URL: http://svn.apache.org/viewvc/geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/util/TemplateEngine.groovy?view=diff&rev=503955&r1=503954&r2=503955 ============================================================================== --- geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/util/TemplateEngine.groovy (original) +++ geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/util/TemplateEngine.groovy Mon Feb 5 18:00:29 2007 @@ -23,53 +23,49 @@ package gbuild.system.util +import groovy.text.SimpleTemplateEngine + import gbuild.system.LogSupport import org.apache.commons.lang.time.StopWatch -import org.apache.velocity.app.VelocityEngine - /** - * Helper to render templates with Velocity. + * Helper to create templates. */ class TemplateEngine extends LogSupport { - private VelocityEngine velocity = new VelocityEngine() + private SimpleTemplateEngine engine = new SimpleTemplateEngine() - // Lazy initialized to allow nicer API to installing libraries - private boolean initialized = false + private URL baseurl - def TemplateEngine(basepath) { - def url = getClass().classLoader.getResource(basepath) - assert url - assert url.protocol == 'file' - - def basedir = url.path - log.info "Base dir: $basedir" + private Map cache = [:] + + def TemplateEngine(String basepath) { + assert basepath - velocity.setProperty('resource.loader', 'file') - velocity.setProperty('file.resource.loader.description', 'Velocity File Resource Loader') - velocity.setProperty('file.resource.loader.class', 'org.apache.velocity.runtime.resource.loader.FileResourceLoader') - velocity.setProperty('file.resource.loader.path', basedir) - velocity.setProperty('file.resource.loader.cache', 'false') - velocity.setProperty('file.resource.loader.modificationCheckInterval', '2') + if (!basepath.endsWith('/')) { + basepath += '/' + } - velocity.setProperty('runtime.log.logsystem.class', 'org.apache.velocity.runtime.log.NullLogSystem') + baseurl = getClass().classLoader.getResource(basepath) + assert baseurl } - def setLibraries(List libs) { - assert libs - assert !initialized + Template getTemplate(String name) { + assert name - velocity.setProperty('velocimacro.library', libs.join(',')) - } - - Template getTemplate(name) { - if (!initialized) { - velocity.init() - initialized = true + def tmpl = cache[name] + if (!tmpl) { + def url = new URL(baseurl, name) + log.info "Creating new template: $name, from: $url" + + tmpl = engine.createTemplate(url) + cache[name] = tmpl + } + else { + log.info "Using cached template: $name" } - return new Template(name, velocity.getTemplate(name)) + return new Template(name, tmpl) } }