ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Conor MacNeill <co...@cortexebusiness.com.au>
Subject override
Date Thu, 31 Jul 2003 12:07:59 GMT
I'd like to take a slightly different angle on the <import> issue by getting 
some thoughts on this little experimental task I wrote. I haven't cleaned it 
up at all (lots of unused imports, inner classes etc). Anyway it lets you 
override any target in the build. e.g. This build file

<project name="override" default="test">

  <taskdef name="override" 
classname="org.apache.tools.ant.taskdefs.Override"/>
  <taskdef name="super" 
classname="org.apache.tools.ant.taskdefs.Override$Super"/>

  <override target="test">
    <echo message="pre"/>
    <super/>
    <echo message="post"/>
  </override>

  <override target="test">
    <echo message="pre2"/>
    <super/>
    <echo message="post2"/>
  </override>

  <target name="test">
    <echo message="test"/>
  </target>

</project>

produces the following output
Buildfile: build.xml

test:
     [echo] pre2
     [echo] pre
     [echo] test
     [echo] post
     [echo] post2

BUILD SUCCESSFUL

:-)

I think with a renaming <import> task this would let you override any part of 
the build easily.

BTW, note that simple renaming of targets is not enough. Any use of a target 
name needs to be updated too (e.g. <antcall>). Can be done (at time of use) 
but may require tasks knowing their import prefix. The import task will need 
this to do cascade renaming.

Anyway, just thought I'd throw it out there. Override might even be useful in 
an entity includes approach.

Comments?

Conor

Mime
View raw message