在 Ant 任务中,我设置了一个文件列表属性。例如
web/src/main/test/com/whatever/Ralph
business/src/main/test/com/whatever/Alice
web/src/main/test/com/whatever/Bob
我想从此列表中提取子目录集。在 bash 中我会:
$ cat filename | cut -d'/' -f1 | sort | uniq
business
web
有没有办法可以在 Ant 宏中做类似的事情?它也需要在 Windows 上运行,所以<exec>
不是一个选择。
您可以使用loadresource task http://ant.apache.org/manual/Tasks/loadresource.html with a 过滤链 http://ant.apache.org/manual/Types/filterchain.html。也许是这样的:
<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}" />
Result:
[echo] business
[echo] web
BUILD SUCCESSFUL
在旧版本的 Ant (loadfile带有过滤器链的任务。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)