Getting and using parent directory through ANT

Sumitk picture Sumitk · Aug 4, 2011 · Viewed 8.8k times · Source

I have a directory structure & build.xml like this

    /path-to-project/src/prj1
    /path-to-project/src/prj2

    /path-to-project/tests
    /path-to-project/tests/build.xml

I have to somehow get the path

    /path-to-project/

in my build.xml

My build.xml is like this

<project name="php-project-1" default="build" basedir=".">
  <property name="source" value="src"/>
    <target name="phploc" description="Generate phploc.csv">
      <exec executable="phploc">
        <arg value="--log-csv" />
        <arg value="${basedir}/build/logs/phploc.csv" />
        <arg path="${source}" />
      </exec>
    </target>
</project>

Here I somehow want to get value of ${source} as /path-to-project/src/ but I am not getting it with ${parent.dir}

Is it possible to get this path in the build.xml?

Answer

David Harkness picture David Harkness · Aug 4, 2011

You can use .. just as you do on the command-line to navigate to the parent directory.

<project name="php-project-1" default="build" basedir=".">
  <property name="root.dir" location=".."/>
  <property name="source" location="${root.dir}/src"/>
  ...
</project>

Update: Changed value to location as per martin's answer which you should accept.