我有两个目录,需要比较它们是否具有相同的文件。我成功地做到了以下几点:
<fileset dir="d:test" id="onlyinbar">
<not>
<present targetdir="A_DIR"/>
</not>
</fileset>
<echo>these files are only in bar : ${toString:onlyinbar}</echo>
<fileset dir="A_DIR" id="differentbarfoo">
<different targetdir="d:test" ignoreFileTimes="true"/>
</fileset>
<echo>these files are different in bar compared to foo : ${toString:differentbarfoo}</echo>
但是,如果这两个都是真的,我需要发布另一个任务。只要<condition>
标记似乎只支持文件间比较,我就看不出如何在<fileset>
标记中分配属性。我们将不胜感激。
我们需要避免任何第三方参与该解决方案。我的主要问题是标签的组合。我们知道我们的"测试",即文件集标签必须处于这种状态,但不知道如何。资源计数虽然缩短了问题:
<target name="export-report-icons" description="A description">
<condition property="test2" else="false">
<or>
<resourcecount when="gt" count="0" property="flength">
<fileset dir="d:test" id="onlyinbar">
<present targetdir="DIRs_A" present="srconly"/>
</fileset>
</resourcecount>
<resourcecount when="gt" count="0" property="flength">
<fileset dir="DIR_A" id="differentbarfoo">
<different targetdir="d:test" ignoreFileTimes="true"/>
</fileset>
</resourcecount>
</or>
</condition>
</target>
<target name="copyThis" depends="export-report-icons" if="${test2}">
....
</target>
因此,这将为两个文件集中的一个成功的情况设置OR,计数器包装文件集资源,使其可以在该条件下托管,并且该条件的属性为true或false,具体取决于ORed计数。如果${test2}为true,则执行"copy This"目标。请注意,如果您将id设置为test2,它将始终符合true的条件,因为在这种情况下,它会检查值是否存在。
<union>
集合运算符将多个集合中的资源分组为一个集合。
类似地,看看<intersect>
和<difference>
。
您提到了"if",我认为它指的是来自第三方Ant-Contrib库的<if>
任务。这里有一个例子,如果<union>
组合的文件集与任何文件匹配,就会产生回声:
<if>
<resourcecount when="gt" count="0">
<union id="Check">
<resources refid="onlyinbar"/>
<resources refid="differentbarfoo"/>
</union>
</resourcecount>
<then>
<echo>There are differences: ${toString:Check}</echo>
</then>
</if>