Domanda

We want to build multiple zip files where some of the files have contents in common with others. Rather than specify the full list of files for each zip (they're actually quite large) I thought I would try to get some reuse.

So I tried using <union> for this:

<project name="test" default="zips">
  <target name="zips">
    <union id="common">
      <zipfileset prefix="." dir="." includes="1"/>
      <zipfileset prefix="3" dir="." includes="2"/>
    </union>
    <zip zipfile="1.zip">
      <resources refid="common"/>
    </zip>
    <zip zipfile="2.zip">
      <resources refid="common"/>
    </zip>
  </target>
</project>

This does generate two zip files with "1" and "2" inside each, but the "3" prefix is missing from both files.

What am I doing wrong?

We also have a custom task which uses zipfileset internally. I tried to get it to work with union as well, but couldn't figure out how to get at the prefix value.

È stato utile?

Soluzione

Try this for your common resourcecollection:

<union id="common">
  <fileset dir="." includes="1"/>
  <mappedresources>
      <fileset dir="." includes="2"/>
      <globmapper from="*" to="3/*"/>
  </mappedresources>
</union>

The prefix parameter in a zipfileset is only used when reading files from an archive specified with the src parameter, otherwise it is ignored - which is the behaviour you see. For your use, you are trying to specify the prefix in the created archive. To do that you need a mapper.

See also: Ant docs for mappedresources.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top