You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Brown, Carlton" <Ca...@compucredit.com> on 2008/11/26 16:32:12 UTC

Zip files: elegant way of remapping directories while extracting?

I am wondering how I can extract selected directores from a zip file
while performing granular re-mapping of multiple directories.   I have
tried various techniques with <unzip> but cannot find the case I'm
looking for.

The <zip> task allows the simple convenience re-mapping of directory
structures by using a nested <zipfileset> with the prefix attribute.
However, the <unzip> task is not the inverse of the <zip>.   It is
treated as a special case of copy, requiring the use of patternsets and
mappers (along with the benefits and limitations thereof).   Thus,
certain complex mappings that can be done with <zip> cannot conversely
be done in an <unzip>.   Or so it appears to me.

For example, I have a zip file whose output needs to be mapped as
follows:

/en/html -> /root
/en/jsp -> /root
/static/pdf -> /root/pdf

The third mapping is different from the first two.   Multiple mappers
would be needed to accomplish this, but it is not possible to nest
multiple mappers within a an <unzip> or <copy> (except in a chain, which
operates on all files, not just selected ones).

Here is my fantasy code that would accomplish the <unzip> as elegantly
as the <zip> can be peformed in actuality:
<unzip src="web.zip">
	<zipfileset dir="en/html" includes="*" prefix="/root"/>
	<zipfileset dir="en/jsp" includes="*" prefix="/root"/>
	<zipfileset dir="static/pdf" includes="*" prefix="/root/pdf"/>
</unzip>

Have I missed some actual way of doing this in a simple and elegant
fashion?  Otherwise I'm forced to unzip the entire archive and perform
many <copy> tasks at a granular level to perform the restructure.

Thanks in advance,
Carlton



-----------------------------------------
====================================================
This message contains PRIVILEGED and CONFIDENTIAL
information that is intended only for use by the 
named recipient. If you are not the named recipient,
any disclosure, dissemination, or action based on 
the contents of this message is prohibited. In such
case please notify us and destroy and delete all 
copies of this transmission.  Thank you.
====================================================

Re: Zip files: elegant way of remapping directories while extracting?

Posted by Stefan Bodewig <bo...@apache.org>.
On 2008-12-02, Brown, Carlton <Ca...@compucredit.com> wrote:

>> From: Stefan Bodewig [mailto:bodewig@apache.org]

>> On 2008-11-26, Brown, Carlton <Ca...@compucredit.com> wrote:

>>> Here is my fantasy code that would accomplish the <unzip>
>> as elegantly
>>> as the <zip> can be peformed in actuality:
>>> <unzip src="web.zip">
>>> 	<zipfileset dir="en/html" includes="*" prefix="/root"/>
>>> 	<zipfileset dir="en/jsp" includes="*" prefix="/root"/>
>>> 	<zipfileset dir="static/pdf" includes="*" prefix="/root/pdf"/>
>>> </unzip>

>> wouldn't that be

>>   <copy todir="/root">
>>     <zipfileset src="web.zip"/>
>>     <chainedmapper>
>>       <globmapper from="en/html/*" to="*"/>
>>       <globmapper from="en/jsp/*" to="*"/>
>>       <globmapper from="static/pdf/*" to="pdf/*"/>
>>     </chainedmapper>
>>   </copy>

>> the globmappers should ignore all files that don't match the
>> from patterns.

> That's the problem, I don't wish to ignore all files that don't match
> the 'from' patterns.

Grab the firstmatch mapper from svn trunk
<http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/FirstMatchMapper.java?view=log>,
typedef it and replace the chainedmapper of my example with it - and
add an identity mapper at the end.

This is the least intrusive solution I can offer.  svn trunk offers
more options and so will Ant 1.8.x (no release date planned, yet).

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Zip files: elegant way of remapping directories while extracting?

Posted by "Brown, Carlton" <Ca...@compucredit.com>.
> -----Original Message-----
> From: Stefan Bodewig [mailto:bodewig@apache.org] 
> Sent: Wednesday, November 26, 2008 11:26 AM
> To: user@ant.apache.org
> Subject: Re: Zip files: elegant way of remapping directories 
> while extracting?
> 
> On 2008-11-26, Brown, Carlton <Ca...@compucredit.com> wrote:
> 
> > Here is my fantasy code that would accomplish the <unzip> 
> as elegantly 
> > as the <zip> can be peformed in actuality:
> > <unzip src="web.zip">
> > 	<zipfileset dir="en/html" includes="*" prefix="/root"/>
> > 	<zipfileset dir="en/jsp" includes="*" prefix="/root"/>
> > 	<zipfileset dir="static/pdf" includes="*" prefix="/root/pdf"/> 
> > </unzip>
> 
> wouldn't that be
> 
>   <copy todir="/root">
>     <zipfileset src="web.zip"/>
>     <chainedmapper>
>       <globmapper from="en/html/*" to="*"/>
>       <globmapper from="en/jsp/*" to="*"/>
>       <globmapper from="static/pdf/*" to="pdf/*"/>
>     </chainedmapper>
>   </copy>
> 
> the globmappers should ignore all files that don't match the 
> from patterns.

That's the problem, I don't wish to ignore all files that don't match
the 'from' patterns.  Whatever doesn't match the 'from' pattern should
be extracted normally.   This would be the reverse operation of the
zipfileset 'prefix' allowing certain directories to be remapped, while
leaving the others alone.

-----------------------------------------
====================================================
This message contains PRIVILEGED and CONFIDENTIAL
information that is intended only for use by the 
named recipient. If you are not the named recipient,
any disclosure, dissemination, or action based on 
the contents of this message is prohibited. In such
case please notify us and destroy and delete all 
copies of this transmission.  Thank you.
====================================================

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Zip files: elegant way of remapping directories while extracting?

Posted by Stefan Bodewig <bo...@apache.org>.
On 2008-11-26, Brown, Carlton <Ca...@compucredit.com> wrote:

> Here is my fantasy code that would accomplish the <unzip> as elegantly
> as the <zip> can be peformed in actuality:
> <unzip src="web.zip">
> 	<zipfileset dir="en/html" includes="*" prefix="/root"/>
> 	<zipfileset dir="en/jsp" includes="*" prefix="/root"/>
> 	<zipfileset dir="static/pdf" includes="*" prefix="/root/pdf"/>
> </unzip>

wouldn't that be

  <copy todir="/root">
    <zipfileset src="web.zip"/>
    <chainedmapper>
      <globmapper from="en/html/*" to="*"/>
      <globmapper from="en/jsp/*" to="*"/>
      <globmapper from="static/pdf/*" to="pdf/*"/>
    </chainedmapper>
  </copy>

the globmappers should ignore all files that don't match the from
patterns.

svn trunk contains a new type of resource collection, the mapped
resource collection that merges mapper and resource collection,
something like

  <mappedresources>
    <zipfileset src="web.zip" includes="en/html/*"/>
    <globmapper from="en/html/*" to="/root/*"/>
  </mappedresources>

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org