Ant zipfileset包含目录中的文件,但如果它们在另一个目录中重复,则不会

问题描述 投票:0回答:1

我正在研究一个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中的重复项。

基于以上示例,我可以接受以下任一解决方案:

  1. PARENT-DIR / foo /包含a,b,c,d,e,f,g,x,y,q,r,每个孩子的/ foo /是空的。
  2. PARENT-DIR / foo /包含a,b,c,d,e,f,g,childDirA / foo /仅包含x,y和childDirB / foo /仅包含q,r。

其他一些可能有帮助的信息:

  • 子目录的数量很少(<20)并且应该是稳定的,因此可以单独对它们进行操作。
  • 每个/ foo /中的文件数量很大(~100)并且可能会发生变化,因此逐个列出这些文件并不是一个好的解决方案。

是否有一些zipfileset模式和选择器的组合可以实现这一目标?

ant zipfile
1个回答
0
投票

这真的是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>
© www.soinside.com 2019 - 2024. All rights reserved.