|
| 1 | +# Template Engine |
| 2 | + |
| 3 | +## Context and Problem Statement |
| 4 | + |
| 5 | +Various modules in the SDK generate code and other artifacts, such as documentation, from Aspect |
| 6 | +Models. For this, a suitable template engine is required that can be embedded in the generation |
| 7 | +APIs. |
| 8 | + |
| 9 | +## Decision Drivers |
| 10 | + |
| 11 | +* Sufficient expressiveness for the task at hand |
| 12 | +* Good Java integration, since the engine is to be embedded in the Java code base |
| 13 | +* Beneficial: Good tool support (editing from editors/IDEs, in particular Intellij IDEA) |
| 14 | + |
| 15 | +## Considered Options |
| 16 | + |
| 17 | +* [Xtend](https://eclipse.dev/Xtext/xtend/): Language development framework on the Eclipse Platform; |
| 18 | + works like a cross between the Java language with smaller syntax and a template engine. Xtend |
| 19 | + works by cross-compiling Xtend source code to Java source code. |
| 20 | +* [Apache Velocity](https://velocity.apache.org/): Java-based template engine. IntelliJ IDEA |
| 21 | + integration exists (syntax highlighting, auto complete, etc.). Templates are defined in VTL |
| 22 | + (Velocity Template Language). |
| 23 | +* [Apache Freemarker](https://freemarker.apache.org/): Template engine with Java API integration, |
| 24 | + with an XML-like syntax. Templates are defined in FTL (Freemarker Template Language). No IntelliJ |
| 25 | + IDEA plugin seems to exist. |
| 26 | + |
| 27 | +## Decision Outcome |
| 28 | + |
| 29 | +Chosen option: "Apache Velocity", because it is a mature project. In terms of features, Velocity and |
| 30 | +Freemarker are very similar; the only notable difference for our daily work seems to be the |
| 31 | +availability of an IntelliJ IDEA plugin to work with the templates. Xtend is difficult to use for |
| 32 | +multiple reasons: Firstly, IDE support only exists for the Eclipse IDE, secondly, errors in the |
| 33 | +template result in stack traces that refer to the lines of the Java source code that was generated |
| 34 | +from the template, which makes debugging very difficult. Lastly, the cross-compilation approach on |
| 35 | +top of regular Java compilation makes building notably slower and evaluation of template snippets |
| 36 | +from (e.g., in unit tests) impossible. |
| 37 | + |
| 38 | +### Consequences |
| 39 | + |
| 40 | +* Good, because Velocity is a robust library with good IDE support. |
| 41 | +* Bad, because there seems to be not much syntax support for FTL in other editors. |
| 42 | + |
0 commit comments