Ant Datatype之selector

        selector(选择器)对文件集(或其他选择器容器)中的每个文件进行测试,窗口<and>、<or>、<not>、<none>、<selector>和<majority>可以合并到选择器容器内,从而可以进行分组和某些逻辑操作。

        选择器容器列表:

<filename> 基于模式匹配文件,工作方式类似于模式集的<inclucde>或<exclude>元素
<depth> 基于目录深度选择文件
<size> 按照小于、等于、大于某指定值来选择文件
<date> 根据最终修改时间早于、晚于或等于某一指定时间来选择文件(或目录)
<present> 选择存在于某个目录树中的文件
<depend> 选择比在其他目录树中选择指定文件更新的版本
<contains> 选择包含指定字符串的文件
<containsregexp> 选择包含与指定正则表达式匹配的字符的文件
<different> 选择某一目录不包含的文件
<type> 根据文件或目录的类型进行选择
<modified> 计算文件的checksum,选择检查或发生变化的文件
<signedselector> 选择已签名的JAR文件,可选的包括签名者姓名
<scriptselector> 嵌入一段脚本语言来描述选择规则

 

简单测试:

<?xml version="1.0" encoding="UTF-8"?>
<project name="datatype_selector" default="copyother">
	
	<property name="copy.fromdir" location="src"/>
	<property name="copy.todir" location="tosrc"/>

	<fileset id="copy.pattern" dir="${copy.fromdir}">
		<include name="**/*.txt"/>
		<include name="**/*.java"/>
	</fileset>

	<fileset id="copyother.selector" dir="${copy.fromdir}">
		<or>
			<filename name="**/新*" />
			<contains text="新"/>
		</or>
	</fileset>

	<target name="copy" depends="clean">
		<copy todir="${copy.todir}">
			<fileset refid="copy.pattern" />
		</copy>
	</target>

	<target name="copyother" depends="copy">
		<copy todir="${copy.todir}">
			<fileset refid="copyother.selector"/>
		</copy>
	</target>

	<target name="clean">
		<delete dir="${copy.todir}"/>
	</target>
	
</project>

 输出:

E:\antspace\datatype>ant
Buildfile: E:\antspace\datatype\build.xml

clean:
   [delete] Deleting directory E:\antspace\datatype\tosrc

copy:
     [copy] Copying 4 files to E:\antspace\datatype\tosrc

copyother:
     [copy] Copying 2 files to E:\antspace\datatype\tosrc

BUILD SUCCESSFUL
Total time: 0 seconds

 

你可能感兴趣的:(selector)