开发者

Getting and using parent directory through ANT

开发者 https://www.devze.com 2023-03-26 11:43 出处:网络
I have a directory structure & build.xml like this /path-to-project/src/prj1 /path-to-project/src/prj2

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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消