Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant zipfileset rename file

Tags:

rename

ant

I would like to include file to zipfileset but rename it as well

e.g.

<zipfileset dir="${basedir}/test/target"   prefix="webapps">
    <include name="test*.war"/>
</zipfileset>

but want to change name from test.war to sample.war

how to achieve this ? thank you.

like image 367
aRagornol Avatar asked Nov 26 '12 12:11

aRagornol


2 Answers

You can probably do what you want using a mappedresources resource collection. This 'worked for me' in a basic test (one input war called test1.war):

<mappedresources id="mapped.zfs">
    <zipfileset dir="${basedir}/test/target">
        <include name="test*.war"/>
    </zipfileset>
    <globmapper from="test*" to="webapps/sample*" />
</mappedresources>

<zip destfile="eg.zip">
    <resources refid="mapped.zfs" />
</zip>

% unzip -l eg.zip 
Archive:  eg.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  11-27-2012 00:19   webapps/
     1423  11-27-2012 00:16   webapps/sample1.war
---------                     -------
     1423                     2 files
like image 91
martin clayton Avatar answered Sep 21 '22 02:09

martin clayton


I don't think this is possible, I'd go for 2 steps approach.

Either rename and add:

<move file="${basedir}/test/target/test.war" tofile="${basedir}/test/target/sample.war"/>
<zipfileset dir="${basedir}/test/target"   prefix="webapps">
    <include name="sample*.war"/>
</zipfileset>

or copy and add (if you need both):

<copy file="${basedir}/test/target/test.war" tofile="${basedir}/test/target/sample.war"/>
<zipfileset dir="${basedir}/test/target"   prefix="webapps">
    <include name="sample*.war"/>
</zipfileset>
like image 38
Peter Butkovic Avatar answered Sep 21 '22 02:09

Peter Butkovic