geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r821961 [11/30] - in /geronimo/sandbox/djencks/osgi/framework: ./ buildsupport/ buildsupport/car-maven-plugin/ buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ buildsupport/geronimo-maven-plugin/src/main/jav...
Date Mon, 05 Oct 2009 18:54:56 GMT
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AbstractZipUnArchiver.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AbstractZipUnArchiver.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AbstractZipUnArchiver.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AbstractZipUnArchiver.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,313 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.zip;
+
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+import org.apache.geronimo.system.plugin.plexus.archiver.AbstractUnArchiver;
+import org.apache.geronimo.system.plugin.plexus.archiver.ArchiveFilterException;
+import org.apache.geronimo.system.plugin.plexus.archiver.ArchiverException;
+import org.apache.geronimo.system.plugin.plexus.archiver.util.ArchiveEntryUtils;
+import org.apache.geronimo.system.plugin.plexus.io.fileselectors.FileInfo;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoResource;
+import org.apache.geronimo.system.plugin.plexus.util.FileUtils;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Date;
+import java.util.Enumeration;
+
+/**
+ * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
+ * @version $Id: AbstractZipUnArchiver.java 7140 2008-01-06 11:50:12Z jochen $
+ */
+public abstract class AbstractZipUnArchiver
+    extends AbstractUnArchiver
+{
+    private static final String NATIVE_ENCODING = "native-encoding";
+
+    private String encoding = "UTF8";
+
+    public AbstractZipUnArchiver()
+    {
+    }
+
+    public AbstractZipUnArchiver( File sourceFile )
+    {
+        super( sourceFile );
+    }
+
+    /**
+     * Sets the encoding to assume for file names and comments.
+     * <p/>
+     * <p>Set to <code>native-encoding</code> if you want your
+     * platform's native encoding, defaults to UTF8.</p>
+     */
+    public void setEncoding( String encoding )
+    {
+        if ( NATIVE_ENCODING.equals( encoding ) )
+        {
+            encoding = null;
+        }
+        this.encoding = encoding;
+    }
+
+    private static class ZipEntryFileInfo implements PlexusIoResource
+    {
+        private final ZipFile zipFile;
+        private final ZipEntry zipEntry;
+
+        ZipEntryFileInfo( ZipFile zipFile, ZipEntry zipEntry )
+        {
+            this.zipFile = zipFile;
+            this.zipEntry = zipEntry;
+        }
+
+        public String getName()
+        {
+            return zipEntry.getName();
+        }
+
+        public boolean isDirectory()
+        {
+            return zipEntry.isDirectory();
+        }
+
+        public boolean isFile()
+        {
+            return !zipEntry.isDirectory();
+        }
+
+        public InputStream getContents()
+            throws IOException
+        {
+            return zipFile.getInputStream( zipEntry );
+        }
+
+        public long getLastModified()
+        {
+            final long l = zipEntry.getTime();
+            return l == 0 ? PlexusIoResource.UNKNOWN_MODIFICATION_DATE : l;
+        }
+
+        public long getSize()
+        {
+            final long l = zipEntry.getSize();
+            return l == -1 ? PlexusIoResource.UNKNOWN_RESOURCE_SIZE : l;
+        }
+
+        public URL getURL()
+            throws IOException
+        {
+            return null;
+        }
+
+        public boolean isExisting()
+        {
+            return true;
+        }
+    }
+
+    protected void execute()
+        throws ArchiverException
+    {
+        getLogger().debug( "Expanding: " + getSourceFile() + " into " + getDestDirectory() );
+        ZipFile zf = null;
+        try
+        {
+            zf = new ZipFile( getSourceFile(), encoding );
+            Enumeration e = zf.getEntries();
+            while ( e.hasMoreElements() )
+            {
+                ZipEntry ze = (ZipEntry) e.nextElement();
+                ZipEntryFileInfo fileInfo = new ZipEntryFileInfo( zf, ze );
+                if ( !isSelected( ze.getName(), fileInfo ) )
+                {
+                    continue;
+                }
+                extractFileIfIncluded( getSourceFile(), getDestDirectory(), zf.getInputStream( ze ), ze.getName(),
+                                       new Date( ze.getTime() ), ze.isDirectory(), null );
+            }
+
+            getLogger().debug( "expand complete" );
+        }
+        catch ( IOException ioe )
+        {
+            throw new ArchiverException( "Error while expanding " + getSourceFile().getAbsolutePath(), ioe );
+        }
+        finally
+        {
+            if ( zf != null )
+            {
+                try
+                {
+                    zf.close();
+                }
+                catch ( IOException e )
+                {
+                    //ignore
+                }
+            }
+        }
+    }
+
+    private void extractFileIfIncluded( File sourceFile,
+                                        File destDirectory,
+                                        InputStream inputStream,
+                                        String name,
+                                        Date time,
+                                        boolean isDirectory, Integer mode )
+        throws IOException, ArchiverException
+    {
+        try
+        {
+            if ( include( inputStream, name ) )
+            {
+                extractFile( sourceFile, destDirectory, inputStream, name, time, isDirectory, mode );
+            }
+        }
+        catch ( ArchiveFilterException e )
+        {
+            throw new ArchiverException( "Error verifying \'" + name + "\' for inclusion: " + e.getMessage(), e );
+        }
+    }
+
+    protected void extractFile( File srcF,
+                                File dir,
+                                InputStream compressedInputStream,
+                                String entryName,
+                                Date entryDate,
+                                boolean isDirectory, Integer mode )
+        throws IOException, ArchiverException
+    {
+        File f = FileUtils.resolveFile( dir, entryName );
+
+        try
+        {
+            if ( !isOverwrite() && f.exists() && ( f.lastModified() >= entryDate.getTime() ) )
+            {
+                return;
+            }
+
+            // create intermediary directories - sometimes zip don't add them
+            File dirF = f.getParentFile();
+            if ( dirF != null )
+            {
+                dirF.mkdirs();
+            }
+
+            if ( isDirectory )
+            {
+                f.mkdirs();
+            }
+            else
+            {
+                byte[] buffer = new byte[1024];
+                int length;
+                FileOutputStream fos = null;
+                try
+                {
+                    fos = new FileOutputStream( f );
+
+                    while ( ( length = compressedInputStream.read( buffer ) ) >= 0 )
+                    {
+                        fos.write( buffer, 0, length );
+                    }
+
+                    fos.close();
+                    fos = null;
+                }
+                finally
+                {
+                    if ( fos != null )
+                    {
+                        try
+                        {
+                            fos.close();
+                        }
+                        catch ( IOException e )
+                        {
+                            // ignore
+                        }
+                    }
+                }
+            }
+
+            f.setLastModified( entryDate.getTime() );
+
+            if ( mode != null )
+            {
+                ArchiveEntryUtils.chmod( f, mode.intValue(), getLogger() );
+            }
+        }
+        catch ( FileNotFoundException ex )
+        {
+            getLogger().warn( "Unable to expand to file " + f.getPath() );
+        }
+    }
+
+    protected void execute( String path,
+                         File outputDirectory )
+        throws ArchiverException
+    {
+        ZipFile zipFile = null;
+
+        try
+        {
+            zipFile = new ZipFile( getSourceFile(), encoding );
+
+            Enumeration e = zipFile.getEntries();
+
+            while ( e.hasMoreElements() )
+            {
+                ZipEntry ze = (ZipEntry) e.nextElement();
+                ZipEntryFileInfo fileInfo = new ZipEntryFileInfo( zipFile, ze );
+                if ( !isSelected( ze.getName(), fileInfo ) )
+                {
+                    continue;
+                }
+
+                if ( ze.getName().startsWith( path ) )
+                {
+                    extractFileIfIncluded( getSourceFile(), outputDirectory, zipFile.getInputStream( ze ), ze.getName(),
+                                           new Date( ze.getTime() ), ze.isDirectory(), null );
+                }
+            }
+        }
+        catch ( IOException ioe )
+        {
+            throw new ArchiverException( "Error while expanding " + getSourceFile().getAbsolutePath(), ioe );
+        }
+        finally
+        {
+            if ( zipFile != null )
+            {
+                try
+                {
+                    zipFile.close();
+                }
+                catch ( IOException e )
+                {
+                    //ignore
+                }
+            }
+        }
+    }
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AbstractZipUnArchiver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AbstractZipUnArchiver.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AbstractZipUnArchiver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AsiExtraField.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AsiExtraField.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AsiExtraField.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AsiExtraField.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,361 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.zip;
+
+/*
+ * Copyright  2001-2002,2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+import org.apache.geronimo.system.plugin.plexus.archiver.UnixStat;
+
+import java.util.zip.CRC32;
+import java.util.zip.ZipException;
+
+/**
+ * Adds Unix file permission and UID/GID fields as well as symbolic
+ * link handling.
+ * <p/>
+ * <p>This class uses the ASi extra field in the format:
+ * <pre>
+ *         Value         Size            Description
+ *         -----         ----            -----------
+ * (Unix3) 0x756e        Short           tag for this extra block type
+ *         TSize         Short           total data size for this block
+ *         CRC           Long            CRC-32 of the remaining data
+ *         Mode          Short           file permissions
+ *         SizDev        Long            symlink'd size OR major/minor dev num
+ *         UID           Short           user ID
+ *         GID           Short           group ID
+ *         (var.)        variable        symbolic link filename
+ * </pre>
+ * taken from appnote.iz (Info-ZIP note, 981119) found at <a
+ * href="ftp://ftp.uu.net/pub/archiving/zip/doc/">ftp://ftp.uu.net/pub/archiving/zip/doc/</a></p>
+ * <p/>
+ * <p/>
+ * <p>Short is two bytes and Long is four bytes in big endian byte and
+ * word order, device numbers are currently not supported.</p>
+ *
+ * @version $Revision$ $Date$
+ *          from org.apache.ant.tools.zip.AsiExtraField v1.10
+ */
+public class AsiExtraField
+    implements ZipExtraField, UnixStat, Cloneable
+{
+
+    private static final ZipShort HEADER_ID = new ZipShort( 0x756E );
+
+    /**
+     * Standard Unix stat(2) file mode.
+     *
+     * @since 1.1
+     */
+    private int mode = 0;
+
+    /**
+     * User ID.
+     *
+     * @since 1.1
+     */
+    private int uid = 0;
+
+    /**
+     * Group ID.
+     *
+     * @since 1.1
+     */
+    private int gid = 0;
+
+    /**
+     * File this entry points to, if it is a symbolic link.
+     * <p/>
+     * <p>empty string - if entry is not a symbolic link.</p>
+     *
+     * @since 1.1
+     */
+    private String link = "";
+
+    /**
+     * Is this an entry for a directory?
+     *
+     * @since 1.1
+     */
+    private boolean dirFlag = false;
+
+    /**
+     * Instance used to calculate checksums.
+     *
+     * @since 1.1
+     */
+    private CRC32 crc = new CRC32();
+
+    public AsiExtraField()
+    {
+    }
+
+    /**
+     * The Header-ID.
+     *
+     * @since 1.1
+     */
+    public ZipShort getHeaderId()
+    {
+        return HEADER_ID;
+    }
+
+    /**
+     * Length of the extra field in the local file data - without
+     * Header-ID or length specifier.
+     *
+     * @since 1.1
+     */
+    public ZipShort getLocalFileDataLength()
+    {
+        return new ZipShort( 4         // CRC
+                             + 2         // Mode
+                             + 4         // SizDev
+                             + 2         // UID
+                             + 2         // GID
+                             + getLinkedFile().getBytes().length );
+    }
+
+    /**
+     * Delegate to local file data.
+     *
+     * @since 1.1
+     */
+    public ZipShort getCentralDirectoryLength()
+    {
+        return getLocalFileDataLength();
+    }
+
+    /**
+     * The actual data to put into local file data - without Header-ID
+     * or length specifier.
+     *
+     * @since 1.1
+     */
+    public byte[] getLocalFileDataData()
+    {
+        // CRC will be added later
+        byte[] data = new byte[getLocalFileDataLength().getValue() - 4];
+        System.arraycopy( ( new ZipShort( getMode() ) ).getBytes(), 0, data, 0, 2 );
+
+        byte[] linkArray = getLinkedFile().getBytes();
+        System.arraycopy( ( new ZipLong( linkArray.length ) ).getBytes(),
+                          0, data, 2, 4 );
+
+        System.arraycopy( ( new ZipShort( getUserId() ) ).getBytes(),
+                          0, data, 6, 2 );
+        System.arraycopy( ( new ZipShort( getGroupId() ) ).getBytes(),
+                          0, data, 8, 2 );
+
+        System.arraycopy( linkArray, 0, data, 10, linkArray.length );
+
+        crc.reset();
+        crc.update( data );
+        long checksum = crc.getValue();
+
+        byte[] result = new byte[data.length + 4];
+        System.arraycopy( ( new ZipLong( checksum ) ).getBytes(), 0, result, 0, 4 );
+        System.arraycopy( data, 0, result, 4, data.length );
+        return result;
+    }
+
+    /**
+     * Delegate to local file data.
+     *
+     * @since 1.1
+     */
+    public byte[] getCentralDirectoryData()
+    {
+        return getLocalFileDataData();
+    }
+
+    /**
+     * Set the user id.
+     *
+     * @since 1.1
+     */
+    public void setUserId( int uid )
+    {
+        this.uid = uid;
+    }
+
+    /**
+     * Get the user id.
+     *
+     * @since 1.1
+     */
+    public int getUserId()
+    {
+        return uid;
+    }
+
+    /**
+     * Set the group id.
+     *
+     * @since 1.1
+     */
+    public void setGroupId( int gid )
+    {
+        this.gid = gid;
+    }
+
+    /**
+     * Get the group id.
+     *
+     * @since 1.1
+     */
+    public int getGroupId()
+    {
+        return gid;
+    }
+
+    /**
+     * Indicate that this entry is a symbolic link to the given filename.
+     *
+     * @param name Name of the file this entry links to, empty String
+     *             if it is not a symbolic link.
+     * @since 1.1
+     */
+    public void setLinkedFile( String name )
+    {
+        link = name;
+        mode = getMode( mode );
+    }
+
+    /**
+     * Name of linked file
+     *
+     * @return name of the file this entry links to if it is a
+     *         symbolic link, the empty string otherwise.
+     * @since 1.1
+     */
+    public String getLinkedFile()
+    {
+        return link;
+    }
+
+    /**
+     * Is this entry a symbolic link?
+     *
+     * @since 1.1
+     */
+    public boolean isLink()
+    {
+        return getLinkedFile().length() != 0;
+    }
+
+    /**
+     * File mode of this file.
+     *
+     * @since 1.1
+     */
+    public void setMode( int mode )
+    {
+        this.mode = getMode( mode );
+    }
+
+    /**
+     * File mode of this file.
+     *
+     * @since 1.1
+     */
+    public int getMode()
+    {
+        return mode;
+    }
+
+    /**
+     * Indicate whether this entry is a directory.
+     *
+     * @since 1.1
+     */
+    public void setDirectory( boolean dirFlag )
+    {
+        this.dirFlag = dirFlag;
+        mode = getMode( mode );
+    }
+
+    /**
+     * Is this entry a directory?
+     *
+     * @since 1.1
+     */
+    public boolean isDirectory()
+    {
+        return dirFlag && !isLink();
+    }
+
+    /**
+     * Populate data from this array as if it was in local file data.
+     *
+     * @since 1.1
+     */
+    public void parseFromLocalFileData( byte[] data, int offset, int length )
+        throws ZipException
+    {
+
+        long givenChecksum = ( new ZipLong( data, offset ) ).getValue();
+        byte[] tmp = new byte[length - 4];
+        System.arraycopy( data, offset + 4, tmp, 0, length - 4 );
+        crc.reset();
+        crc.update( tmp );
+        long realChecksum = crc.getValue();
+        if ( givenChecksum != realChecksum )
+        {
+            throw new ZipException( "bad CRC checksum "
+                                    + Long.toHexString( givenChecksum )
+                                    + " instead of "
+                                    + Long.toHexString( realChecksum ) );
+        }
+
+        int newMode = ( new ZipShort( tmp, 0 ) ).getValue();
+        byte[] linkArray = new byte[(int) ( new ZipLong( tmp, 2 ) ).getValue()];
+        uid = ( new ZipShort( tmp, 6 ) ).getValue();
+        gid = ( new ZipShort( tmp, 8 ) ).getValue();
+
+        if ( linkArray.length == 0 )
+        {
+            link = "";
+        }
+        else
+        {
+            System.arraycopy( tmp, 10, linkArray, 0, linkArray.length );
+            link = new String( linkArray );
+        }
+        setDirectory( ( newMode & DIR_FLAG ) != 0 );
+        setMode( newMode );
+    }
+
+    /**
+     * Get the file mode for given permissions with the correct file type.
+     *
+     * @since 1.1
+     */
+    protected int getMode( int mode )
+    {
+        int type = FILE_FLAG;
+        if ( isLink() )
+        {
+            type = LINK_FLAG;
+        }
+        else if ( isDirectory() )
+        {
+            type = DIR_FLAG;
+        }
+        return type | ( mode & PERM_MASK );
+    }
+
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AsiExtraField.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AsiExtraField.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AsiExtraField.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ExtraFieldUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ExtraFieldUtils.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ExtraFieldUtils.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ExtraFieldUtils.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,194 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.zip;
+
+/*
+ * Copyright  2001-2002,2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+import java.util.Hashtable;
+import java.util.Vector;
+import java.util.zip.ZipException;
+
+/**
+ * ZipExtraField related methods
+ *
+ * @version $Revision$ $Date$
+ *          from org.apache.ant.tools.zip.ExtraFieldUtils v1.9
+ */
+public class ExtraFieldUtils
+{
+
+    /**
+     * Static registry of known extra fields.
+     *
+     * @since 1.1
+     */
+    private static Hashtable implementations;
+
+    static
+    {
+        implementations = new Hashtable();
+        register( AsiExtraField.class );
+    }
+
+    /**
+     * Register a ZipExtraField implementation.
+     * <p/>
+     * <p>The given class must have a no-arg constructor and implement
+     * the {@link ZipExtraField ZipExtraField interface}.</p>
+     *
+     * @since 1.1
+     */
+    public static void register( Class c )
+    {
+        try
+        {
+            ZipExtraField ze = (ZipExtraField) c.newInstance();
+            implementations.put( ze.getHeaderId(), c );
+        }
+        catch ( ClassCastException cc )
+        {
+            throw new RuntimeException( c + " doesn\'t implement ZipExtraField" );
+        }
+        catch ( InstantiationException ie )
+        {
+            throw new RuntimeException( c + " is not a concrete class" );
+        }
+        catch ( IllegalAccessException ie )
+        {
+            throw new RuntimeException( c + "\'s no-arg constructor is not public" );
+        }
+    }
+
+    /**
+     * Create an instance of the approriate ExtraField, falls back to
+     * {@link UnrecognizedExtraField UnrecognizedExtraField}.
+     *
+     * @since 1.1
+     */
+    public static ZipExtraField createExtraField( ZipShort headerId )
+        throws InstantiationException, IllegalAccessException
+    {
+        Class c = (Class) implementations.get( headerId );
+        if ( c != null )
+        {
+            return (ZipExtraField) c.newInstance();
+        }
+        UnrecognizedExtraField u = new UnrecognizedExtraField();
+        u.setHeaderId( headerId );
+        return u;
+    }
+
+    /**
+     * Split the array into ExtraFields and populate them with the
+     * give data.
+     *
+     * @since 1.1
+     */
+    public static ZipExtraField[] parse( byte[] data )
+        throws ZipException
+    {
+        Vector v = new Vector();
+        int start = 0;
+        while ( start <= data.length - 4 )
+        {
+            ZipShort headerId = new ZipShort( data, start );
+            int length = ( new ZipShort( data, start + 2 ) ).getValue();
+            if ( start + 4 + length > data.length )
+            {
+                throw new ZipException( "data starting at " + start
+                                        + " is in unknown format" );
+            }
+            try
+            {
+                ZipExtraField ze = createExtraField( headerId );
+                ze.parseFromLocalFileData( data, start + 4, length );
+                v.addElement( ze );
+            }
+            catch ( InstantiationException ie )
+            {
+                throw new ZipException( ie.getMessage() );
+            }
+            catch ( IllegalAccessException iae )
+            {
+                throw new ZipException( iae.getMessage() );
+            }
+            start += ( length + 4 );
+        }
+        if ( start != data.length )
+        { // array not exhausted
+            throw new ZipException( "data starting at " + start
+                                    + " is in unknown format" );
+        }
+
+        ZipExtraField[] result = new ZipExtraField[v.size()];
+        v.copyInto( result );
+        return result;
+    }
+
+    /**
+     * Merges the local file data fields of the given ZipExtraFields.
+     *
+     * @since 1.1
+     */
+    public static byte[] mergeLocalFileDataData( ZipExtraField[] data )
+    {
+        int sum = 4 * data.length;
+        for ( int i = 0; i < data.length; i++ )
+        {
+            sum += data[ i ].getLocalFileDataLength().getValue();
+        }
+        byte[] result = new byte[sum];
+        int start = 0;
+        for ( int i = 0; i < data.length; i++ )
+        {
+            System.arraycopy( data[ i ].getHeaderId().getBytes(),
+                              0, result, start, 2 );
+            System.arraycopy( data[ i ].getLocalFileDataLength().getBytes(),
+                              0, result, start + 2, 2 );
+            byte[] local = data[ i ].getLocalFileDataData();
+            System.arraycopy( local, 0, result, start + 4, local.length );
+            start += ( local.length + 4 );
+        }
+        return result;
+    }
+
+    /**
+     * Merges the central directory fields of the given ZipExtraFields.
+     *
+     * @since 1.1
+     */
+    public static byte[] mergeCentralDirectoryData( ZipExtraField[] data )
+    {
+        int sum = 4 * data.length;
+        for ( int i = 0; i < data.length; i++ )
+        {
+            sum += data[ i ].getCentralDirectoryLength().getValue();
+        }
+        byte[] result = new byte[sum];
+        int start = 0;
+        for ( int i = 0; i < data.length; i++ )
+        {
+            System.arraycopy( data[ i ].getHeaderId().getBytes(),
+                              0, result, start, 2 );
+            System.arraycopy( data[ i ].getCentralDirectoryLength().getBytes(),
+                              0, result, start + 2, 2 );
+            byte[] local = data[ i ].getCentralDirectoryData();
+            System.arraycopy( local, 0, result, start + 4, local.length );
+            start += ( local.length + 4 );
+        }
+        return result;
+    }
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ExtraFieldUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ExtraFieldUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ExtraFieldUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/PlexusIoZipFileResourceCollection.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/PlexusIoZipFileResourceCollection.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/PlexusIoZipFileResourceCollection.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/PlexusIoZipFileResourceCollection.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,47 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.zip;
+
+import org.apache.geronimo.system.plugin.plexus.io.resources.AbstractPlexusIoArchiveResourceCollection;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Iterator;
+
+public class PlexusIoZipFileResourceCollection
+    extends AbstractPlexusIoArchiveResourceCollection
+{
+
+    /**
+     * The zip file resource collections role hint.
+     */
+    public static final String ROLE_HINT = "zip";
+
+
+    protected Iterator getEntries() throws IOException
+    {
+        final File f = getFile();
+        if ( f == null )
+        {
+            throw new IOException( "The tar archive file has not been set." );
+        }
+        final ZipFile zipFile = new ZipFile( f );
+        final Enumeration en = zipFile.getEntries();
+        return new Iterator(){
+            public boolean hasNext()
+            {
+                return en.hasMoreElements();
+            }
+            public Object next()
+            {
+                final ZipEntry entry = (ZipEntry) en.nextElement();
+                final ZipResource res = new ZipResource( zipFile, entry );
+                
+                return res;
+            }
+            public void remove()
+            {
+                throw new UnsupportedOperationException( "Removing isn't implemented." );
+            }
+        };
+    }
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/PlexusIoZipFileResourceCollection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/PlexusIoZipFileResourceCollection.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/PlexusIoZipFileResourceCollection.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/UnrecognizedExtraField.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/UnrecognizedExtraField.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/UnrecognizedExtraField.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/UnrecognizedExtraField.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,111 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.zip;
+
+/*
+ * Copyright  2001-2002,2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+/**
+ * Simple placeholder for all those extra fields we don't want to deal
+ * with.
+ * <p/>
+ * <p>Assumes local file data and central directory entries are
+ * identical - unless told the opposite.</p>
+ *
+ * @version $Revision$ $Date$
+ *          from org.apache.ant.tools.zip.UnrecognizedExtraField v1.8
+ */
+public class UnrecognizedExtraField
+    implements ZipExtraField
+{
+
+    /**
+     * The Header-ID.
+     *
+     * @since 1.1
+     */
+    private ZipShort headerId;
+
+    public void setHeaderId( ZipShort headerId )
+    {
+        this.headerId = headerId;
+    }
+
+    public ZipShort getHeaderId()
+    {
+        return headerId;
+    }
+
+    /**
+     * Extra field data in local file data - without
+     * Header-ID or length specifier.
+     *
+     * @since 1.1
+     */
+    private byte[] localData;
+
+    public void setLocalFileDataData( byte[] data )
+    {
+        localData = data;
+    }
+
+    public ZipShort getLocalFileDataLength()
+    {
+        return new ZipShort( localData.length );
+    }
+
+    public byte[] getLocalFileDataData()
+    {
+        return localData;
+    }
+
+    /**
+     * Extra field data in central directory - without
+     * Header-ID or length specifier.
+     *
+     * @since 1.1
+     */
+    private byte[] centralData;
+
+    public void setCentralDirectoryData( byte[] data )
+    {
+        centralData = data;
+    }
+
+    public ZipShort getCentralDirectoryLength()
+    {
+        if ( centralData != null )
+        {
+            return new ZipShort( centralData.length );
+        }
+        return getLocalFileDataLength();
+    }
+
+    public byte[] getCentralDirectoryData()
+    {
+        if ( centralData != null )
+        {
+            return centralData;
+        }
+        return getLocalFileDataData();
+    }
+
+    public void parseFromLocalFileData( byte[] data, int offset, int length )
+    {
+        byte[] tmp = new byte[length];
+        System.arraycopy( data, offset, tmp, 0, length );
+        setLocalFileDataData( tmp );
+    }
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/UnrecognizedExtraField.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/UnrecognizedExtraField.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/UnrecognizedExtraField.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipArchiver.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipArchiver.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipArchiver.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipArchiver.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,26 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.zip;
+
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @version $Id: ZipArchiver.java 2436 2005-09-01 17:20:41Z trygvis $
+ */
+public class ZipArchiver
+    extends AbstractZipArchiver
+{
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipArchiver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipArchiver.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipArchiver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipEntry.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipEntry.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipEntry.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipEntry.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,543 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.zip;
+
+/*
+ * Copyright  2001-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Vector;
+import java.util.zip.ZipException;
+
+import org.apache.geronimo.system.plugin.plexus.archiver.ArchiveFile;
+
+/**
+ * Extension that adds better handling of extra fields and provides
+ * access to the internal and external file attributes.
+ *
+ * @version $Revision$ $Date$
+ *          from org.apache.ant.tools.zip.ZipEntry v1.16
+ */
+public class ZipEntry
+    extends java.util.zip.ZipEntry
+    implements Cloneable, ArchiveFile.Entry
+{
+
+    private static final int PLATFORM_UNIX = 3;
+
+    private static final int PLATFORM_FAT = 0;
+
+    private int internalAttributes = 0;
+
+    private int platform = PLATFORM_FAT;
+
+    private long externalAttributes = 0;
+
+    private Vector extraFields = new Vector();
+
+    private String name = null;
+
+    /**
+     * Creates a new zip entry with the specified name.
+     *
+     * @since 1.1
+     */
+    public ZipEntry( String name )
+    {
+        super( name );
+    }
+
+    /**
+     * Creates a new zip entry with fields taken from the specified zip entry.
+     *
+     * @since 1.1
+     */
+    public ZipEntry( java.util.zip.ZipEntry entry )
+        throws ZipException
+    {
+        /*
+         * REVISIT: call super(entry) instead of this stuff in Ant2,
+         *          "copy constructor" has not been available in JDK 1.1
+         */
+        super( entry.getName() );
+
+        setComment( entry.getComment() );
+        setMethod( entry.getMethod() );
+        setTime( entry.getTime() );
+
+        long size = entry.getSize();
+        if ( size > 0 )
+        {
+            setSize( size );
+        }
+        long cSize = entry.getCompressedSize();
+        if ( cSize > 0 )
+        {
+            setComprSize( cSize );
+        }
+        long crc = entry.getCrc();
+        if ( crc > 0 )
+        {
+            setCrc( crc );
+        }
+
+        byte[] extra = entry.getExtra();
+        if ( extra != null )
+        {
+            setExtraFields( ExtraFieldUtils.parse( extra ) );
+        }
+        else
+        {
+            // initializes extra data to an empty byte array
+            setExtra();
+        }
+    }
+
+    /**
+     * Creates a new zip entry with fields taken from the specified zip entry.
+     *
+     * @since 1.1
+     */
+    public ZipEntry( ZipEntry entry )
+        throws ZipException
+    {
+        this( (java.util.zip.ZipEntry) entry );
+        setInternalAttributes( entry.getInternalAttributes() );
+        setExternalAttributes( entry.getExternalAttributes() );
+        setExtraFields( entry.getExtraFields() );
+    }
+
+    /**
+     * @since 1.9
+     */
+    protected ZipEntry()
+    {
+        super( "" );
+    }
+
+    /**
+     * Overwrite clone
+     *
+     * @since 1.1
+     */
+    public Object clone()
+    {
+        try
+        {
+            ZipEntry e = (ZipEntry) super.clone();
+
+            e.setName( getName() );
+            e.setComment( getComment() );
+            e.setMethod( getMethod() );
+            e.setTime( getTime() );
+            long size = getSize();
+            if ( size > 0 )
+            {
+                e.setSize( size );
+            }
+            long cSize = getCompressedSize();
+            if ( cSize > 0 )
+            {
+                e.setComprSize( cSize );
+            }
+            long crc = getCrc();
+            if ( crc > 0 )
+            {
+                e.setCrc( crc );
+            }
+
+            e.extraFields = (Vector) extraFields.clone();
+            e.setInternalAttributes( getInternalAttributes() );
+            e.setExternalAttributes( getExternalAttributes() );
+            e.setExtraFields( getExtraFields() );
+            return e;
+        }
+        catch ( Throwable t )
+        {
+            // in JDK 1.1 ZipEntry is not Cloneable, so super.clone declares
+            // to throw CloneNotSupported - since JDK 1.2 it is overridden to
+            // not throw that exception
+            return null;
+        }
+    }
+
+    /**
+     * Retrieves the internal file attributes.
+     *
+     * @since 1.1
+     */
+    public int getInternalAttributes()
+    {
+        return internalAttributes;
+    }
+
+    /**
+     * Sets the internal file attributes.
+     *
+     * @since 1.1
+     */
+    public void setInternalAttributes( int value )
+    {
+        internalAttributes = value;
+    }
+
+    /**
+     * Retrieves the external file attributes.
+     *
+     * @since 1.1
+     */
+    public long getExternalAttributes()
+    {
+        return externalAttributes;
+    }
+
+    /**
+     * Sets the external file attributes.
+     *
+     * @since 1.1
+     */
+    public void setExternalAttributes( long value )
+    {
+        externalAttributes = value;
+    }
+
+    /**
+     * Sets Unix permissions in a way that is understood by Info-Zip's
+     * unzip command.
+     *
+     * @since Ant 1.5.2
+     */
+    public void setUnixMode( int mode )
+    {
+        setExternalAttributes( ( mode << 16 )
+                               // MS-DOS read-only attribute
+                               | ( ( mode & 0200 ) == 0 ? 1 : 0 )
+                               // MS-DOS directory flag
+                               | ( isDirectory() ? 0x10 : 0 ) );
+        platform = PLATFORM_UNIX;
+    }
+
+    /**
+     * Unix permission.
+     *
+     * @since Ant 1.6
+     */
+    public int getUnixMode()
+    {
+        return (int) ( ( getExternalAttributes() >> 16 ) & 0xFFFF );
+    }
+
+    /**
+     * Platform specification to put into the &quot;version made
+     * by&quot; part of the central file header.
+     *
+     * @return 0 (MS-DOS FAT) unless {@link #setUnixMode setUnixMode}
+     *         has been called, in which case 3 (Unix) will be returned.
+     * @since Ant 1.5.2
+     */
+    public int getPlatform()
+    {
+        return platform;
+    }
+
+    /**
+     * @since 1.9
+     */
+    protected void setPlatform( int platform )
+    {
+        this.platform = platform;
+    }
+
+    /**
+     * Replaces all currently attached extra fields with the new array.
+     *
+     * @since 1.1
+     */
+    public void setExtraFields( ZipExtraField[] fields )
+    {
+        extraFields.removeAllElements();
+        for ( int i = 0; i < fields.length; i++ )
+        {
+            extraFields.addElement( fields[ i ] );
+        }
+        setExtra();
+    }
+
+    /**
+     * Retrieves extra fields.
+     *
+     * @since 1.1
+     */
+    public ZipExtraField[] getExtraFields()
+    {
+        ZipExtraField[] result = new ZipExtraField[extraFields.size()];
+        extraFields.copyInto( result );
+        return result;
+    }
+
+    /**
+     * Adds an extra fields - replacing an already present extra field
+     * of the same type.
+     *
+     * @since 1.1
+     */
+    public void addExtraField( ZipExtraField ze )
+    {
+        ZipShort type = ze.getHeaderId();
+        boolean done = false;
+        for ( int i = 0; !done && i < extraFields.size(); i++ )
+        {
+            if ( ( (ZipExtraField) extraFields.elementAt( i ) ).getHeaderId().equals( type ) )
+            {
+                extraFields.setElementAt( ze, i );
+                done = true;
+            }
+        }
+        if ( !done )
+        {
+            extraFields.addElement( ze );
+        }
+        setExtra();
+    }
+
+    /**
+     * Remove an extra fields.
+     *
+     * @since 1.1
+     */
+    public void removeExtraField( ZipShort type )
+    {
+        boolean done = false;
+        for ( int i = 0; !done && i < extraFields.size(); i++ )
+        {
+            if ( ( (ZipExtraField) extraFields.elementAt( i ) ).getHeaderId().equals( type ) )
+            {
+                extraFields.removeElementAt( i );
+                done = true;
+            }
+        }
+        if ( !done )
+        {
+            throw new java.util.NoSuchElementException();
+        }
+        setExtra();
+    }
+
+    /**
+     * Throws an Exception if extra data cannot be parsed into extra fields.
+     *
+     * @since 1.1
+     */
+    public void setExtra( byte[] extra )
+        throws RuntimeException
+    {
+        try
+        {
+            setExtraFields( ExtraFieldUtils.parse( extra ) );
+        }
+        catch ( Exception e )
+        {
+            throw new RuntimeException( e.getMessage() );
+        }
+    }
+
+    /**
+     * Unfortunately {@link java.util.zip.ZipOutputStream
+     * java.util.zip.ZipOutputStream} seems to access the extra data
+     * directly, so overriding getExtra doesn't help - we need to
+     * modify super's data directly.
+     *
+     * @since 1.1
+     */
+    protected void setExtra()
+    {
+        super.setExtra( ExtraFieldUtils.mergeLocalFileDataData( getExtraFields() ) );
+    }
+
+    /**
+     * Retrieves the extra data for the local file data.
+     *
+     * @since 1.1
+     */
+    public byte[] getLocalFileDataExtra()
+    {
+        byte[] extra = getExtra();
+        return extra != null ? extra : new byte[0];
+    }
+
+    /**
+     * Retrieves the extra data for the central directory.
+     *
+     * @since 1.1
+     */
+    public byte[] getCentralDirectoryExtra()
+    {
+        return ExtraFieldUtils.mergeCentralDirectoryData( getExtraFields() );
+    }
+
+    /**
+     * Helper for JDK 1.1 <-> 1.2 incompatibility.
+     *
+     * @since 1.2
+     */
+    private Long compressedSize = null;
+
+    /**
+     * Make this class work in JDK 1.1 like a 1.2 class.
+     * <p/>
+     * <p>This either stores the size for later usage or invokes
+     * setCompressedSize via reflection.</p>
+     *
+     * @since 1.2
+     */
+    public void setComprSize( long size )
+    {
+        if ( haveSetCompressedSize() )
+        {
+            performSetCompressedSize( this, size );
+        }
+        else
+        {
+            compressedSize = new Long( size );
+        }
+    }
+
+    /**
+     * Override to make this class work in JDK 1.1 like a 1.2 class.
+     *
+     * @since 1.2
+     */
+    public long getCompressedSize()
+    {
+        if ( compressedSize != null )
+        {
+            // has been set explicitly and we are running in a 1.1 VM
+            return compressedSize.longValue();
+        }
+        return super.getCompressedSize();
+    }
+
+    /**
+     * @since 1.9
+     */
+    public String getName()
+    {
+        return name == null ? super.getName() : name;
+    }
+
+    /**
+     * @since 1.10
+     */
+    public boolean isDirectory()
+    {
+        return getName().endsWith( "/" );
+    }
+
+    protected void setName( String name )
+    {
+        this.name = name;
+    }
+
+    /**
+     * Helper for JDK 1.1
+     *
+     * @since 1.2
+     */
+    private static Method setCompressedSizeMethod = null;
+
+    /**
+     * Helper for JDK 1.1
+     *
+     * @since 1.2
+     */
+    private final static Object lockReflection = new Object();
+
+    /**
+     * Helper for JDK 1.1
+     *
+     * @since 1.2
+     */
+    private static boolean triedToGetMethod = false;
+
+    /**
+     * Are we running JDK 1.2 or higher?
+     *
+     * @since 1.2
+     */
+    private static boolean haveSetCompressedSize()
+    {
+        checkSCS();
+        return setCompressedSizeMethod != null;
+    }
+
+    /**
+     * Invoke setCompressedSize via reflection.
+     *
+     * @since 1.2
+     */
+    private static void performSetCompressedSize( ZipEntry ze, long size )
+    {
+        Long[] s = {new Long( size )};
+        try
+        {
+            setCompressedSizeMethod.invoke( ze, s );
+        }
+        catch ( InvocationTargetException ite )
+        {
+            Throwable nested = ite.getTargetException();
+            throw new RuntimeException( "Exception setting the compressed size "
+                                        + "of " + ze + ": "
+                                        + nested.getMessage() );
+        }
+        catch ( Throwable other )
+        {
+            throw new RuntimeException( "Exception setting the compressed size "
+                                        + "of " + ze + ": "
+                                        + other.getMessage() );
+        }
+    }
+
+    /**
+     * Try to get a handle to the setCompressedSize method.
+     *
+     * @since 1.2
+     */
+    private static void checkSCS()
+    {
+        if ( !triedToGetMethod )
+        {
+            synchronized ( lockReflection )
+            {
+                triedToGetMethod = true;
+                try
+                {
+                    setCompressedSizeMethod =
+                        java.util.zip.ZipEntry.class.getMethod( "setCompressedSize",
+                                                                new Class[]{Long.TYPE} );
+                }
+                catch ( NoSuchMethodException nse )
+                {
+                    // ignored
+                }
+            }
+        }
+    }
+
+    public long getLastModificationTime()
+    {
+        return getTime();
+    }
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipEntry.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipEntry.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipExtraField.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipExtraField.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipExtraField.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipExtraField.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,83 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.zip;
+
+/*
+ * Copyright  2001,2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+import java.util.zip.ZipException;
+
+/**
+ * General format of extra field data.
+ * <p/>
+ * <p>Extra fields usually appear twice per file, once in the local
+ * file data and once in the central directory.  Usually they are the
+ * same, but they don't have to be.  {@link
+ * java.util.zip.ZipOutputStream java.util.zip.ZipOutputStream} will
+ * only use the local file data in both places.</p>
+ *
+ * @version $Revision$ $Date$
+ *          from org.apache.ant.tools.zip.ZipExtraField v1.9
+ */
+public interface ZipExtraField
+{
+
+    /**
+     * The Header-ID.
+     *
+     * @since 1.1
+     */
+    ZipShort getHeaderId();
+
+    /**
+     * Length of the extra field in the local file data - without
+     * Header-ID or length specifier.
+     *
+     * @since 1.1
+     */
+    ZipShort getLocalFileDataLength();
+
+    /**
+     * Length of the extra field in the central directory - without
+     * Header-ID or length specifier.
+     *
+     * @since 1.1
+     */
+    ZipShort getCentralDirectoryLength();
+
+    /**
+     * The actual data to put into local file data - without Header-ID
+     * or length specifier.
+     *
+     * @since 1.1
+     */
+    byte[] getLocalFileDataData();
+
+    /**
+     * The actual data to put central directory - without Header-ID or
+     * length specifier.
+     *
+     * @since 1.1
+     */
+    byte[] getCentralDirectoryData();
+
+    /**
+     * Populate data from this array as if it was in local file data.
+     *
+     * @since 1.1
+     */
+    void parseFromLocalFileData( byte[] data, int offset, int length )
+        throws ZipException;
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipExtraField.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipExtraField.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipExtraField.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipFile.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipFile.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipFile.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipFile.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,583 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.zip;
+
+/*
+ * Copyright  2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.RandomAccessFile;
+import java.io.UnsupportedEncodingException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.zip.Inflater;
+import java.util.zip.InflaterInputStream;
+import java.util.zip.ZipException;
+
+import org.apache.geronimo.system.plugin.plexus.archiver.ArchiveFile;
+
+/**
+ * Replacement for <code>java.util.ZipFile</code>.
+ * <p/>
+ * <p>This class adds support for file name encodings other than UTF-8
+ * (which is required to work on ZIP files created by native zip tools
+ * and is able to skip a preamble like the one found in self
+ * extracting archives.  Furthermore it returns instances of
+ * <code>org.apache.tools.zip.ZipEntry</code> instead of
+ * <code>java.util.zip.ZipEntry</code>.</p>
+ * <p/>
+ * <p>It doesn't extend <code>java.util.zip.ZipFile</code> as it would
+ * have to reimplement all methods anyway.  Like
+ * <code>java.util.ZipFile</code>, it uses RandomAccessFile under the
+ * covers and supports compressed and uncompressed entries.</p>
+ * <p/>
+ * <p>The method signatures mimic the ones of
+ * <code>java.util.zip.ZipFile</code>, with a couple of exceptions:
+ * <p/>
+ * <ul>
+ * <li>There is no getName method.</li>
+ * <li>entries has been renamed to getEntries.</li>
+ * <li>getEntries and getEntry return
+ * <code>org.apache.tools.zip.ZipEntry</code> instances.</li>
+ * <li>close is allowed to throw IOException.</li>
+ * </ul>
+ *
+ * @version $Revision$ $Date$
+ *          from org.apache.ant.tools.zip.ZipFile v1.13
+ */
+public class ZipFile implements ArchiveFile
+{
+
+    /**
+     * Maps ZipEntrys to Longs, recording the offsets of the local
+     * file headers.
+     */
+    private Hashtable entries = new Hashtable();
+
+    /**
+     * Maps String to ZipEntrys, name -> actual entry.
+     */
+    private Hashtable nameMap = new Hashtable();
+
+    /**
+     * Maps ZipEntrys to Longs, recording the offsets of the actual file data.
+     */
+    private Hashtable dataOffsets = new Hashtable();
+
+    /**
+     * The encoding to use for filenames and the file comment.
+     * <p/>
+     * <p>For a list of possible values see <a
+     * href="http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html">http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html</a>.
+     * Defaults to the platform's default character encoding.</p>
+     */
+    private String encoding = null;
+
+    /**
+     * The actual data source.
+     */
+    private RandomAccessFile archive;
+
+    /**
+     * Opens the given file for reading, assuming the platform's
+     * native encoding for file names.
+     *
+     * @param f the archive.
+     * @throws IOException if an error occurs while reading the file.
+     */
+    public ZipFile( File f )
+        throws IOException
+    {
+        this( f, null );
+    }
+
+    /**
+     * Opens the given file for reading, assuming the platform's
+     * native encoding for file names.
+     *
+     * @param name name of the archive.
+     * @throws IOException if an error occurs while reading the file.
+     */
+    public ZipFile( String name )
+        throws IOException
+    {
+        this( new File( name ), null );
+    }
+
+    /**
+     * Opens the given file for reading, assuming the specified
+     * encoding for file names.
+     *
+     * @param name     name of the archive.
+     * @param encoding the encoding to use for file names
+     * @throws IOException if an error occurs while reading the file.
+     */
+    public ZipFile( String name, String encoding )
+        throws IOException
+    {
+        this( new File( name ), encoding );
+    }
+
+    /**
+     * Opens the given file for reading, assuming the specified
+     * encoding for file names.
+     *
+     * @param f        the archive.
+     * @param encoding the encoding to use for file names
+     * @throws IOException if an error occurs while reading the file.
+     */
+    public ZipFile( File f, String encoding )
+        throws IOException
+    {
+        this.encoding = encoding;
+        archive = new RandomAccessFile( f, "r" );
+        populateFromCentralDirectory();
+        resolveLocalFileHeaderData();
+    }
+
+    /**
+     * The encoding to use for filenames and the file comment.
+     *
+     * @return null if using the platform's default character encoding.
+     */
+    public String getEncoding()
+    {
+        return encoding;
+    }
+
+    /**
+     * Closes the archive.
+     *
+     * @throws IOException if an error occurs closing the archive.
+     */
+    public void close()
+        throws IOException
+    {
+        archive.close();
+    }
+
+    /**
+     * Returns all entries.
+     *
+     * @return all entries as {@link ZipEntry} instances
+     */
+    public Enumeration getEntries()
+    {
+        return entries.keys();
+    }
+
+    /**
+     * Returns a named entry - or <code>null</code> if no entry by
+     * that name exists.
+     *
+     * @param name name of the entry.
+     * @return the ZipEntry corresponding to the given name - or
+     *         <code>null</code> if not present.
+     */
+    public ZipEntry getEntry( String name )
+    {
+        return (ZipEntry) nameMap.get( name );
+    }
+
+    public InputStream getInputStream( ArchiveFile.Entry entry )
+        throws IOException
+    {
+        return getInputStream( (ZipEntry) entry );
+    }
+
+    /**
+     * Returns an InputStream for reading the contents of the given entry.
+     *
+     * @param ze the entry to get the stream for.
+     * @return a stream to read the entry from.
+     */
+    public InputStream getInputStream( ZipEntry ze )
+        throws IOException, ZipException
+    {
+        Long start = (Long) dataOffsets.get( ze );
+        if ( start == null )
+        {
+            return null;
+        }
+        BoundedInputStream bis =
+            new BoundedInputStream( start.longValue(), ze.getCompressedSize() );
+        switch ( ze.getMethod() )
+        {
+            case ZipEntry.STORED:
+                return bis;
+            case ZipEntry.DEFLATED:
+                bis.addDummy();
+                return new InflaterInputStream( bis, new Inflater( true ) );
+            default:
+                throw new ZipException( "Found unsupported compression method "
+                                        + ze.getMethod() );
+        }
+    }
+
+    private static final int CFH_LEN =
+        /* version made by                 */ 2 +
+                                              /* version needed to extract       */ 2 +
+                                              /* general purpose bit flag        */ 2 +
+                                              /* compression method              */ 2 +
+                                              /* last mod file time              */ 2 +
+                                              /* last mod file date              */ 2 +
+                                              /* crc-32                          */ 4 +
+                                              /* compressed size                 */ 4 +
+                                              /* uncompressed size               */ 4 +
+                                              /* filename length                 */ 2 +
+                                              /* extra field length              */ 2 +
+                                              /* file comment length             */ 2 +
+                                              /* disk number start               */ 2 +
+                                              /* internal file attributes        */ 2 +
+                                              /* external file attributes        */ 4 +
+                                              /* relative offset of local header */ 4;
+
+    /**
+     * Reads the central directory of the given archive and populates
+     * the internal tables with ZipEntry instances.
+     * <p/>
+     * <p>The ZipEntrys will know all data that can be obtained from
+     * the central directory alone, but not the data that requires the
+     * local file header or additional data to be read.</p>
+     */
+    private void populateFromCentralDirectory()
+        throws IOException
+    {
+        positionAtCentralDirectory();
+
+        byte[] cfh = new byte[CFH_LEN];
+
+        byte[] signatureBytes = new byte[4];
+        archive.readFully( signatureBytes );
+        ZipLong sig = new ZipLong( signatureBytes );
+        while ( sig.equals( ZipOutputStream.CFH_SIG ) )
+        {
+            archive.readFully( cfh );
+            int off = 0;
+            ZipEntry ze = new ZipEntry();
+
+            ZipShort versionMadeBy = new ZipShort( cfh, off );
+            off += 2;
+            ze.setPlatform( ( versionMadeBy.getValue() >> 8 ) & 0x0F );
+
+            off += 4; // skip version info and general purpose byte
+
+            ze.setMethod( ( new ZipShort( cfh, off ) ).getValue() );
+            off += 2;
+
+            ze.setTime( fromDosTime( new ZipLong( cfh, off ) ).getTime() );
+            off += 4;
+
+            ze.setCrc( ( new ZipLong( cfh, off ) ).getValue() );
+            off += 4;
+
+            ze.setCompressedSize( ( new ZipLong( cfh, off ) ).getValue() );
+            off += 4;
+
+            ze.setSize( ( new ZipLong( cfh, off ) ).getValue() );
+            off += 4;
+
+            int fileNameLen = ( new ZipShort( cfh, off ) ).getValue();
+            off += 2;
+
+            int extraLen = ( new ZipShort( cfh, off ) ).getValue();
+            off += 2;
+
+            int commentLen = ( new ZipShort( cfh, off ) ).getValue();
+            off += 2;
+
+            off += 2; // disk number
+
+            ze.setInternalAttributes( ( new ZipShort( cfh, off ) ).getValue() );
+            off += 2;
+
+            ze.setExternalAttributes( ( new ZipLong( cfh, off ) ).getValue() );
+            off += 4;
+
+            // LFH offset
+            entries.put( ze, new Long( ( new ZipLong( cfh, off ) ).getValue() ) );
+
+            byte[] fileName = new byte[fileNameLen];
+            archive.readFully( fileName );
+            ze.setName( getString( fileName ) );
+
+            nameMap.put( ze.getName(), ze );
+
+            archive.skipBytes( extraLen );
+
+            byte[] comment = new byte[commentLen];
+            archive.readFully( comment );
+            ze.setComment( getString( comment ) );
+
+            archive.readFully( signatureBytes );
+            sig = new ZipLong( signatureBytes );
+        }
+    }
+
+    private static final int MIN_EOCD_SIZE =
+        /* end of central dir signature    */ 4 +
+                                              /* number of this disk             */ 2 +
+                                              /* number of the disk with the     */   +
+        /* start of the central directory  */ 2 +
+                                                /* total number of entries in      */   +
+        /* the central dir on this disk    */ 2 +
+                                                /* total number of entries in      */   +
+        /* the central dir                 */ 2 +
+                                                /* size of the central directory   */ 4 +
+                                                /* offset of start of central      */   +
+        /* directory with respect to       */   +
+        /* the starting disk number        */ 4 +
+                                                /* zipfile comment length          */ 2;
+
+    private static final int CFD_LOCATOR_OFFSET =
+        /* end of central dir signature    */ 4 +
+                                              /* number of this disk             */ 2 +
+                                              /* number of the disk with the     */   +
+        /* start of the central directory  */ 2 +
+                                                /* total number of entries in      */   +
+        /* the central dir on this disk    */ 2 +
+                                                /* total number of entries in      */   +
+        /* the central dir                 */ 2 +
+                                                /* size of the central directory   */ 4;
+
+    /**
+     * Searches for the &quot;End of central dir record&quot;, parses
+     * it and positions the stream at the first central directory
+     * record.
+     */
+    private void positionAtCentralDirectory()
+        throws IOException
+    {
+        long off = archive.length() - MIN_EOCD_SIZE;
+        archive.seek( off );
+        byte[] sig = ZipOutputStream.EOCD_SIG.getBytes();
+        int curr = archive.read();
+        boolean found = false;
+        while ( curr != -1 )
+        {
+            if ( curr == sig[ 0 ] )
+            {
+                curr = archive.read();
+                if ( curr == sig[ 1 ] )
+                {
+                    curr = archive.read();
+                    if ( curr == sig[ 2 ] )
+                    {
+                        curr = archive.read();
+                        if ( curr == sig[ 3 ] )
+                        {
+                            found = true;
+                            break;
+                        }
+                    }
+                }
+            }
+            archive.seek( --off );
+            curr = archive.read();
+        }
+        if ( !found )
+        {
+            throw new ZipException( "archive is not a ZIP archive" );
+        }
+        archive.seek( off + CFD_LOCATOR_OFFSET );
+        byte[] cfdOffset = new byte[4];
+        archive.readFully( cfdOffset );
+        archive.seek( ( new ZipLong( cfdOffset ) ).getValue() );
+    }
+
+    /**
+     * Number of bytes in local file header up to the &quot;length of
+     * filename&quot; entry.
+     */
+    private static final long LFH_OFFSET_FOR_FILENAME_LENGTH =
+        /* local file header signature     */ 4 +
+                                              /* version needed to extract       */ 2 +
+                                              /* general purpose bit flag        */ 2 +
+                                              /* compression method              */ 2 +
+                                              /* last mod file time              */ 2 +
+                                              /* last mod file date              */ 2 +
+                                              /* crc-32                          */ 4 +
+                                              /* compressed size                 */ 4 +
+                                              /* uncompressed size               */ 4;
+
+    /**
+     * Walks through all recorded entries and adds the data available
+     * from the local file header.
+     * <p/>
+     * <p>Also records the offsets for the data to read from the
+     * entries.</p>
+     */
+    private void resolveLocalFileHeaderData()
+        throws IOException
+    {
+        Enumeration e = getEntries();
+        while ( e.hasMoreElements() )
+        {
+            ZipEntry ze = (ZipEntry) e.nextElement();
+            long offset = ( (Long) entries.get( ze ) ).longValue();
+            archive.seek( offset + LFH_OFFSET_FOR_FILENAME_LENGTH );
+            byte[] b = new byte[2];
+            archive.readFully( b );
+            int fileNameLen = ( new ZipShort( b ) ).getValue();
+            archive.readFully( b );
+            int extraFieldLen = ( new ZipShort( b ) ).getValue();
+            archive.skipBytes( fileNameLen );
+            byte[] localExtraData = new byte[extraFieldLen];
+            archive.readFully( localExtraData );
+            ze.setExtra( localExtraData );
+            dataOffsets.put( ze,
+                             new Long( offset + LFH_OFFSET_FOR_FILENAME_LENGTH
+                                       + 2 + 2 + fileNameLen + extraFieldLen ) );
+        }
+    }
+
+    /**
+     * Convert a DOS date/time field to a Date object.
+     *
+     * @param l contains the stored DOS time.
+     * @return a Date instance corresponding to the given time.
+     */
+    protected static Date fromDosTime( ZipLong l )
+    {
+        long dosTime = l.getValue();
+        Calendar cal = Calendar.getInstance();
+        cal.set( Calendar.YEAR, (int) ( ( dosTime >> 25 ) & 0x7f ) + 1980 );
+        cal.set( Calendar.MONTH, (int) ( ( dosTime >> 21 ) & 0x0f ) - 1 );
+        cal.set( Calendar.DATE, (int) ( dosTime >> 16 ) & 0x1f );
+        cal.set( Calendar.HOUR_OF_DAY, (int) ( dosTime >> 11 ) & 0x1f );
+        cal.set( Calendar.MINUTE, (int) ( dosTime >> 5 ) & 0x3f );
+        cal.set( Calendar.SECOND, (int) ( dosTime << 1 ) & 0x3e );
+        return cal.getTime();
+    }
+
+    /**
+     * Retrieve a String from the given bytes using the encoding set
+     * for this ZipFile.
+     *
+     * @param bytes the byte array to transform
+     * @return String obtained by using the given encoding
+     * @throws ZipException if the encoding cannot be recognized.
+     */
+    protected String getString( byte[] bytes )
+        throws ZipException
+    {
+        if ( encoding == null )
+        {
+            return new String( bytes );
+        }
+        else
+        {
+            try
+            {
+                return new String( bytes, encoding );
+            }
+            catch ( UnsupportedEncodingException uee )
+            {
+                throw new ZipException( uee.getMessage() );
+            }
+        }
+    }
+
+    /**
+     * InputStream that delegates requests to the underlying
+     * RandomAccessFile, making sure that only bytes from a certain
+     * range can be read.
+     */
+    private class BoundedInputStream
+        extends InputStream
+    {
+        private long remaining;
+
+        private long loc;
+
+        private boolean addDummyByte = false;
+
+        BoundedInputStream( long start, long remaining )
+        {
+            this.remaining = remaining;
+            loc = start;
+        }
+
+        public int read()
+            throws IOException
+        {
+            if ( remaining-- <= 0 )
+            {
+                if ( addDummyByte )
+                {
+                    addDummyByte = false;
+                    return 0;
+                }
+                return -1;
+            }
+            synchronized ( archive )
+            {
+                archive.seek( loc++ );
+                return archive.read();
+            }
+        }
+
+        public int read( byte[] b, int off, int len )
+            throws IOException
+        {
+            if ( remaining <= 0 )
+            {
+                if ( addDummyByte )
+                {
+                    addDummyByte = false;
+                    b[ off ] = 0;
+                    return 1;
+                }
+                return -1;
+            }
+
+            if ( len <= 0 )
+            {
+                return 0;
+            }
+
+            if ( len > remaining )
+            {
+                len = (int) remaining;
+            }
+            int ret;
+            synchronized ( archive )
+            {
+                archive.seek( loc );
+                ret = archive.read( b, off, len );
+            }
+            if ( ret > 0 )
+            {
+                loc += ret;
+                remaining -= ret;
+            }
+            return ret;
+        }
+
+        /**
+         * Inflater needs an extra dummy byte for nowrap - see
+         * Inflater's javadocs.
+         */
+        void addDummy()
+        {
+            addDummyByte = true;
+        }
+    }
+
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipFile.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipFile.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipFile.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipLong.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipLong.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipLong.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipLong.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,114 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.zip;
+
+/*
+ * Copyright  2001-2002,2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+/**
+ * Utility class that represents a four byte integer with conversion
+ * rules for the big endian byte order of ZIP files.
+ *
+ * @version $Revision$ $Date$
+ *          from org.apache.ant.tools.zip.ZipLong v1.10
+ */
+public final class ZipLong
+    implements Cloneable
+{
+
+    private long value;
+
+    /**
+     * Create instance from a number.
+     *
+     * @since 1.1
+     */
+    public ZipLong( long value )
+    {
+        this.value = value;
+    }
+
+    /**
+     * Create instance from bytes.
+     *
+     * @since 1.1
+     */
+    public ZipLong( byte[] bytes )
+    {
+        this( bytes, 0 );
+    }
+
+    /**
+     * Create instance from the four bytes starting at offset.
+     *
+     * @since 1.1
+     */
+    public ZipLong( byte[] bytes, int offset )
+    {
+        value = ( bytes[ offset + 3 ] << 24 ) & 0xFF000000L;
+        value += ( bytes[ offset + 2 ] << 16 ) & 0xFF0000;
+        value += ( bytes[ offset + 1 ] << 8 ) & 0xFF00;
+        value += ( bytes[ offset ] & 0xFF );
+    }
+
+    /**
+     * Get value as two bytes in big endian byte order.
+     *
+     * @since 1.1
+     */
+    public byte[] getBytes()
+    {
+        byte[] result = new byte[4];
+        result[ 0 ] = (byte) ( ( value & 0xFF ) );
+        result[ 1 ] = (byte) ( ( value & 0xFF00 ) >> 8 );
+        result[ 2 ] = (byte) ( ( value & 0xFF0000 ) >> 16 );
+        result[ 3 ] = (byte) ( ( value & 0xFF000000l ) >> 24 );
+        return result;
+    }
+
+    /**
+     * Get value as Java int.
+     *
+     * @since 1.1
+     */
+    public long getValue()
+    {
+        return value;
+    }
+
+    /**
+     * Override to make two instances with same value equal.
+     *
+     * @since 1.1
+     */
+    public boolean equals( Object o )
+    {
+        if ( o == null || !( o instanceof ZipLong ) )
+        {
+            return false;
+        }
+        return value == ( (ZipLong) o ).getValue();
+    }
+
+    /**
+     * Override to make two instances with same value equal.
+     *
+     * @since 1.1
+     */
+    public int hashCode()
+    {
+        return (int) value;
+    }
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipLong.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipLong.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipLong.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message