Creating an Ant XDoclet Task
Problem
You want to create an Ant XDoclet task and subtask to generate a new type of file.
Solution
Extend xdoclet.DocletTask to create the main task,
if necessary, and extend xdoclet.TemplateSubTask
to create one or more subtasks.
Discussion
This recipe is the first part of a five-part recipe. It describes the
steps needed to create a new Ant XDoclet task and subtask. We are
going to create tasks for the
JUnitPerfDoclet
code generator.
Tip
JUnitPerfDoclet does not need a main XDoclet task. Specifically, we
do not need to extend xdoclet.DocletTask because
no extra functionality needs to be added. All of the functionality
needed by JUnitPerfDoclet lies in the subtask. For completeness, this
recipe shows how to create a Doclet task.
Creating an Ant XDoclet task
The first step is to create the main Ant XDoclet task. This task is
much like the ejbdoclet task, serving as an entry
point into the XDoclet engine.
Here are the steps needed to create an Ant XDoclet task:
Create a new Java source file and give it a name. For this example, create a
YourNewDocletTask.javafile and add it to your project.Add the following import:
import xdoclet.DocletTask;
Extend the
DocletTaskclass:public class YourNewDocletTask extends DocletTask {Add the necessary public getter and setter methods for attributes your task defines. For example, if your new task defines an attribute called
validId, then you would have this setter method:public void setValidId(String id) { this.id = id; }
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access