Expander Variables
It is possible to define custom variable bindings for Expanders, Features etc. This can be useful to avoid having to repeat the same logic for each expander.
First, create a class that implements the ExpanderVariable
interface.
This class needs to implement the resolve(ExpanderVariableContext)
method.
It should return a VariableBinding object when it is applicable to do so.
You will also need to add the @VariableScope
annotation to define where the variable is needed.
@VariableScope(ARTIFACT_PATH)
public class LayerDir implements ExpanderVariable {
@Override
public Optional<VariableBinding> resolve(ExpanderVariableContext context) {
return context.getExpander()
.map(expander -> {
String dir = expander.getLayerType().getSubdir();
return bind(dir).as("layerDir")
.describedAs("Expander layer sub-directory", LayerDir.class);
});
}
}
Next, create a file META-INF/services/net.democritus.expander.variables.ExpanderVariable
.
In this file, list the variable classes you have implemented, each on a separate line.
net.democritus.expander.variables.locations.LayerDir
The expanders will find the variable classes and add the variable binding to the mapping context during expansion.
<expander name="...">
...
<artifactPath>$module.rootDirectory$/src/app/$layerDir$</artifactPath>
</expander>