mar*_*ton 24
一种可能性是使用first资源选择器.例如,要a.jar在目录下找到名为somewhere 的文件jars:
<first id="first">
<fileset dir="jars" includes="**/a.jar" />
</first>
<echo message="${toString:first}" />
Run Code Online (Sandbox Code Playgroud)
如果没有匹配的文件,则不会回显任何内容,否则您将获得第一个匹配的路径.
以下是选择第一个匹配文件的示例.逻辑如下:
该功能封装在macrodef中以实现可重用性.
<project default="test">
<target name="test">
<find dir="test" name="*" property="match.1"/>
<echo message="found: ${match.1}"/>
<find dir="test" name="*.html" property="match.2"/>
<echo message="found: ${match.2}"/>
</target>
<macrodef name="find">
<attribute name="dir"/>
<attribute name="name"/>
<attribute name="property"/>
<sequential>
<pathconvert property="@{property}.matches" pathsep="${line.separator}">
<fileset dir="@{dir}">
<include name="@{name}"/>
</fileset>
</pathconvert>
<loadresource property="@{property}">
<string value="${@{property}.matches}"/>
<filterchain>
<headfilter lines="1"/>
</filterchain>
</loadresource>
</sequential>
</macrodef>
</project>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13179 次 |
| 最近记录: |