ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vincent Bergbauer" <>
Subject Re: Ant templates and more templates
Date Wed, 04 Oct 2000 21:05:07 GMT
Top-level data types can help alleviate the tedium without involving a complex template system
If path, argument, fileset, patternset can be defined under <project> and refered to
with refid, they
can be shared by multiple tasks. 
You can use ant-call with appropriate parameters refering to those ids.
It would still not be as compact from the user's point of view as templates, but it could
be an easy

Using your Jose's example with a slightly more complicated arg parameter:

<target name="generic">
  <java classname="XYZ" fork="${fork-prop}">
     <classpath refid="XYZpath" />
     <arg value="fix value" />
     <arg value="${arg-prop}" />

<arg id="arg-specific">
  <arg value="changing value" />
  <arg value="more changing value" />

<target name="specific">
  <ant-call target="generic">
    <param name="fork-prop" value="yes" />
    <param name="arg-prop" refid="arg-specific" />

> Jose Alberto Fernandez wrote:
 > Writing some build files for our projects here I have come across
> several situations in which I would have liked having some sort of
> template facilities for ANT.
 > (1) This first is for tasks. The <java> tasks that I use are quite
> quite monotonous: Call this class with this arguments, then call it
> again but just change the last arguments, etc, etc.
> One way to deal with this is to define my own task that extends <java>
> and that presets all that needs to be preset. But wouldn't it be nice
> to have a way to say tell ANT to do that without a need to 
> declare and maintain new classes?
 > Something like:
 > <javataskdef name="mytask" classname="XYZ" >
>   <classpath refid="XYZpath" />
>   <arg value="fix value" />
> </javataskdef>
 > Now I should be able to use:
 > <mytask fork="yes" >
>   <arg value="changing value" />
> </mytask>
> And this should be equivalent to doing:
 > <java classname="XYZ" fork="yes" >
>   <classpath refid="XYZpath" />
>   <arg value="fix value" />
>   <arg value="changing value" />
> </java>
> (2) A second situation where templates are interesting is when trying
> to interconnect tasks from on build file to another using the <ant>
> task. In this case one usially want to have access from the marter
> build file to the suordinate build files. Usually one would
> have <target>s like:
 > <target name="subtarget1"  depends="..." >
>   <ant target="subtarget1" antfile="subproject.xml" />
> </target>
 > Every time you add a task to the subproject, you need to 
> add an entry
> point in the project. A real syncronization problem. What I 
> would like is to be able to say:
 > <target template="sub*" key="subtarget" depends="..." >
>    <ant target="${subtarget} antfile="subproject.xml" />
> </target>
 > So with a call like:
 >     ant subtarget1 subtarget2
 > ANT will execute the above template twice, once for each  substitution
> and call the respective subtarget1 and subtarget2 in subproject.xml.
> Now notice that the template mechanism is more generic than just
> calling subprojects. It will allow for some nice things.
> I do not think that (2), in particular, can be solved with XSLT
> because you only know the substitution at execution time.
 > Does this looks as something interesting to have? I think 
> the approach
> is quite declarative in both cases, does anybody see a major problem
> with this?
 > Jose Alberto

Do You Yahoo!?
Get your free address at

View raw message