ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Gordon" <tim.gor...@allustra.com>
Subject Import - bug or feature?
Date Fri, 27 Jun 2003 12:53:37 GMT
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


Mime
View raw message