Reputation: 345
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.
Upvotes: 6
Views: 4425
Reputation: 415
martin clayton's answer worked for me. I was also able to do it all in one element (as children):
<zip destfile="eg.zip">
<mappedresources>
<zipfileset file="test*.war"/>
<globmapper from="test*" to="webapps/sample*" />
</mappedresources>
<!-- additional file-sets and resources may be listed here -->
</zip>
Upvotes: 1
Reputation: 78105
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
Upvotes: 7
Reputation: 3279
In addition to solution mentioned by peter, if you do not want to retain 2 copies of the same file... you can remove the copied one...
<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>
<delete file="${basedir}/test/target/sample.war"/>
Now you would not have duplicate copy of test.war.
Upvotes: 0
Reputation: 12139
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>
Upvotes: 1