我正在研究一个ant目标,它将一些目标和文件作为输入,由一些上游目标生成,并输出一个zip文件。
因此,我的目标看起来有点像这样:
<target name="package-the-zip" depends="upstream-thing1, upstream-thing2">
<!-- a little bit of tweaking happens here -->
<zip destfile="myPackage.zip">
<zipfileset dir="PARENT-DIR" prefix="myParent">
<!-- a handful of include and exclude tags are here -->
</zipfileset>
</zip>
</target>
截至目前,PARENT-DIR / foo /包含少量文件 - 例如,将它们称为a,b,c,d,e,f和g。除此之外,PARENT-DIR / childDirA / foo /包含a,b,e,g,x,y和PARENT-DIR / childDirB / foo /包含b,c,e,f,q,r等等几个孩子。换句话说,每个孩子的/ foo /包含父母的一些重复,以及一个或两个独特的东西。我想消除生成的zip中的重复项。
基于以上示例,我可以接受以下任一解决方案:
其他一些可能有帮助的信息:
是否有一些zipfileset模式和选择器的组合可以实现这一目标?
这真的是Saurabh14292的答案,不是我的。他似乎已经选择不将他的评论转换为答案,因此CW。
解决方案是在压缩之前将子文件复制到父文件中。复制会添加唯一文件并忽略重复项。然后,在压缩时,排除子文件。问题中的片段变为:
<target name="package-the-zip" depends="upstream-thing1, upstream-thing2">
<!-- a little bit of tweaking happens here -->
<copy todir="PARENT-DIR/foo">
<fileset dir="PARENT-DIR/childDirA/foo">
<!-- include as needed -->
</fileset>
</copy>
<!-- repeat copy for each child as needed -->
<zip destfile="myPackage.zip">
<zipfileset dir="PARENT-DIR" prefix="myParent">
<!-- a handful of include and exclude tags are here -->
<exclude name="PARENT-DIR/childDir*/foo" />
</zipfileset>
</zip>
</target>