转换一个Ant文件集到多个应用ARGS [英] Converting an Ant fileset to multiple apply args

查看:131
本文介绍了转换一个Ant文件集到多个应用ARGS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文件:

dir/foo.txt
dir/bar.txt
dir/foobar.txt

在一个Ant 适用的任务,我想通过文件的列表作为参数:

In an Ant apply task, I want to pass the list of files as arguments:

<target name="atask">
    <apply executable="${cmd}" parallel="false" verbose="true">
        <arg value="-in"/>
        <srcfile/>
        <arg value="dir/foo.txt"/>
        <arg value="dir/bar.txt"/>
        <arg value="dir/foobar.txt"/>

        <fileset dir="${list.dir}" includes="*.list"/>
    </apply>
</target>

这工作得很好,但如果我要挑文件的列表动态,用文件集的内容:

This works fine, but what if I want to pick the list of files dynamically, using a fileset:

<fileset dir="dir" includes="*.txt"/>

我如何转换这个文件集中 ARG 元素 - 每个文件?是这样的:

How can I convert this fileset to arg elements - one per file? Something like:

<arg>
    <fileset dir="dir" includes="*.txt"/>
</arg>

而不是

<arg value="dir/foo.txt"/>
<arg value="dir/bar.txt"/>
<arg value="dir/foobar.txt"/>

(这个例子不工作,因为 ARG 不支持的文件集

(This example doesn't work because arg doesn't support fileset)

推荐答案

下面的说明使用 pathconvert 任务。

的转换路径使用传递给可执行文件&LT; ARG线/方式&gt;

The converted path is passed to the executable using <arg line />.

此不承担任何空间在你的 *。txt的文件的路径。

This assumes no spaces in the paths of your *.txt files.

<target name="atask">
    <fileset dir="dir" id="myTxts">
        <include name="*.txt" />
    </fileset>
    <pathconvert property="cmdTxts" refid="myTxts" pathsep=" " />

    <apply executable="${cmd}" parallel="false" verbose="true">
        <arg value="-in" />
        <srcfile />
        <arg line="${cmdTxts}" />

        <fileset dir="${list.dir}" includes="*.list" />
    </apply>
</target>

如果您可能会遇到这样的空间应该做的:同上,但变化(希望这明显系):

If you might encounter spaces this should do: as above, but change (hopefully obvious which lines) to:

    <pathconvert property="cmdTxts" refid="myTxts" pathsep="' '" />

        <arg line="'${cmdTxts}'"/>

这篇关于转换一个Ant文件集到多个应用ARGS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆