> 
> Peter Donald (have to use full name because this list is 
> soooo full ;) , any
> hint on how to include a basic templating mechanism with current Ant?
> I recall you favor templating, and I'm sure you can help us 
> (I'm interested
> too) and give us some advice.
> 

Just to briefly describe how I've implemented my templates: I have a
template buildfile (regular Ant buildfile) with some common (or default)
targets, paths, properties, etc.  Then for every "real" project I merge
(with XSLT) this template with another customization (also an Ant buildfile)
which overrides definitions in the template.  This works like a simple
inheritance mechanism.  So I could have a template like:

<project name="template" default="compile">

 <property name="source-dir" value="src"/>
 <property name="build-dir" value="build"/>

 <target name="init"/>
 <target name="compile" depends="init">
  <javac srcdir="${source-dir}" destdir="${build-dir}"/>
 </target>

</project>

and a customization for a project (notice the additional <super/> in target
compile):

<project name="custom">

 <property name="build-dir" value="classes"/>

 <target name="idlj">
  <exec/>
 </target>

 <target name="compile" depends="init,idlj">
  <super/>
 </target>

</project>

which would be merged into:

<project name="custom" default="compile">

 <property name="source-dir" value="src"/>
 <property name="build-dir" value="classes"/>

 <target name="init"/>

 <target name="idlj">
  <exec/>
 </target>

 <target name="compile" depends="init,idlj">
  <javac srcdir="${source-dir}" destdir="${build-dir}"/>
 </target>

</project>

I found this to work quite nicely.  I added the <super> target because I
wanted as few changes as possible in the template to cause manual changes to
be made to the customization.

--
knut

Reply via email to