0

我有以下 Ant 目标,它从特定的 .ZIP 存档中提取内容:

<!-- UNPACK-MATH -->
<target name="unpack-math" depends="init-contrib">
  <!-- NOTE: the 'unzip' task doesn't fail when it cannot extract over read-only files; however, 'copy' with a 'zipfileset' does. -->
  <first id="math.archive">
    <fileset dir="${builddir}" includes="MATH_MF*.zip" />
  </first>
  <if>
    <length string="${toString:math.archive}" when="greater" length="0" />
    <then>
      <copy todir="${basedir}">
        <zipfileset src="${toString:math.archive}" />
      </copy>
    </then>
    <else>
      <echo message="No math to unpack." />
    </else>
  </if>
</target>

我现在想做的是“清理”提取的文件。但是,以下方法不起作用:

<!-- CLEAN-MATH -->
<target name="clean-math" depends="init-contrib">
  <first id="math.archive">
    <fileset dir="${builddir}" includes="MATH_MF*.zip" />
  </first>
  <if>
    <length string="${toString:math.archive}" when="greater" length="0" />
    <then>
      <delete>
        <zipfileset src="${toString:math.archive}" />
      </delete>
    </then>
    <else>
      <echo message="No math to clean." />
    </else>
  </if>
</target>

我得到以下堆栈跟踪:

BUILD FAILED
D:\Development\MForce\Games\gamebuild.xml:214: java.lang.ClassCastException: class org.apache.tools.ant.types.resources.ZipResource doesn't provide files
        at org.apache.tools.ant.types.resources.comparators.FileSystem.resourceCompare(FileSystem.java:43)
...

有任何想法吗?

4

1 回答 1

0

此解决方案似乎有效,但需要先解压缩 .ZIP 存档(其中列出了您要作为其他根目录删除的文件),我希望避免这种情况:

<!-- CLEAN-MATH -->
<target name="clean-math" depends="init-contrib">
  <first id="math.archive">
    <fileset dir="${builddir}" includes="MATH_MF*.zip" />
  </first>
  <if>
    <length string="${toString:math.archive}" when="greater" length="0" />
    <then>
      <unzip dest="${builddir}/tmp" src="${toString:math.archive}"/>
       <delete>
        <fileset dir="${basedir}" includes="**/*">
          <present present="both" targetdir="${builddir}/tmp"/>
        </fileset>
      </delete>
      <delete dir="${builddir}/tmp"/>
    </then>
    <else>
      <echo message="No math to clean." />
    </else>
  </if>
</target>
于 2013-02-13T14:48:10.927 回答