You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Tim Gordon <ti...@allustra.com> on 2003/06/27 14:53:37 UTC
Import - bug or feature?
I know that the comments around ImportTask recommend that absolute file
paths be used, but I thought that relative file paths in imported files
would be defined relative to the base dir of the project that does the
import, which is what seems to happen in the simple case where one ANT file
imports another as a library. However, if an import is shared between two
different ANT files which call each other, looking at how <import> is
behaving...
Lets say I've got two ant files,
/basedir/callerdir/caller.xml and
/basedir/calleedir/callee.xml,
both of which contain
<import file="../libdir/lib.xml"/>
Inside lib.xml we've got a stock-implementation of a target which involves
paths:
<project name="lib">
<target name="projectClassPath">
<path id="project.class.path">
<pathelement location="../build"/>
<fileset dir="../lib">
<include name="**/*.jar"/>
<include name="**/*.zip"/>
</fileset>
</path>
<property name="project.class.path" refid="project.class.path"/>
<echo>${project.class.path}</echo>
</target>
</project>
Now ANT first encounters the <import file="lib.xml"/> in caller.xml. If we
invoke
ant -f /basedir/callerdir/caller.xml projectClassPath
Then our paths are defined relative to the basedir of caller.xml, which is
what you'd expect.
However, if caller.xml has the following snippet:
<target name="call">
<ant antfile="../../calleedir/callee.xml" target="projectClassPath"/>
</target>
Then when caller.xml invokes a target in callee.xml
ant -f /basedir/callerdir/caller.xml call
we get "Duplicated project name in import. Project lib defined first in
/basedir/callerdir/caller.xml and again in /basedir/calleedir/callee.xml".
There is more to it than just the warning - when the echo occurs the paths
are defined relative to caller.xml, not callee.xml, as we'd expect.
If I <ant> one ant file from another, I would have thought it's symantically
like invoking another JVM. What's actaully happenend here is that it looks
like callee.xml is invoking targets which have really been defined in
caller.xml.
If it's a bug I'll look into a potential fix. Unless it's supposed to work
that way for some reason...
Tim Gordon
Allustra Limited
1 Royal Exchange Avenue
London
EC3V 3LT
Tel 020 7464 4190
Tel 020 7464 4194
http://www.allustra.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Import - bug or feature?
Posted by Nicola Ken Barozzi <ni...@apache.org>.
Tim Gordon wrote, On 27/06/2003 14.53:
...
> If I <ant> one ant file from another, I would have thought it's symantically
> like invoking another JVM. What's actaully happenend here is that it looks
> like callee.xml is invoking targets which have really been defined in
> caller.xml.
>
> If it's a bug I'll look into a potential fix. Unless it's supposed to work
> that way for some reason...
AFAIK it's a bug. As you say, an <ant> invocation should completely wrap
the environment, unless you say it should inherit stuff... hmmm... but
it inherits properties, not tasks.
Probably the system that checks for duplicate imports is not scoped.
Which brings us back to the initial "what is the basedir of the imported
antfile" question.
What you show here is that now it fails to live up to the current rule,
that the basedit is that of the antfile that has imported the library.
See if you can find a fix, it would be nice :-)
--
Nicola Ken Barozzi nicolaken@apache.org
- verba volant, scripta manent -
(discussions get forgotten, just code remains)
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org