本文介绍了蚂蚁当量切割|排序|优衣库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ant任务中,我设置了一个属性,该属性是文件列表.例如

In an Ant task I set a property which is a list of files. e.g.

web/src/main/test/com/whatever/Ralph
business/src/main/test/com/whatever/Alice
web/src/main/test/com/whatever/Bob

我想从此列表中提取子目录集.在bash中,我会:

I would like to extract the set of subdirectories from this list. In bash I'd:

$ cat filename | cut -d'/' -f1 | sort | uniq
business
web

有没有办法可以在Ant宏中执行类似的操作?它也需要在Windows上运行,因此<exec>不是一个选择.

Is there a way I can do something similar in an Ant macro? It needs to run on Windows too, so <exec> is not an option.

推荐答案

您可以使用 loadresource任务,其中带有过滤链.可能是这样的:

You can do this using a loadresource task with a filterchain. Something like this perhaps:

<property name="list.of.files">
web/src/main/test/com/whatever/Ralph
business/src/main/test/com/whatever/Alice
web/src/main/test/com/whatever/Bob
</property>

<loadresource property="dirs">
    <string value="${list.of.files}" />
    <filterchain>
        <replaceregex pattern="/.*" replace="" />
        <sortfilter />
        <uniqfilter />
    </filterchain>
</loadresource>

<echo message="${dirs}" />

结果:

 [echo] business
 [echo] web

BUILD SUCCESSFUL

在旧版的Ant(< 1.7)中,您可以通过将属性写到文件中,然后将loadfile任务与filterchain一起使用来进行相同的操作.

In older versions of Ant (<1.7) you could do the same by writing the property out to a file, then using a loadfile task with filterchain.

这篇关于蚂蚁当量切割|排序|优衣库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 19:21