Extensions - overview
Starting with version 3
Extensible model for generating new code
We have pared down the artefacts that h2zero generates to the very basic java and SQL based files. Through extensions, additional features and code generators can be enabled.
Parts of the extension
- The actual code, and
- the configuration
Once the code and configuration items are done, the extension then needs to be registered to run within the h2zero generation.
The code
The code is divided into two parts:
- The
Extension, and optionally - zero or more
Validators
The Extension generates the artefacts, taking the parsed h2zero models and outputting code into various places. It may generate more than one file of multiple file types.
There is only ever one entry point for the code.
The Validator validates that the h2zero model objects have all of the required information so that the generation of the files will have the highest chance of success. This is an optional component and there can be more that one Validator for each extension.
The configuration
The configuration for the extension, and passing in configuration items is held within the h2zero file.
{
"options": {
...
"extensions": [
"synapticloop.h2zero.extension.TaglibExtension"
],
"synapticloop.h2zero.extension.TaglibExtension": {
"string": "value",
"isBoolean": true,
"number": 23
}
...
"output": {
"code": "src/test/java/",
"resources": "src/test/resources/",
"build": "build/"
}
},
The extension is registered within the options JSON object within the JSON Array key of extensions.
"extensions": [
"synapticloop.h2zero.extension.TaglibExtension"
],
For any options that are required to be passed through, the extension class then becomes the key for passing in the options. I.e. an extension of synapticloop.h2zero.extension.TaglibExtension will look for a key of synapticloop.h2zero.extension.TaglibExtension within the options JSON object.