Velocity Template Engine plugin or extension?

624 Views Asked by At

Has anyone tried building Velocity template engine extension or plugin?

Our team is heavily using Velocity Template Language for API input/output transformations. Since a lot of complex logic is in the VTL code, we have implemented a way to unit test the VTL code. However the current problem is that there's no way to measure the code coverage of these unit tests. We want to implement a VTL Engine extension to calculate the coverage when executing these tests. Does anyone have any insight or similar experience?

Thanks!!

1

There are 1 best solutions below

0
On

Velocity doesn't have this feature yet.

Meanwhile, you can:

  • open an issue on Velocity JIRA so that it can get a chance to be included in the next version
  • workaround the problem: prepare (automatically!) a copy of your templates where each line is prefixed by a comment with file and line number, and use the tests output to correlate the coverage
  • patch Velocity to do so, it's not that hard:
    • the org.apache.velocity.runtime.parser.Node.java class needs a new int field, visited initialized to 0
    • make each render() method increment visited in all the render() method of all other parser nodes which do have such a method
    • after the test case, use a class extending o.a.v.runtime.parser.visitor.BaseVisitor to collect, for each of your template, each node location infos and number of renderings

And if you're successful at this last option, be sure to submit a patch!