Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting and using parent directory through ANT

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?

like image 264
Sumitk Avatar asked Dec 04 '22 20:12

Sumitk


2 Answers

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.

like image 113
David Harkness Avatar answered Dec 07 '22 10:12

David Harkness


You should use the location attribute rather than value to set the source property:

<property name="source" location="src"/>

Ant will then set the property to the absolute path of the given location. If the the location looks like a relative path, the absolute path is calculated relative to basedir. The property task has other attributes you can use to tune this further.

To get the parent directory of your basedir, you can similarly use:

<property name="parent.dir" location=".." />

(at least on a unix machine, not tested on windows.)

like image 33
martin clayton Avatar answered Dec 07 '22 10:12

martin clayton