ant的fileset元素

FileSet是一组文件,这些文件可以在基目录树下找到且与指定的PatternSets和Selectors匹配。FileSet的结构类似于如下:

1)<fileset dir="${server.src}">
<patternset/>
<Selector/>
</fileset>

 

2)patternset一般用作FileSet的子元素,用来帮助筛选文件。可以包含如下的子元素:include,exclude,includes,excludes,includesfile,excludesfile.

FileSet 中隐式地包含了一个patternset元素,所以可以在FileSet中直接包含patterset中的元素,例如<include>, <includesfile>, <exclude> and <excludesfile> 。

如下的patternset包含std子目录下的java文件,如果professional定义的话还包含prof下的java文件,但是不包含名字中包含Test的文件。
<patternset id="sources">
<include name="std/**/*.java"/>
<include name="prof/**/*.java" if="professional"/>
<exclude name="**/*Test*"/>
</patternset>

 

3)Selector一般用作FileSet的子元素,用来帮助筛选文件。

常用的核心的selector有:
<contains> - 用来选择包含指定字符串的文件
<date> - 用来选择在某个特定时间前或后修改的文件
<depend> - Select files that have been modified more recently than equivalent files elsewhere
<depth> - 用来选择指定目录深度的文件
<different> - Select files that are different from those elsewhere
<filename> - 用来选择文件名匹配特定模式的文件。等价于include和exclude的patternset。
<present> - 用来选择在某个位置存在或不存在的文件
<containsregexp> - 用来选择匹配指定正则表达式的文件
<size> - 用来选择比指定size大或小的文件
<type> - Select files that are either regular files or directories.
<modified> - Select files if the return value of the configured algorithm is different from that stored in a cache.
<signedselector> - Select files if they are signed, and optionally if they have a signature of a certain name.
<scriptselector> - Use a BSF or JSR 223 scripting language to create your own selector
<readable> - 选择有readable属性的文件
<writable> - 选择有writable属性的文件

例如选择包含script的所有的html文件
<fileset dir="${doc.path}" includes="**/*.html">
<contains text="script" casesensitive="no"/>
</fileset>

例如选择所有在January1,2001前修改的JAR文件
<fileset dir="${jar.path}" includes="**/*.jar">
<date datetime="01/01/2001 12:00 AM" when="before"/>
</fileset>

例如选择所有满足正则表达式的txt文件
<fileset dir="${doc.path}" includes="*.txt">
<containsregexp expression="[4-6]\.[0-9]"/>
</fileset>

如下的selector与patternset等价:
<fileset dir="${server.src}" casesensitive="yes">
<filename name="**/*.java"/>
<not>
<filename name="**/*Test*"/>
</not>
</fileset>
等价于
<fileset dir="${server.src}" casesensitive="yes">
<filename name="**/*.java"/>
<filename name="**/*Test*" negate="true"/>
</fileset>
等价于
<fileset dir="${server.src}" casesensitive="yes">
<include name="**/*.java"/>
<exclude name="**/*Test*"/>
</fileset>


selector容器可以包含其他的selector,常用的selector容器有:
<and>
<contains>
<custom>
<date>
<depend>
<depth>
<filename>
<majority>
<none>
<not>
<or>
<present>
<selector>
<size>


例如选择比4096bytes大且从上个millenium没有更新的JAR文件
<fileset dir="${dist}" includes="**/*.jar">
<and>
<size value="4" units="Ki" when="more"/>
<date datetime="01/01/2001 12:00 AM" when="before"/>
</and>
</fileset>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值