ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <>
Subject Re: [Q:] Writing a simple Ant task?
Date Wed, 25 Sep 2002 17:59:10 GMT
David M. Smith wrote:
> Hi,
> I wanted to write a task along the following lines
> <mytask srcfile="" destfile="">
>         <param find="Key1" replaceWith="Value1"/>
>         <param find="Key2" replaceWith="Value2"/>
>         <param find="Keyn" replaceWith="Valuen"/>
> </mytask>

> However, I would still like to understand how I would write this task.

Welcome to the world of Ant task writers! :)

> Looking at the Ant source code, it seems generic enough to be able to
> handle arbitary nested elements, but what methods must I put on my task
> class to support this? I am thinking createParam(), setParam() and
> getParam().
> Do I need to create a ant.types.Param class?

You could implement any class that you wanted that had a setFind(...) 
and a setReplaceWith(...) methods (the types of these is quite flexible, 
but lets just say String arguments for now.

Then your main task class would either implement createParam, addParam, 
or addConfiguredParam.  The simplest case is for your class that we 
defined above to have a no-arg constructor and use the addParam() method.

Sounds a bit complex, but its not too difficult once you know some of 
the basic rules/patterns that Ant's introspection mechanism uses.


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message