ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pierre, Sebastian" <spie...@Rational.Com>
Subject Re: Defining tasks in several build.xml files
Date Thu, 15 Jun 2000 17:05:51 GMT
> So, I would like to know if there is a way with Ant to define a task
> that can be "included" in another 'build.xml', so that you can have a
> kind of repository of common tasks that you can include.
> 
> If such a thing does not exist, do you have suggestions on what you
> (all Ant users) would like so that I can see if I can add it.

Hi !

I guess I'm answering a little bit lately to your message, and somebody
may have already answered your question.

My suggestion is to use entities, which are typically an XML thing that
allows inclusion of file (a little bit like #define and #include in C).

For example if you use the following task in each of your project:

  | <taskdef name="myTask" classname="org.myname.MyClass"/>

You can embed it into an entity :

  | <!ENTITY mytask
  |  "<<taskdef name="myTask" classname="org.myname.MyClass"/>"
  | >

But to embed this entity into your 'build.xml' document you've got to
add a DOCTYPE section :

  | <?xml version="1.0" ?>
  |
  | <!DOCTYPE project
  | [
  | <!ENTITY mytask
  |	"<<taskdef name="myTask" classname="org.myname.MyClass"/>"
  | >
  | ]>

And if you want to share this entity between your project, put its
declaration into an xml 'chunk' file :

  +Full listing of the /tmp/taskdef.xch file
  | <!ENTITY mytask
  |	"<<taskdef name="myTask" classname="org.myname.MyClass"/>"

  +Beginning of your project file
  | <?xml version="1.0" ?>
  |
  | <!DOCTYPE project
  | [
  |   <!ENTITY % taskdefs SYSTEM "/tmp/taskdef.xch">
  |   %taskdef;
  | >
  | ]>
  | 
  | <project name="myProject">
  |   &mytask;
  |  ...

Notice that entities prefixes by a % are used ONLY inside a DOCTYPE
section, and the entities prefixed by an & are used outside (generally).

Hope this helps!

Bye,
Seb.

Mime
View raw message