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?
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.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With