menugenerator task
What is a menu generator ?
A menu generator is supposed to generate menu. It provides some methods to write menu entries in a given menu file.Writing your own menugenerator
To write your own menu generator you must write a java class implementing the org.apache.easyant.core.menu.MenuGenerator interface.This interface allow you to implements the logic to generate menu entries in a menu file.
When you're own implementation is ready you'll need to register it in easyant this is done through a menu generator registry.
What is a menu generator registry ?
A menu generator registry is used to reference all the menu generator for a given context.As explained before a menu generator is supposed to generate menu entries in one given file.
But maybe in a project we can have multiple menu files.
Let's take the example of easyant documentation, we have a root menu and we also have submenus for plugins and buildtypes.
So behind we have three different files :
- the root menu
- submenu for plugins
- submenu for buildtypes How can we handle this with easyant ?
The answer is by using context.
We can ask easyant to manage a registry by context (if not specified the default context will be "default").
Plugins can register their menugenerator implementation is the registry for a given context.
Registering a menugenerator
The syntax looks like this<ea:registermenugenerator classname="org.mycompany.menugenerators.MyOwnMenuGenerator" file="my.file" context="root"/>The registermenugenerator task support classpath and classpathref attribute.
<ea:registermenugenerator classname="org.mycompany.menugenerators.MyOwnMenuGenerator" file="my.file" context="root" classpathref="my.classpath"/>It also support nested classpath
<ea:registermenugenerator classname="org.mycompany.menugenerators.MyOwnMenuGenerator" file="my.file" context="root">So get back to our example talking about easyant documentation to understand the meaning of context.
<classpath>
<fileset dir="/path/to/directory" incluse="**/*.jar"/>
</classpath>
</ea:registermenugenerator>
We have three files so we need to register three menugenerators in different context.
Here we consider that i only uses Xooki as a documentation layer.
So the xooki plugins should do :
<ea:registermenugenerator classname="org.mycompany.menugenerators.XookiMenuGenerator" file="${basedir}/toc.json" context="root"/>
<ea:registermenugenerator classname="org.mycompany.menugenerators.XookiMenuGenerator" file="/path/to/plugins/toc.json" context="plugins"/>
<ea:registermenugenerator classname="org.mycompany.menugenerators.XookiMenuGenerator" file="/path/to/buildtypes/toc.json" context="buildtypes"/>
Here we've registered the same implementation for three different context.We will now play with menu entries
Adding a simple menu entry
The syntax looks like this :<ea:addmenuentry context="test" title="mytitle" targetlink="foobar"/>The title is the label of the link in the menu. The target link means is a URL(can be relative).
The context similar as the one in
What happens behind ?
EasyAnt will retrieve the right registry for this context, loop and all registered menu generator implementation, and process the generation of the link.
This task also supported nested
Adding a multiple menu entries
<ea:addmenuentry context="test">
<ea:menuentry title="foo" targetlink="bar"/>
<ea:menuentry title="bla" targetlink="plop"/>
<ea:menuentry title="test" targetlink="test"/>
</ea:addmenuentry>