-
Notifications
You must be signed in to change notification settings - Fork 2
Plugins
Plugins provide a means to change the Java Classes that are generated. There are three different types of plugin that can be added to the generator: ClassModifyingPlugin, TypeModifyPlugin and NameGeneratablePlugin. Each type works on a different stage of the generation process.
Add plugins to the generator by adding the plugins tag to the generatorProperties tag, see below:
<configuration>
...
<generatorProperties>
<plugins>
<plugin>uk.gov.justice.generation.pojo.plugin.classmodifying.MakeClassSerializablePlugin</plugin>
<plugin>uk.gov.justice.generation.pojo.plugin.typemodifying.SupportJavaOptionalsPlugin</plugin>
<plugin>uk.gov.justice.generation.pojo.plugin.typemodifying.CustomReturnTypePlugin</plugin>
</plugins>
</generatorProperties>
...
</configuration>
The plugins are listed by delimiting them with ','.
The default plugins can be disabled by adding the following to the generatorProperties tag:
<configuration>
...
<generatorProperties>
...
<excludeDefaultPlugins>true</excludeDefaultPlugins>
...
</generatorProperties>
...
</configuration>
If the default plugins are disabled then you must provide your own plugins for creating the fields and methods of the Java POJO.
You can disable the default POJO Builder plugin (GenerateBuilderForClassPlugin), by excluding defaults then adding the field and method plugin back to the list, see below:
<configuration>
...
<generatorProperties>
<excludeDefaultPlugins>true</excludeDefaultPlugins>
<plugins>
<plugin>uk.gov.justice.generation.pojo.plugin.classmodifying.AddFieldsAndMethodsToClassPlugin</plugin>
</plugins>
</generatorProperties>
...
</configuration>
This works by applying changes to the Java Poet TypeSpec.Builder, before generation is completed. Two default plugins are setup: AddFieldsAndMethodsToClassPlugin, GenerateBuilderForClassPlugin.
Each field of a schema is represented by a Definition, and each type of Definition needs to converted into a Java Poet TypeName. The Type Modifying Plugin receives the default or already modified TypeName, which can then be modified or a completely different TypeName can be returned.
There can only be one Name Generatable Plugin present, it will decide the field name for the root schema, which will ultimately be used to generate the Class name of the root. There is a default plugin provided that uses the file name to construct the field name for the root. By adding a user defined plugin to the plugins list, this default plugin will be overridden.
- Provided Plugins - Description of provided plugins
- Plugin Development - How to develop custom Plugins
- Definition - Description of the internal model used for generation