Bug 33333 - Enable <import> task within targets
Summary: Enable <import> task within targets
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.6.2
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Ant Notifications List
Depends on:
Reported: 2005-02-01 18:06 UTC by Austin Hastings
Modified: 2008-11-24 03:58 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Austin Hastings 2005-02-01 18:06:10 UTC
I'm generating a buildfile fragment dynamically, and my primary buildfile needs
to  do dependency checking on this fragment to determine if a new fragment
should be generated.

The operating scenarios are:

1. No fragment exists.

2. Fragment exists but is out-of-date.

3. Fragment exists and is fine.

Currently, I am using a HUUUUUUUUUUGE HAAAAAAACK involving <exec> to do 'black
box' recursion: 

A. <available> & <property> to provide a default (empty) fragment (I don't want
to use <import optional="true"/> because it ISN'T optional, just missing, in
case 1.)

B. Target-based checking and regeneration of the fragment in the init step of
all the primary targets.

C. <exec> ant with overridden properties to force the inclusion of the
known-good fragment.

All this hackery and cruft would go away if my init step could check the
fragment, maybe regenerate it, and then import it.
Comment 1 Nicola Ken Barozzi 2005-02-01 18:18:34 UTC
Try doing it outside of the targets. It used to work, I used it in Centipede.
Comment 2 Austin Hastings 2005-02-01 19:35:11 UTC
I don't understand what you are suggesting. Can you elaborate a bit?
Comment 3 Phil Weighill-Smith 2005-02-01 20:14:05 UTC
We actually use a task to do what you've suggested thus:

<project ...>
    <generatescript file="xyz.xml".../>

    <import file="xyz.xml"/>


You can now put arbitrary tasks in Ant scripts in the "default" target (i.e. 
outside any explicit target) which will be processed in file order.
Comment 4 Austin Hastings 2005-02-02 18:36:18 UTC
I'm trying the <generate> at toplevel approach, and it shows some promising
results. Thanks.

Now, I think this may be a separate issue, but:

I have a file that I <import> containing a series of macrodefs, including my
<generate> macrodef.

If I add a <target> to that file, before the <generate> macrodef, when I run ant
and try to <generate> from the top level, it complains that the task is not defined.

Removing the <target> def to after the <generate> macrodef fixes this, as does
removing the <target> back to the several importing files (but I don't want
multiple copies of the target :-(

Has anyone seen this before?
Comment 5 Peter Reilly 2005-02-02 19:02:03 UTC
>Removing the <target> def to after the <generate> macrodef fixes this, as does
>removing the <target> back to the several importing files (but I don't want
>multiple copies of the target :-(

This is due to bug 31487 (fixed in cvs for ant 1.6.3)

* Execution of top level tasks in imported files get delayed by targets.
  Bugzilla report 31487.