To aid with the generic-ism of the brother.xml and sister.xml files, you can
use the XML built-in ENTITY trick:
-----
<!DOCTYPE project [
<!ENTITY default-clean SYSTEM "file:../common-ant/clean.inc.xml">
]>
<project ...>
<!-- if you need your own specialized clean task, then override the
default by not including it here -->
&default-clean;
...
</project>
----
clean.inc.xml would contain something like:
----
<target name="clean">
<delete dir="${basedir}/${project-directory}/exports" />
...
</target>
----
-Matt Albrecht
Try something new.
> -----Original Message-----
> From: Dominique Devienne [mailto:[EMAIL PROTECTED]
> Sent: Thursday, May 02, 2002 10:16 AM
> To: 'Ant Developers List'
> Subject: RE: Ant <project> extension, templatized build files
>
>
> Interesting, and clever. You're example is missing targets in
> bother and
> sister to call down on the template to do the 'clean' target
> for example.
> You defined clean in parent.xml, but call 'build' sub-targets
> for it... If
> you did call 'clean' (as I believe you should), it would fail
> as shown since
> there's no 'clean' target in brother or sister.xml.
> Basically, it means
> every target you want to be able to call in parent.xml has to
> be present in
> all siblings build.xml, and call done on the template it's
> using. May not be
> a problem for you, but is a little constraining. Like I said though,
> interesting! Thanks, --DD
>
> -----Original Message-----
> From: Chad Loder [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, May 01, 2002 10:55 PM
> To: Ant Developers List
> Subject: Re: Ant <project> extension, templatized build files
>
> Peter wrote:
> > I would recomend you have a look at the existing projects
> as they are
> more
> > likely to be imediately usable by you.
>
> I am personally turned off by what I've seen of Maven and
> (to a lesser extent) Centipide. Ant is attractive because
> it aims only to be a great, NEUTRAL build tool. Using ant by
> itself implies no particular project management/structuring
> ideology (i.e. "eXtreme programming", "The Apache way (tm)"
> or whatever the buzzword of the year is). I don't want anyone
> telling me how to structure my projects, how to do my unit testing,
> etc. Rather than using Maven and struggling to turn all the
> unwanted stuff off, I would like to use ant and build what's
> necessary from scratch.
>
> To sum it up, I don't think one needs all the Maven baggage
> to implement templatized buildfiles. Kudos to the Maven people
> and all...it's just not how I do things.
>
> Therefore let me re-state my problem in the simplest way I
> can. "Given a set of subprojects whose buildfiles share a high
> degree of redundancy, how do I reduce this redundancy by factoring
> the redundant portions into a single buildfile, while retaining the
> flexibility to override the definitions of particular targets."
>
> Having thus restated my problem, I sat down and played with
> ant 1.4, coming up with a solution that does what I need,
> without requiring any ant changes whatsoever.
>
> I describe my solution below -- I'd like to know what people
> think of it. Peter, in particular, I think you and I may be trying to
> solve different problems (my needs being somewhat simpler).
>
> I'd like to get comments on this proposed solution (improvements?
> possible complications or limitations down the road for large
> projects?).
>
> THE SOLUTION
> ------------
>
> Assume there is one main project "parent" which consists of
> two similar "Sibling"-style subprojects, "brother" and "sister".
> The steps required to build a Sibling are always the same,
> subject to minor differences subproject-specific differences
> (compile flags, pre-build and post-build steps, etc.).
>
> If one had other kinds of subprojects (e.g., in addition to
> Siblings, one wanted to build WinExe's or WinDLLs, etc.),
> one could make a template-winexe.xml, template-windll.xml,
> and so on.
>
> I created 4 build files:
>
> build.xml: the parent build file
> brother.xml: the build file for the "brother" subproject
> sister.xml: the build file for the "sister" subproject
> template-sibling.xml: the "Sibling" template
>
> -----------------------------------------------------------------
> <!-- build.xml, the main parent build file -->
> <project name="parent" default="build">
> <!-- execute the given ${target} on all sub projects -->
> <target name="children">
> <ant antfile="brother.xml" target="${subtarget}"/>
> <ant antfile="sister.xml" target="${subtarget}"/>
> </target>
>
> <!-- distribute the "build" command to all children -->
> <target name="build">
> <antcall target="children">
> <param name="subtarget" value="build"/>
> </antcall>
> </target>
>
> <!-- distribute the "build" command to all children -->
> <target name="clean">
> <antcall target="children">
> <param name="subtarget" value="build"/>
> </antcall>
> </target>
> </project>
>
>
> -----------------------------------------------------------------
> <!-- brother.xml: build file for the "brother" sibling subproject -->
> <project name="brother">
> <property name="project-compile-flags" value="/BROTHER"/>
>
> <target name="build">
> <ant antfile="template-sibling.xml">
> <property name="project-pre-build-targets"
> value="brother-pre-build"/>
>
> <property name="project-pre-build-file"
> value="${ant.file}"/>
>
> <!-- the brother requires no special post-build
> processing -->
> </ant>
> </target>
>
> <target name="brother-pre-build">
> <echo>Executing the brother's pre-build targets</echo>
> </target>
>
> <target name="brother-post-build">
> <echo>Executing the brother's post-build targets</echo>
> </target>
> </project>
>
>
> -----------------------------------------------------------------
> <!-- sister.xml: build file for the "sister" sibling subproject -->
> <project name="sister">
> <target name="build">
> <ant antfile="template-sibling.xml">
> <property name="project-pre-build-targets"
> value="sister-pre-build"/>
> <property name="project-pre-build-file"
> value="${ant.file}"/>
> <property name="project-post-build-targets"
> value="sister-post-build"/>
> <property name="project-post-build-file"
> value="${ant.file}"/>
> </ant>
> </target>
>
> <target name="sister-pre-build">
> <echo>Executing the sister's pre-build targets</echo>
> </target>
>
> <target name="sister-post-build">
> <echo>Executing the sister's post-build targets</echo>
> </target>
> </project>
>
> -----------------------------------------------------------------
> <project name="template-sibling" default="build">
>
> <!--
> These subproject-specific properties can be overridden by
> subprojects. If not overridden, they default to empty.
> -->
> <property name="project-compile-flags" value=""/>
> <property name="project-pre-build-file" value="${ant.file}"/>
> <property name="project-pre-build-targets" value="do-nothing"/>
> <property name="project-post-build-file" value="${ant.file}"/>
> <property name="project-post-build-targets" value="do-nothing"/>
>
> <!--
> These properties should NOT be overridden. The
> subproject-specific
> flags get appended to them.
> -->
> <property name="compile-flags" value="/A /B /C
> ${project-compile-flags}"/>
>
> <target name="pre-build" if="project-pre-build-targets">
> <echo>Doing
> pre-build.
> ${project-pre-build-file}:${project-pre-build-targets}</echo>
> <ant antfile="${project-pre-build-file}"
> target="${project-pre-build-targets}"/>
> </target>
>
> <target name="build" depends="pre-build">
> <echo>Doing template build</echo>
> <echo>Compile flags is ${compile-flags}</echo>
> <antcall target="post-build"/>
> </target>
>
> <target name="post-build" if="project-post-build-targets">
> <echo>Doing
> post-build.
> ${project-post-build-file}:${project-post-build-targets}</echo>
> <ant antfile="${project-post-build-file}"
> target="${project-post-build-targets}"/>
> </target>
>
> <target name="do-nothing">
> <!-- no op -->
> </target>
>
> </project>
> -----------------------------------------------------------------
>
>
> This gives me the desired results and *almost* all the flexibility
> I need. Watch:
>
> $ ant
>
> Buildfile: build.xml
>
> build:
>
> children:
>
> build:
>
> pre-build:
> [echo] Doing pre-build.
> E:\r7\ant-test\brother.xml:brother-pre-build
>
> brother-pre-build:
> [echo] Executing the brother's pre-build targets
>
> build:
> [echo] Doing template build
> [echo] Compile flags is /A /B /C /BROTHER
>
> post-build:
> [echo] Doing post-build.
> E:\r7\ant-test\template-sibling.xml:do-nothing
>
> do-nothing:
>
> build:
>
> pre-build:
> [echo] Doing pre-build.
> E:\r7\ant-test\sister.xml:sister-pre-build
>
> sister-pre-build:
> [echo] Executing the sister's pre-build targets
>
> build:
> [echo] Doing template build
> [echo] Compile flags is /A /B /C
>
> post-build:
> [echo] Doing post-build.
> E:\r7\ant-test\sister.xml:sister-post-build
>
> sister-post-build:
> [echo] Executing the sister's post-build targets
>
> BUILD SUCCESSFUL
> Total time: 1 second
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>