ant-user mailing list archives

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

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}"
subdir="${user.dir}"/>
<copy todir="{build.dir}/stuff>
  <fileset dir="${src.dir}>
    <include name="${relative.dir}/*"/>
  </fileset>
</copy>

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))
    {
      relativePath.append('.');
    }

    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);
    }

    setValue(relativePath.toString());

    super.execute();

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

Tim Gordon

Allustra Limited
1 Royal Exchange Avenue
London
EC3V 3LT
Tel 020 7464 4190
Tel 020 7464 4194
http://www.allustra.com/


Mime
View raw message