Skip to content

Commit ac5a872

Browse files
authored
Merge pull request #392 from bci-oss/391-document-past-design-decisions
Describe important past design decisions
2 parents 3b2204c + c79b260 commit ac5a872

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Native Binaries
2+
3+
## Context and Problem Statement
4+
5+
The SDK's command line interface should be usable as convenient to use as possible, i.e., it should
6+
be usable without requiring a user to have a certain version of Java installed. It should also be
7+
directly launchable, i.e., by typing its name (without the `java -jar` incantation).
8+
9+
## Decision Drivers
10+
11+
* CLI should be runnable without having Java installed.
12+
* CLI should be directly executable (i.e., without calling `java -jar`).
13+
* Beneficial: CLI should respond quickly, in particluar when showing help texts.
14+
15+
Note: A more detailed explanation of those points can be found in the blog post [Building a decent
16+
Java CLI](https://atextor.de/2020/07/27/building-a-decent-java-cli.html).
17+
18+
## Considered Options
19+
20+
* Regular executable .jar with custom launcher script and bundled JRE.
21+
* Advantages
22+
* .jar file can work as-is.
23+
* Flexibility to adjust script.
24+
* Disadvantages
25+
* Binary can not be distributed on its own; it will always need a complete folder (containing
26+
the JRE).
27+
* Overall startup time: startup time of the .exe + startup time of the JVM.
28+
* [Launch4J](https://launch4j.sourceforge.net/index.html):
29+
* Remarks
30+
* Effectively provides a native binary that optionally extracts an executable .jar from itself,
31+
then lauches the .jar using Java.
32+
* Advantages
33+
* .jar file can work as-is.
34+
* Out-of-the-box solution including Maven plugin.
35+
* Disadvantages
36+
* Binary can not be distributed on its own; it will always need a complete folder (containing
37+
the JRE).
38+
* Overall startup time: startup time of the .exe + startup time of the JVM.
39+
* [GraalVM Native Image](https://www.graalvm.org/latest/reference-manual/native-image/basics/):
40+
* Remarks
41+
* Project driven by Oracle to create native binaries from Java applications, including compiler,
42+
custom runtime (that will be baked into the binary) and accompanying tooling such as source
43+
annotations.
44+
* Advantages
45+
* "Official" project with support present or coming in major frameworks.
46+
* Proper tooling available (Maven plugin, Github actions, etc.).
47+
* Can produce standalone binaries.
48+
* Startup time overhead is removed/reduced.
49+
* Disadvantages
50+
* Additional configuration effort for resources, reflection, JNI,...
51+
52+
## Decision Outcome
53+
54+
Chosen option: "GraalVM Native Image", because only this option will provide a quickly starting,
55+
self-contained binary.
56+

0 commit comments

Comments
 (0)