ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Gordon" <>
Subject Converting ${user.dir} into a path relative to ${some.dir}
Date Wed, 02 Apr 2003 09:31:13 GMT

I'm invoking ANT from a subdirectory, getting at the build.xml using
ant -find.

It would be very useful if I could create a FileSet which selects the files
that are in my directory. This would allow me to execute something like

<relativepathproperty name="relative.dir" basedir="${src.dir}"
<copy todir="{build.dir}/stuff>
  <fileset dir="${src.dir}>
    <include name="${relative.dir}/*"/>

So if ${user.dir} is currently
c:/sandboxes/dev/project/src/com/mydomain/app/client, the build.xml is
located in c:/sandboxes/dev/project (basedir = '.') and ${src.dir} is set to
src, ${relative.dir} should end up as com/mydomain/app/client.

I tried just putting ${user.dir} in place of ${relative.dir} and it doesn't
work - not sure why.

I wrote an implementation of RelativePathProperty for ANT 1.4.1 - it's
similar to dirname in 1.5.2 - here's it's execute() method - m_basedir and
m_subbdir are set as File objects:

    StringBuffer relativePath = new StringBuffer();
    if (m_basedir.equals(m_subdir))

    File search = m_subdir;
    while (!m_basedir.equals(search) && search != null)
      if (relativePath.length() > 0)
        relativePath.insert(0, File.separatorChar);
      relativePath.insert(0, search.getName());
      search = search.getParentFile();

    if (search == null)
      throw new BuildException(m_subdir.toString() + " is not a subdirectory
of " + m_basedir);



I tried using dirname, but it didn't work for me.

Tim Gordon

Allustra Limited
1 Royal Exchange Avenue
Tel 020 7464 4190
Tel 020 7464 4194

View raw message