ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Kelly <>
Subject Specifying repeated tasks: loops, sub-tasks, ...?
Date Mon, 04 Sep 2000 12:48:39 GMT
Has the list ever discussed making it easier to do repeated actions, or
specify many similar sub-tasks using loops or sub-tasks or some existing
feature I've missed?

One example: we run tests as part of our build process.  Some file
should not exist before a test, so we clean them up with delete:

    <!-- CLEAN TESTS
======================================================= -->
=================================================================== -->
    <target name="clean.test">
        <delete file="file1"/>
        <delete file="file2"/>

then run the tests.  However, I know of no good way to delete these
files before *every* test in ant.

I often run into this kind of thing, which I would normally handle via a
function or a loop in a conventional programming or scripting language.
I would be tempted to use ant tasks for this, but a target is executed
only once, and even if not, would require a lot of boilerplate to
specify that each test depends on this target.  In the case of my test
runs, it would be handy to be able to specify a sub-target to run before
and after my test, e.g.

<java java="my.test.class" setup="clean.test" teardown="clean.test"/>

Since I don't have this, I've written an extension of the Java task that
takes lists of files to delete, but I'm not satisfied with needing such
a specific solution.  Seems like there should be a way to do this kind
of thing at the xml level using <delete> and the other shell-like
features rather than in Java.

The JUnit task provides its own solution to this, but again in a very
specific way.  If I solved the problem in that way, I might write a new
task that ran a series of tests, with the same setup and tear-down for
        <delete file="file1"/>
        <delete file="file2"/>
    <test class="my.test.class"/>
    <test class="my.test.class2"/>
        <delete file="file3"/>

When I consider implementing this, I feel there's a general looping
construct missing in ant that would support junit and other things that
don't quite fall into the directory-based category.

The refid feature of recent months is also a nice feature in this vein,
but not exactly what I need.

Any thoughts appreciated.  I read the list sporadically, so apologies in
advance if I've missed previous discussions of such features.


Bill Kelly
Senior Software Engineer
Softwired AG * Technoparkstrasse 11 * CH-8005 Zurich * Switzerland * tel +41-1-4452370 * fax +41-1-4452372
*** Now available iBus//MessageServer Standard Edition 4.0 ***

View raw message