geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r821961 [12/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/ZipOutputStream.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/ZipOutputStream.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipOutputStream.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipOutputStream.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,932 @@
+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.io.File;
+import java.io.FileOutputStream;
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.RandomAccessFile;
+import java.io.UnsupportedEncodingException;
+import java.util.Date;
+import java.util.Hashtable;
+import java.util.Vector;
+import java.util.zip.CRC32;
+import java.util.zip.Deflater;
+import java.util.zip.ZipException;
+
+/**
+ * Reimplementation of {@link java.util.zip.ZipOutputStream
+ * java.util.zip.ZipOutputStream} that does handle the extended
+ * functionality of this package, especially internal/external file
+ * attributes and extra fields with different layouts for local file
+ * data and central directory entries.
+ * <p/>
+ * <p>This class will try to use {@link java.io.RandomAccessFile
+ * RandomAccessFile} when you know that the output is going to go to a
+ * file.</p>
+ * <p/>
+ * <p>If RandomAccessFile cannot be used, this implementation will use
+ * a Data Descriptor to store size and CRC information for {@link
+ * #DEFLATED DEFLATED} entries, this means, you don't need to
+ * calculate them yourself.  Unfortunately this is not possible for
+ * the {@link #STORED STORED} method, here setting the CRC and
+ * uncompressed size information is required before {@link
+ * #putNextEntry putNextEntry} can be called.</p>
+ *
+ * @version $Revision$ $Date$
+ *          from org.apache.ant.tools.zip.ZipOutputStream v1.24
+ */
+public class ZipOutputStream
+    extends FilterOutputStream
+{
+
+    /**
+     * Current entry.
+     *
+     * @since 1.1
+     */
+    private ZipEntry entry;
+
+    /**
+     * The file comment.
+     *
+     * @since 1.1
+     */
+    private String comment = "";
+
+    /**
+     * Compression level for next entry.
+     *
+     * @since 1.1
+     */
+    private int level = Deflater.DEFAULT_COMPRESSION;
+
+    /**
+     * Has the compression level changed when compared to the last
+     * entry?
+     *
+     * @since 1.5
+     */
+    private boolean hasCompressionLevelChanged = false;
+
+    /**
+     * Default compression method for next entry.
+     *
+     * @since 1.1
+     */
+    private int method = DEFLATED;
+
+    /**
+     * List of ZipEntries written so far.
+     *
+     * @since 1.1
+     */
+    private Vector entries = new Vector();
+
+    /**
+     * CRC instance to avoid parsing DEFLATED data twice.
+     *
+     * @since 1.1
+     */
+    private CRC32 crc = new CRC32();
+
+    /**
+     * Count the bytes written to out.
+     *
+     * @since 1.1
+     */
+    private long written = 0;
+
+    /**
+     * Data for local header data
+     *
+     * @since 1.1
+     */
+    private long dataStart = 0;
+
+    /**
+     * Offset for CRC entry in the local file header data for the
+     * current entry starts here.
+     *
+     * @since 1.15
+     */
+    private long localDataStart = 0;
+
+    /**
+     * Start of central directory.
+     *
+     * @since 1.1
+     */
+    private ZipLong cdOffset = new ZipLong( 0 );
+
+    /**
+     * Length of central directory.
+     *
+     * @since 1.1
+     */
+    private ZipLong cdLength = new ZipLong( 0 );
+
+    /**
+     * Helper, a 0 as ZipShort.
+     *
+     * @since 1.1
+     */
+    private static final byte[] ZERO = {0, 0};
+
+    /**
+     * Helper, a 0 as ZipLong.
+     *
+     * @since 1.1
+     */
+    private static final byte[] LZERO = {0, 0, 0, 0};
+
+    /**
+     * Holds the offsets of the LFH starts for each entry.
+     *
+     * @since 1.1
+     */
+    private Hashtable offsets = 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>
+     *
+     * @since 1.3
+     */
+    private String encoding = null;
+
+    /**
+     * This Deflater object is used for output.
+     * <p/>
+     * <p>This attribute is only protected to provide a level of API
+     * backwards compatibility.  This class used to extend {@link
+     * java.util.zip.DeflaterOutputStream DeflaterOutputStream} up to
+     * Revision 1.13.</p>
+     *
+     * @since 1.14
+     */
+    protected Deflater def = new Deflater( Deflater.DEFAULT_COMPRESSION, true );
+
+    /**
+     * This buffer servers as a Deflater.
+     * <p/>
+     * <p>This attribute is only protected to provide a level of API
+     * backwards compatibility.  This class used to extend {@link
+     * java.util.zip.DeflaterOutputStream DeflaterOutputStream} up to
+     * Revision 1.13.</p>
+     *
+     * @since 1.14
+     */
+    protected byte[] buf = new byte[512];
+
+    /**
+     * Optional random access output.
+     *
+     * @since 1.14
+     */
+    private RandomAccessFile raf = null;
+
+    /**
+     * Compression method for deflated entries.
+     *
+     * @since 1.1
+     */
+    public static final int DEFLATED = ZipEntry.DEFLATED;
+
+    /**
+     * Compression method for deflated entries.
+     *
+     * @since 1.1
+     */
+    public static final int STORED = ZipEntry.STORED;
+
+    /**
+     * Creates a new ZIP OutputStream filtering the underlying stream.
+     *
+     * @since 1.1
+     */
+    public ZipOutputStream( OutputStream out )
+    {
+        super( out );
+    }
+
+    /**
+     * Creates a new ZIP OutputStream writing to a File.  Will use
+     * random access if possible.
+     *
+     * @since 1.14
+     */
+    public ZipOutputStream( File file )
+        throws IOException
+    {
+        super( null );
+
+        try
+        {
+            raf = new RandomAccessFile( file, "rw" );
+            raf.setLength( 0 );
+        }
+        catch ( IOException e )
+        {
+            if ( raf != null )
+            {
+                try
+                {
+                    raf.close();
+                }
+                catch ( IOException inner )
+                {
+                    // ignore
+                }
+                raf = null;
+            }
+            out = new FileOutputStream( file );
+        }
+    }
+
+    /**
+     * This method indicates whether this archive is writing to a seekable stream (i.e., to a random
+     * access file).
+     * <p/>
+     * <p>For seekable streams, you don't need to calculate the CRC or
+     * uncompressed size for {@link #STORED} entries before
+     * invoking {@link #putNextEntry}.
+     *
+     * @since 1.17
+     */
+    public boolean isSeekable()
+    {
+        return raf != null;
+    }
+
+    /**
+     * 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>
+     *
+     * @since 1.3
+     */
+    public void setEncoding( String encoding )
+    {
+        this.encoding = encoding;
+    }
+
+    /**
+     * The encoding to use for filenames and the file comment.
+     *
+     * @return null if using the platform's default character encoding.
+     * @since 1.3
+     */
+    public String getEncoding()
+    {
+        return encoding;
+    }
+
+    /**
+     * Finishs writing the contents and closes this as well as the
+     * underlying stream.
+     *
+     * @since 1.1
+     */
+    public void finish()
+        throws IOException
+    {
+        closeEntry();
+        cdOffset = new ZipLong( written );
+        for ( int i = 0; i < entries.size(); i++ )
+        {
+            writeCentralFileHeader( (ZipEntry) entries.elementAt( i ) );
+        }
+        cdLength = new ZipLong( written - cdOffset.getValue() );
+        writeCentralDirectoryEnd();
+        offsets.clear();
+        entries.removeAllElements();
+    }
+
+    /**
+     * Writes all necessary data for this entry.
+     *
+     * @since 1.1
+     */
+    public void closeEntry()
+        throws IOException
+    {
+        if ( entry == null )
+        {
+            return;
+        }
+
+        long realCrc = crc.getValue();
+        crc.reset();
+
+        if ( entry.getMethod() == DEFLATED )
+        {
+            def.finish();
+            while ( !def.finished() )
+            {
+                deflate();
+            }
+
+            entry.setSize( def.getTotalIn() );
+            entry.setComprSize( def.getTotalOut() );
+            entry.setCrc( realCrc );
+
+            def.reset();
+
+            written += entry.getCompressedSize();
+        }
+        else if ( raf == null )
+        {
+            if ( entry.getCrc() != realCrc )
+            {
+                throw new ZipException( "bad CRC checksum for entry "
+                                        + entry.getName() + ": "
+                                        + Long.toHexString( entry.getCrc() )
+                                        + " instead of "
+                                        + Long.toHexString( realCrc ) );
+            }
+
+            if ( entry.getSize() != written - dataStart )
+            {
+                throw new ZipException( "bad size for entry "
+                                        + entry.getName() + ": "
+                                        + entry.getSize()
+                                        + " instead of "
+                                        + ( written - dataStart ) );
+            }
+        }
+        else
+        { /* method is STORED and we used RandomAccessFile */
+            long size = written - dataStart;
+
+            entry.setSize( size );
+            entry.setComprSize( size );
+            entry.setCrc( realCrc );
+        }
+
+        // If random access output, write the local file header containing
+        // the correct CRC and compressed/uncompressed sizes
+        if ( raf != null )
+        {
+            long save = raf.getFilePointer();
+
+            raf.seek( localDataStart );
+            writeOut( ( new ZipLong( entry.getCrc() ) ).getBytes() );
+            writeOut( ( new ZipLong( entry.getCompressedSize() ) ).getBytes() );
+            writeOut( ( new ZipLong( entry.getSize() ) ).getBytes() );
+            raf.seek( save );
+        }
+
+        writeDataDescriptor( entry );
+        entry = null;
+    }
+
+    /**
+     * Begin writing next entry.
+     *
+     * @since 1.1
+     */
+    public void putNextEntry( ZipEntry ze )
+        throws IOException
+    {
+        closeEntry();
+
+        entry = ze;
+        entries.addElement( entry );
+
+        if ( entry.getMethod() == -1 )
+        { // not specified
+            entry.setMethod( method );
+        }
+
+        if ( entry.getTime() == -1 )
+        { // not specified
+            entry.setTime( System.currentTimeMillis() );
+        }
+
+        // Size/CRC not required if RandomAccessFile is used
+        if ( entry.getMethod() == STORED && raf == null )
+        {
+            if ( entry.getSize() == -1 )
+            {
+                throw new ZipException( "uncompressed size is required for"
+                                        + " STORED method when not writing to a"
+                                        + " file" );
+            }
+            if ( entry.getCrc() == -1 )
+            {
+                throw new ZipException( "crc checksum is required for STORED"
+                                        + " method when not writing to a file" );
+            }
+            entry.setComprSize( entry.getSize() );
+        }
+
+        if ( entry.getMethod() == DEFLATED && hasCompressionLevelChanged )
+        {
+            def.setLevel( level );
+            hasCompressionLevelChanged = false;
+        }
+        writeLocalFileHeader( entry );
+    }
+
+    /**
+     * Set the file comment.
+     *
+     * @since 1.1
+     */
+    public void setComment( String comment )
+    {
+        this.comment = comment;
+    }
+
+    /**
+     * Sets the compression level for subsequent entries.
+     * <p/>
+     * <p>Default is Deflater.DEFAULT_COMPRESSION.</p>
+     *
+     * @since 1.1
+     */
+    public void setLevel( int level )
+    {
+        hasCompressionLevelChanged = ( this.level != level );
+        this.level = level;
+    }
+
+    /**
+     * Sets the default compression method for subsequent entries.
+     * <p/>
+     * <p>Default is DEFLATED.</p>
+     *
+     * @since 1.1
+     */
+    public void setMethod( int method )
+    {
+        this.method = method;
+    }
+
+    /**
+     * Writes bytes to ZIP entry.
+     */
+    public void write( byte[] b, int offset, int length )
+        throws IOException
+    {
+        if ( entry.getMethod() == DEFLATED )
+        {
+            if ( length > 0 )
+            {
+                if ( !def.finished() )
+                {
+                    def.setInput( b, offset, length );
+                    while ( !def.needsInput() )
+                    {
+                        deflate();
+                    }
+                }
+            }
+        }
+        else
+        {
+            writeOut( b, offset, length );
+            written += length;
+        }
+        crc.update( b, offset, length );
+    }
+
+    /**
+     * Writes a single byte to ZIP entry.
+     * <p/>
+     * <p>Delegates to the three arg method.</p>
+     *
+     * @since 1.14
+     */
+    public void write( int b )
+        throws IOException
+    {
+        byte[] buf = new byte[1];
+        buf[ 0 ] = (byte) ( b & 0xff );
+        write( buf, 0, 1 );
+    }
+
+    /**
+     * Closes this output stream and releases any system resources
+     * associated with the stream.
+     *
+     * @throws IOException if an I/O error occurs.
+     * @since 1.14
+     */
+    public void close()
+        throws IOException
+    {
+        finish();
+
+        if ( raf != null )
+        {
+            raf.close();
+        }
+        if ( out != null )
+        {
+            out.close();
+        }
+    }
+
+    /**
+     * Flushes this output stream and forces any buffered output bytes
+     * to be written out to the stream.
+     *
+     * @throws IOException if an I/O error occurs.
+     * @since 1.14
+     */
+    public void flush()
+        throws IOException
+    {
+        if ( out != null )
+        {
+            out.flush();
+        }
+    }
+
+    /*
+     * Various ZIP constants
+     */
+
+    /**
+     * local file header signature
+     *
+     * @since 1.1
+     */
+    protected static final ZipLong LFH_SIG = new ZipLong( 0X04034B50L );
+
+    /**
+     * data descriptor signature
+     *
+     * @since 1.1
+     */
+    protected static final ZipLong DD_SIG = new ZipLong( 0X08074B50L );
+
+    /**
+     * central file header signature
+     *
+     * @since 1.1
+     */
+    protected static final ZipLong CFH_SIG = new ZipLong( 0X02014B50L );
+
+    /**
+     * end of central dir signature
+     *
+     * @since 1.1
+     */
+    protected static final ZipLong EOCD_SIG = new ZipLong( 0X06054B50L );
+
+    /**
+     * Writes next block of compressed data to the output stream.
+     *
+     * @since 1.14
+     */
+    protected final void deflate()
+        throws IOException
+    {
+        int len = def.deflate( buf, 0, buf.length );
+        if ( len > 0 )
+        {
+            writeOut( buf, 0, len );
+        }
+    }
+
+    /**
+     * Writes the local file header entry
+     *
+     * @since 1.1
+     */
+    protected void writeLocalFileHeader( ZipEntry ze )
+        throws IOException
+    {
+        offsets.put( ze, new ZipLong( written ) );
+
+        writeOut( LFH_SIG.getBytes() );
+        written += 4;
+
+        // version needed to extract
+        // general purpose bit flag
+        if ( ze.getMethod() == DEFLATED && raf == null )
+        {
+            // requires version 2 as we are going to store length info
+            // in the data descriptor
+            writeOut( ( new ZipShort( 20 ) ).getBytes() );
+
+            // bit3 set to signal, we use a data descriptor
+            writeOut( ( new ZipShort( 8 ) ).getBytes() );
+        }
+        else
+        {
+            writeOut( ( new ZipShort( 10 ) ).getBytes() );
+            writeOut( ZERO );
+        }
+        written += 4;
+
+        // compression method
+        writeOut( ( new ZipShort( ze.getMethod() ) ).getBytes() );
+        written += 2;
+
+        // last mod. time and date
+        writeOut( toDosTime( new Date( ze.getTime() ) ).getBytes() );
+        written += 4;
+
+        // CRC
+        // compressed length
+        // uncompressed length
+        localDataStart = written;
+        if ( ze.getMethod() == DEFLATED || raf != null )
+        {
+            writeOut( LZERO );
+            writeOut( LZERO );
+            writeOut( LZERO );
+        }
+        else
+        {
+            writeOut( ( new ZipLong( ze.getCrc() ) ).getBytes() );
+            writeOut( ( new ZipLong( ze.getSize() ) ).getBytes() );
+            writeOut( ( new ZipLong( ze.getSize() ) ).getBytes() );
+        }
+        written += 12;
+
+        // file name length
+        byte[] name = getBytes( ze.getName() );
+        writeOut( ( new ZipShort( name.length ) ).getBytes() );
+        written += 2;
+
+        // extra field length
+        byte[] extra = ze.getLocalFileDataExtra();
+        writeOut( ( new ZipShort( extra.length ) ).getBytes() );
+        written += 2;
+
+        // file name
+        writeOut( name );
+        written += name.length;
+
+        // extra field
+        writeOut( extra );
+        written += extra.length;
+
+        dataStart = written;
+    }
+
+    /**
+     * Writes the data descriptor entry
+     *
+     * @since 1.1
+     */
+    protected void writeDataDescriptor( ZipEntry ze )
+        throws IOException
+    {
+        if ( ze.getMethod() != DEFLATED || raf != null )
+        {
+            return;
+        }
+        writeOut( DD_SIG.getBytes() );
+        writeOut( ( new ZipLong( entry.getCrc() ) ).getBytes() );
+        writeOut( ( new ZipLong( entry.getCompressedSize() ) ).getBytes() );
+        writeOut( ( new ZipLong( entry.getSize() ) ).getBytes() );
+        written += 16;
+    }
+
+    /**
+     * Writes the central file header entry
+     *
+     * @since 1.1
+     */
+    protected void writeCentralFileHeader( ZipEntry ze )
+        throws IOException
+    {
+        writeOut( CFH_SIG.getBytes() );
+        written += 4;
+
+        // version made by
+        writeOut( ( new ZipShort( ( ze.getPlatform() << 8 ) | 20 ) ).getBytes() );
+        written += 2;
+
+        // version needed to extract
+        // general purpose bit flag
+        if ( ze.getMethod() == DEFLATED && raf == null )
+        {
+            // requires version 2 as we are going to store length info
+            // in the data descriptor
+            writeOut( ( new ZipShort( 20 ) ).getBytes() );
+
+            // bit3 set to signal, we use a data descriptor
+            writeOut( ( new ZipShort( 8 ) ).getBytes() );
+        }
+        else
+        {
+            writeOut( ( new ZipShort( 10 ) ).getBytes() );
+            writeOut( ZERO );
+        }
+        written += 4;
+
+        // compression method
+        writeOut( ( new ZipShort( ze.getMethod() ) ).getBytes() );
+        written += 2;
+
+        // last mod. time and date
+        writeOut( toDosTime( new Date( ze.getTime() ) ).getBytes() );
+        written += 4;
+
+        // CRC
+        // compressed length
+        // uncompressed length
+        writeOut( ( new ZipLong( ze.getCrc() ) ).getBytes() );
+        writeOut( ( new ZipLong( ze.getCompressedSize() ) ).getBytes() );
+        writeOut( ( new ZipLong( ze.getSize() ) ).getBytes() );
+        written += 12;
+
+        // file name length
+        byte[] name = getBytes( ze.getName() );
+        writeOut( ( new ZipShort( name.length ) ).getBytes() );
+        written += 2;
+
+        // extra field length
+        byte[] extra = ze.getCentralDirectoryExtra();
+        writeOut( ( new ZipShort( extra.length ) ).getBytes() );
+        written += 2;
+
+        // file comment length
+        String comm = ze.getComment();
+        if ( comm == null )
+        {
+            comm = "";
+        }
+        byte[] comment = getBytes( comm );
+        writeOut( ( new ZipShort( comment.length ) ).getBytes() );
+        written += 2;
+
+        // disk number start
+        writeOut( ZERO );
+        written += 2;
+
+        // internal file attributes
+        writeOut( ( new ZipShort( ze.getInternalAttributes() ) ).getBytes() );
+        written += 2;
+
+        // external file attributes
+        writeOut( ( new ZipLong( ze.getExternalAttributes() ) ).getBytes() );
+        written += 4;
+
+        // relative offset of LFH
+        writeOut( ( (ZipLong) offsets.get( ze ) ).getBytes() );
+        written += 4;
+
+        // file name
+        writeOut( name );
+        written += name.length;
+
+        // extra field
+        writeOut( extra );
+        written += extra.length;
+
+        // file comment
+        writeOut( comment );
+        written += comment.length;
+    }
+
+    /**
+     * Writes the &quot;End of central dir record&quot;
+     *
+     * @since 1.1
+     */
+    protected void writeCentralDirectoryEnd()
+        throws IOException
+    {
+        writeOut( EOCD_SIG.getBytes() );
+
+        // disk numbers
+        writeOut( ZERO );
+        writeOut( ZERO );
+
+        // number of entries
+        byte[] num = ( new ZipShort( entries.size() ) ).getBytes();
+        writeOut( num );
+        writeOut( num );
+
+        // length and location of CD
+        writeOut( cdLength.getBytes() );
+        writeOut( cdOffset.getBytes() );
+
+        // ZIP file comment
+        byte[] data = getBytes( comment );
+        writeOut( ( new ZipShort( data.length ) ).getBytes() );
+        writeOut( data );
+    }
+
+    /**
+     * Smallest date/time ZIP can handle.
+     *
+     * @since 1.1
+     */
+    private static final ZipLong DOS_TIME_MIN = new ZipLong( 0x00002100L );
+
+    /**
+     * Convert a Date object to a DOS date/time field.
+     * <p/>
+     * <p>Stolen from InfoZip's <code>fileio.c</code></p>
+     *
+     * @since 1.1
+     */
+    protected static ZipLong toDosTime( Date time )
+    {
+        int year = time.getYear() + 1900;
+        int month = time.getMonth() + 1;
+        if ( year < 1980 )
+        {
+            return DOS_TIME_MIN;
+        }
+        long value = ( ( year - 1980 ) << 25 )
+                     | ( month << 21 )
+                     | ( time.getDate() << 16 )
+                     | ( time.getHours() << 11 )
+                     | ( time.getMinutes() << 5 )
+                     | ( time.getSeconds() >> 1 );
+
+        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 new ZipLong( result );
+    }
+
+    /**
+     * Retrieve the bytes for the given String in the encoding set for
+     * this Stream.
+     *
+     * @since 1.3
+     */
+    protected byte[] getBytes( String name )
+        throws ZipException
+    {
+        if ( encoding == null )
+        {
+            return name.getBytes();
+        }
+        else
+        {
+            try
+            {
+                return name.getBytes( encoding );
+            }
+            catch ( UnsupportedEncodingException uee )
+            {
+                throw new ZipException( uee.getMessage() );
+            }
+        }
+    }
+
+    /**
+     * Write bytes to output or random access file
+     *
+     * @since 1.14
+     */
+    protected final void writeOut( byte [] data )
+        throws IOException
+    {
+        writeOut( data, 0, data.length );
+    }
+
+    /**
+     * Write bytes to output or random access file
+     *
+     * @since 1.14
+     */
+    protected final void writeOut( byte [] data, int offset, int length )
+        throws IOException
+    {
+        if ( raf != null )
+        {
+            raf.write( data, offset, length );
+        }
+        else
+        {
+            out.write( data, offset, length );
+        }
+    }
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipOutputStream.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/ZipOutputStream.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/ZipOutputStream.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/ZipResource.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/ZipResource.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipResource.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipResource.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,78 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.zip;
+
+import org.apache.geronimo.system.plugin.plexus.archiver.UnixStat;
+import org.apache.geronimo.system.plugin.plexus.io.attributes.PlexusIoResourceAttributes;
+import org.apache.geronimo.system.plugin.plexus.io.attributes.SimpleResourceAttributes;
+import org.apache.geronimo.system.plugin.plexus.io.resources.AbstractPlexusIoResourceWithAttributes;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoResource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+public class ZipResource
+    extends AbstractPlexusIoResourceWithAttributes
+{
+
+    private final ZipFile zipFile;
+    private final ZipEntry entry;
+    private PlexusIoResourceAttributes attributes;
+
+    public ZipResource( ZipFile zipFile, ZipEntry entry )
+    {
+        this.zipFile = zipFile;
+        this.entry = entry;
+        final boolean dir = entry.isDirectory();
+        
+        setName( entry.getName() );
+        
+        setFile( !dir );
+        setDirectory( dir );
+        
+        setExisting( true );
+        setFile( !dir );
+        
+        long l = entry.getLastModificationTime();
+        setLastModified( l == -1 ? PlexusIoResource.UNKNOWN_MODIFICATION_DATE : l );
+        setSize( dir ? PlexusIoResource.UNKNOWN_RESOURCE_SIZE : entry.getSize() );
+    }
+
+    public synchronized PlexusIoResourceAttributes getAttributes()
+    {
+        int mode = entry.getUnixMode();
+        if ( ( mode & UnixStat.FILE_FLAG ) == UnixStat.FILE_FLAG )
+        {
+            mode = mode & ~UnixStat.FILE_FLAG;
+        }
+        else
+        {
+            mode = mode & ~UnixStat.DIR_FLAG;
+        }
+        
+        if ( attributes == null )
+        {
+            attributes = new SimpleResourceAttributes();
+            attributes.setOctalMode( mode );
+        }
+        
+        return attributes;
+    }
+
+    public synchronized void setAttributes( PlexusIoResourceAttributes attributes )
+    {
+        this.attributes = attributes;
+    }
+
+    public URL getURL()
+        throws IOException
+    {
+        return null;
+    }
+
+    public InputStream getContents()
+        throws IOException
+    {
+        return zipFile.getInputStream( entry );
+    }
+
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipResource.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/ZipResource.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/ZipResource.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/ZipShort.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/ZipShort.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipShort.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipShort.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,110 @@
+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 two byte integer with conversion
+ * rules for the big endian byte order of ZIP files.
+ *
+ * @version $Revision$ $Date$
+ *          from org.apache.ant.tools.zip.ZipShort v1.10
+ */
+public final class ZipShort
+    implements Cloneable
+{
+
+    private int value;
+
+    /**
+     * Create instance from a number.
+     *
+     * @since 1.1
+     */
+    public ZipShort( int value )
+    {
+        this.value = value;
+    }
+
+    /**
+     * Create instance from bytes.
+     *
+     * @since 1.1
+     */
+    public ZipShort( byte[] bytes )
+    {
+        this( bytes, 0 );
+    }
+
+    /**
+     * Create instance from the two bytes starting at offset.
+     *
+     * @since 1.1
+     */
+    public ZipShort( byte[] bytes, int offset )
+    {
+        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[2];
+        result[ 0 ] = (byte) ( value & 0xFF );
+        result[ 1 ] = (byte) ( ( value & 0xFF00 ) >> 8 );
+        return result;
+    }
+
+    /**
+     * Get value as Java int.
+     *
+     * @since 1.1
+     */
+    public int 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 ZipShort ) )
+        {
+            return false;
+        }
+        return value == ( (ZipShort) o ).getValue();
+    }
+
+    /**
+     * Override to make two instances with same value equal.
+     *
+     * @since 1.1
+     */
+    public int hashCode()
+    {
+        return value;
+    }
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipShort.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/ZipShort.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/ZipShort.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/ZipUnArchiver.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/ZipUnArchiver.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipUnArchiver.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipUnArchiver.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,37 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.zip;
+
+import java.io.File;
+
+/**
+ *
+ * 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.
+ */
+
+/**
+ * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
+ * @version $Revision$ $Date$
+ */
+public class ZipUnArchiver
+    extends AbstractZipUnArchiver
+{
+    public ZipUnArchiver()
+    {
+    }
+
+    public ZipUnArchiver( File sourceFile )
+    {
+        super( sourceFile );
+    }
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/ZipUnArchiver.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/ZipUnArchiver.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/ZipUnArchiver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/AttributeConstants.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/AttributeConstants.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/AttributeConstants.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/AttributeConstants.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,44 @@
+package org.apache.geronimo.system.plugin.plexus.io.attributes;
+
+/*
+ * Copyright 2007 The Codehaus 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.
+ */
+
+public final class AttributeConstants
+{
+
+    public static final int OCTAL_OWNER_READ = 0400;
+
+    public static final int OCTAL_OWNER_WRITE = 0200;
+
+    public static final int OCTAL_OWNER_EXECUTE = 0100;
+
+    public static final int OCTAL_GROUP_READ = 040;
+
+    public static final int OCTAL_GROUP_WRITE = 020;
+
+    public static final int OCTAL_GROUP_EXECUTE = 010;
+
+    public static final int OCTAL_WORLD_READ = 04;
+
+    public static final int OCTAL_WORLD_WRITE = 02;
+
+    public static final int OCTAL_WORLD_EXECUTE = 01;
+
+    private AttributeConstants()
+    {
+    }
+
+}
\ No newline at end of file

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

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

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

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/FileAttributes.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/FileAttributes.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/FileAttributes.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/FileAttributes.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,353 @@
+package org.apache.geronimo.system.plugin.plexus.io.attributes;
+
+/*
+ * Copyright 2007 The Codehaus 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.Arrays;
+
+public class FileAttributes
+    implements PlexusIoResourceAttributes
+{
+    
+    protected static final char VALUE_DISABLED_MODE = '-';
+    
+    protected static final char VALUE_WRITABLE_MODE = 'w';
+    
+    protected static final char VALUE_READABLE_MODE = 'r';
+    
+    protected static final char VALUE_EXECUTABLE_MODE = 'x';
+
+    protected static final int INDEX_WORLD_EXECUTE = 9;
+
+    protected static final int INDEX_WORLD_WRITE = 8;
+
+    protected static final int INDEX_WORLD_READ = 7;
+
+    protected static final int INDEX_GROUP_EXECUTE = 6;
+
+    protected static final int INDEX_GROUP_WRITE = 5;
+
+    protected static final int INDEX_GROUP_READ = 4;
+
+    protected static final int INDEX_OWNER_EXECUTE = 3;
+
+    protected static final int INDEX_OWNER_WRITE = 2;
+
+    protected static final int INDEX_OWNER_READ = 1;
+
+    private int groupId = -1;
+
+    private String groupName;
+
+    private int userId = -1;
+
+    private String userName;
+
+    private char[] mode;
+    
+    public FileAttributes( int userId, String userName, int groupId, String groupName, char[] mode )
+    {
+        this.groupId = groupId;
+        this.groupName = groupName;
+        this.userId = userId;
+        this.userName = userName;
+        setLsModeParts( mode );
+    }
+    
+    public FileAttributes()
+    {
+        mode = new char[10];
+        Arrays.fill( mode, VALUE_DISABLED_MODE );
+    }
+    
+    protected char[] getLsModeParts()
+    {
+        return mode;
+    }
+
+    protected void setLsModeParts( char[] mode )
+    {
+        if( mode.length < 10 )
+        {
+            this.mode = new char[10];
+            System.arraycopy( mode, 0, this.mode, 0, mode.length );
+            for ( int i = mode.length; i < 10; i++ )
+            {
+                this.mode[i] = VALUE_DISABLED_MODE;
+            }
+        }
+        else
+        {
+            this.mode = mode;
+        }
+    }
+
+    public int getGroupId()
+    {
+        return groupId;
+    }
+
+    public String getGroupName()
+    {
+        return groupName;
+    }
+
+    public int getUserId()
+    {
+        return userId;
+    }
+
+    public String getUserName()
+    {
+        return userName;
+    }
+
+    public boolean isGroupExecutable()
+    {
+        return checkFlag( '-', INDEX_GROUP_EXECUTE );
+    }
+
+    private boolean checkFlag( char disabledValue, int idx )
+    {
+        return mode == null ? false : mode[idx] != disabledValue;
+    }
+
+    public boolean isGroupReadable()
+    {
+        return checkFlag( '-', INDEX_GROUP_READ );
+    }
+
+    public boolean isGroupWritable()
+    {
+        return checkFlag( '-', INDEX_GROUP_WRITE );
+    }
+
+    public boolean isOwnerExecutable()
+    {
+        return checkFlag( '-', INDEX_OWNER_EXECUTE );
+    }
+
+    public boolean isOwnerReadable()
+    {
+        return checkFlag( '-', INDEX_OWNER_READ );
+    }
+
+    public boolean isOwnerWritable()
+    {
+        return checkFlag( '-', INDEX_OWNER_WRITE );
+    }
+
+    public boolean isWorldExecutable()
+    {
+        return checkFlag( '-', INDEX_WORLD_EXECUTE );
+    }
+
+    public boolean isWorldReadable()
+    {
+        return checkFlag( '-', INDEX_WORLD_READ );
+    }
+
+    public boolean isWorldWritable()
+    {
+        return checkFlag( '-', INDEX_WORLD_WRITE );
+    }
+
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+        sb.append( "\nFile Attributes:\n------------------------------\nuser: " );
+        sb.append( userName == null ? "" : userName );
+        sb.append( "\ngroup: " );
+        sb.append( groupName == null ? "" : groupName );
+        sb.append( "\nuid: " );
+        sb.append( userId == -1 ? "" : Integer.toString( userId ) );
+        sb.append( "\ngid: " );
+        sb.append( groupId == -1 ? "" : Integer.toString( groupId ) );
+        sb.append( "\nmode: " );
+        sb.append( mode == null ? "" : String.valueOf( mode ) );
+        
+        return sb.toString();
+    }
+
+    public int getOctalMode()
+    {
+        int result = 0;
+        
+        if ( isOwnerReadable() )
+        {
+            result |= AttributeConstants.OCTAL_OWNER_READ;
+        }
+        
+        if ( isOwnerWritable() )
+        {
+            result |= AttributeConstants.OCTAL_OWNER_WRITE;
+        }
+        
+        if ( isOwnerExecutable() )
+        {
+            result |= AttributeConstants.OCTAL_OWNER_EXECUTE;
+        }
+        
+        if ( isGroupReadable() )
+        {
+            result |= AttributeConstants.OCTAL_GROUP_READ;
+        }
+        
+        if ( isGroupWritable() )
+        {
+            result |= AttributeConstants.OCTAL_GROUP_WRITE;
+        }
+        
+        if ( isGroupExecutable() )
+        {
+            result |= AttributeConstants.OCTAL_GROUP_EXECUTE;
+        }
+        
+        if ( isWorldReadable() )
+        {
+            result |= AttributeConstants.OCTAL_WORLD_READ;
+        }
+        
+        if ( isWorldWritable() )
+        {
+            result |= AttributeConstants.OCTAL_WORLD_WRITE;
+        }
+        
+        if ( isWorldExecutable() )
+        {
+            result |= AttributeConstants.OCTAL_WORLD_EXECUTE;
+        }
+        
+        return result;
+    }
+
+    public String getOctalModeString()
+    {
+        return Integer.toString( getOctalMode(), 8 );
+    }
+    
+    public PlexusIoResourceAttributes setGroupExecutable( boolean flag )
+    {
+        setMode( flag ? VALUE_EXECUTABLE_MODE : VALUE_DISABLED_MODE, INDEX_GROUP_EXECUTE );
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setGroupId( int gid )
+    {
+        this.groupId = gid;
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setGroupName( String name )
+    {
+        this.groupName = name;
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setGroupReadable( boolean flag )
+    {
+        setMode( flag ? VALUE_READABLE_MODE : VALUE_DISABLED_MODE, INDEX_GROUP_READ );
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setGroupWritable( boolean flag )
+    {
+        setMode( flag ? VALUE_WRITABLE_MODE : VALUE_DISABLED_MODE, INDEX_GROUP_WRITE );
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setOwnerExecutable( boolean flag )
+    {
+        setMode( flag ? VALUE_EXECUTABLE_MODE : VALUE_DISABLED_MODE, INDEX_OWNER_EXECUTE );
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setOwnerReadable( boolean flag )
+    {
+        setMode( flag ? VALUE_READABLE_MODE : VALUE_DISABLED_MODE, INDEX_OWNER_READ );
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setOwnerWritable( boolean flag )
+    {
+        setMode( flag ? VALUE_WRITABLE_MODE : VALUE_DISABLED_MODE, INDEX_OWNER_WRITE );
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setUserId( int uid )
+    {
+        this.userId = uid;
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setUserName( String name )
+    {
+        this.userName = name;
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setWorldExecutable( boolean flag )
+    {
+        setMode( flag ? VALUE_EXECUTABLE_MODE : VALUE_DISABLED_MODE, INDEX_WORLD_EXECUTE );
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setWorldReadable( boolean flag )
+    {
+        setMode( flag ? VALUE_READABLE_MODE : VALUE_DISABLED_MODE, INDEX_WORLD_READ );
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setWorldWritable( boolean flag )
+    {
+        setMode( flag ? VALUE_WRITABLE_MODE : VALUE_DISABLED_MODE, INDEX_WORLD_WRITE );
+        return this;
+    }
+    
+    public PlexusIoResourceAttributes setLsModeline( String modeLine )
+    {
+        setLsModeParts( modeLine.toCharArray() );
+        return this;
+    }
+    
+    private void setMode( char value, int modeIdx )
+    {
+        char[] mode = getLsModeParts();
+        mode[modeIdx] = value;
+        
+        setLsModeParts( mode );
+    }
+    
+    public PlexusIoResourceAttributes setOctalMode( int mode )
+    {
+        setGroupExecutable( PlexusIoResourceAttributeUtils.isGroupExecutableInOctal( mode ) );
+        setGroupReadable( PlexusIoResourceAttributeUtils.isGroupReadableInOctal( mode ) );
+        setGroupWritable( PlexusIoResourceAttributeUtils.isGroupWritableInOctal( mode ) );
+        setOwnerExecutable( PlexusIoResourceAttributeUtils.isOwnerExecutableInOctal( mode ) );
+        setOwnerReadable( PlexusIoResourceAttributeUtils.isOwnerReadableInOctal( mode ) );
+        setOwnerWritable( PlexusIoResourceAttributeUtils.isOwnerWritableInOctal( mode ) );
+        setWorldExecutable( PlexusIoResourceAttributeUtils.isWorldExecutableInOctal( mode ) );
+        setWorldReadable( PlexusIoResourceAttributeUtils.isWorldReadableInOctal( mode ) );
+        setWorldWritable( PlexusIoResourceAttributeUtils.isWorldWritableInOctal( mode ) );
+        return this;
+    }
+    
+    public PlexusIoResourceAttributes setOctalModeString( String mode )
+    {
+        setOctalMode( Integer.parseInt( mode, 8 ) );
+        return this;
+    }
+}
\ No newline at end of file

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

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

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

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/PlexusIoResourceAttributeUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/PlexusIoResourceAttributeUtils.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/PlexusIoResourceAttributeUtils.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/PlexusIoResourceAttributeUtils.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,487 @@
+package org.apache.geronimo.system.plugin.plexus.io.attributes;
+
+/*
+ * Copyright 2007 The Codehaus 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.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.geronimo.system.plugin.plexus.util.Os;
+import org.apache.geronimo.system.plugin.plexus.util.cli.CommandLineException;
+import org.apache.geronimo.system.plugin.plexus.util.cli.CommandLineUtils;
+import org.apache.geronimo.system.plugin.plexus.util.cli.Commandline;
+import org.apache.geronimo.system.plugin.plexus.util.cli.StreamConsumer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class PlexusIoResourceAttributeUtils
+{
+    private final static Logger logger = LoggerFactory.getLogger(PlexusIoResourceAttributeUtils.class);
+    private PlexusIoResourceAttributeUtils()
+    {
+    }
+    
+    public static PlexusIoResourceAttributes mergeAttributes( PlexusIoResourceAttributes override,
+                                                              PlexusIoResourceAttributes base,
+                                                              PlexusIoResourceAttributes def )
+    {
+        if ( override == null )
+        {
+            return base;
+        }
+        SimpleResourceAttributes result;
+        if ( base == null )
+        {
+            result = new SimpleResourceAttributes();
+        }
+        else
+        {
+            result = new SimpleResourceAttributes( base.getUserId(), base.getUserName(), base.getGroupId(), base.getGroupName(),
+                                          base.getOctalMode() );
+        }
+        
+        if ( override.getGroupId() != -1 )
+        {
+            result.setGroupId( override.getGroupId() );
+        }
+        
+        if ( def != null && result.getGroupId() < 0 )
+        {
+            result.setGroupId( def.getGroupId() );
+        }
+        
+        if ( override.getGroupName() != null )
+        {
+            result.setGroupName( override.getGroupName() );
+        }
+        
+        if ( def != null && result.getGroupName() == null )
+        {
+            result.setGroupName( def.getGroupName() );
+        }
+        
+        if ( override.getUserId() != -1 )
+        {
+            result.setUserId( override.getUserId() );
+        }
+        
+        if ( def != null && result.getUserId() < 0 )
+        {
+            result.setUserId( def.getUserId() );
+        }
+        
+        if ( override.getUserName() != null )
+        {
+            result.setUserName( override.getUserName() );
+        }
+        
+        if ( def != null && result.getUserName() == null )
+        {
+            result.setUserName( def.getUserName() );
+        }
+        
+        if ( override.getOctalMode() > 0 )
+        {
+            result.setOctalMode( override.getOctalMode() );
+        }
+        
+        if ( def != null && result.getOctalMode() < 0 )
+        {
+            result.setOctalMode( def.getOctalMode() );
+        }
+        
+        return result;
+    }
+
+    public static boolean isGroupExecutableInOctal( int mode )
+    {
+        return isOctalModeEnabled( mode, AttributeConstants.OCTAL_GROUP_EXECUTE );
+    }
+
+    public static boolean isGroupReadableInOctal( int mode )
+    {
+        return isOctalModeEnabled( mode, AttributeConstants.OCTAL_GROUP_READ );
+    }
+
+    public static boolean isGroupWritableInOctal( int mode )
+    {
+        return isOctalModeEnabled( mode, AttributeConstants.OCTAL_GROUP_WRITE );
+    }
+
+    public static boolean isOwnerExecutableInOctal( int mode )
+    {
+        return isOctalModeEnabled( mode, AttributeConstants.OCTAL_OWNER_EXECUTE );
+    }
+
+    public static boolean isOwnerReadableInOctal( int mode )
+    {
+        return isOctalModeEnabled( mode, AttributeConstants.OCTAL_OWNER_READ );
+    }
+
+    public static boolean isOwnerWritableInOctal( int mode )
+    {
+        return isOctalModeEnabled( mode, AttributeConstants.OCTAL_OWNER_WRITE );
+    }
+
+    public static boolean isWorldExecutableInOctal( int mode )
+    {
+        return isOctalModeEnabled( mode, AttributeConstants.OCTAL_WORLD_EXECUTE );
+    }
+
+    public static boolean isWorldReadableInOctal( int mode )
+    {
+        return isOctalModeEnabled( mode, AttributeConstants.OCTAL_WORLD_READ );
+    }
+
+    public static boolean isWorldWritableInOctal( int mode )
+    {
+        return isOctalModeEnabled( mode, AttributeConstants.OCTAL_WORLD_WRITE );
+    }
+
+    public static boolean isOctalModeEnabled( int mode, int targetMode )
+    {
+        return ( mode & targetMode ) != 0;
+    }
+
+    public static PlexusIoResourceAttributes getFileAttributes( File file )
+        throws IOException
+    {
+        Map byPath = getFileAttributesByPath( file, null, false );
+        return (PlexusIoResourceAttributes) byPath.get( file.getAbsolutePath() );
+    }
+
+    public static PlexusIoResourceAttributes getFileAttributes( File file, Logger logger )
+        throws IOException
+    {
+        Map byPath = getFileAttributesByPath( file, logger, false );
+        return (PlexusIoResourceAttributes) byPath.get( file.getAbsolutePath() );
+    }
+
+    public static PlexusIoResourceAttributes getFileAttributes( File file, Logger logger, int logLevel )
+        throws IOException
+    {
+        Map byPath = getFileAttributesByPath( file, logger, false );
+        return (PlexusIoResourceAttributes) byPath.get( file.getAbsolutePath() );
+    }
+
+    public static Map getFileAttributesByPath( File dir )
+        throws IOException
+    {
+        return getFileAttributesByPath( dir, null, true );
+    }
+
+    public static Map getFileAttributesByPath( File dir, Logger logger )
+        throws IOException
+    {
+        return getFileAttributesByPath( dir, logger, true );
+    }
+
+    public static Map getFileAttributesByPath( File dir, Logger logger, int logLevel )
+        throws IOException
+    {
+        return getFileAttributesByPath( dir, logger, true );
+    }
+    
+    public static Map getFileAttributesByPath(File dir, Logger logger, boolean recursive)
+        throws IOException
+    {
+        int logLevel = 0;
+        if (logger == null) {
+            logger = PlexusIoResourceAttributeUtils.logger;
+        }
+        if ( !enabledOnCurrentOperatingSystem() )
+        {
+            return Collections.EMPTY_MAP;
+        }
+
+        LoggerStreamConsumer loggerConsumer = new LoggerStreamConsumer( logger, logLevel );
+
+        AttributeParser parser = new AttributeParser( loggerConsumer, logger );
+        
+        String lsOptions = "-1nla" + ( recursive ? "R" : "d" );
+        try
+        {
+            executeLs( dir, lsOptions, loggerConsumer, parser, logger );
+        }
+        catch ( CommandLineException e )
+        {
+            IOException error = new IOException( "Failed to quote directory: '" + dir + "'" );
+            error.initCause( e );
+
+            throw error;
+        }
+
+        parser.secondPass = true;
+        parser.extractNames = true;
+        lsOptions = "-1la" + ( recursive ? "R" : "d" );
+        try
+        {
+            executeLs( dir, lsOptions, loggerConsumer, parser, logger );
+        }
+        catch ( CommandLineException e )
+        {
+            IOException error = new IOException( "Failed to quote directory: '" + dir + "'" );
+            error.initCause( e );
+
+            throw error;
+        }
+
+        return parser.attributesByPath;
+    }
+
+    private static boolean enabledOnCurrentOperatingSystem()
+    {
+        return !Os.isFamily( Os.FAMILY_WINDOWS ) && !Os.isFamily( Os.FAMILY_WIN9X );
+    }
+
+    private static void executeLs( File dir, String options, LoggerStreamConsumer loggerConsumer,
+                                   StreamConsumer parser, Logger logger )
+        throws IOException, CommandLineException
+    {
+        Commandline numericCli = new Commandline();
+
+        numericCli.getShell().setQuotedArgumentsEnabled( true );
+        numericCli.getShell().setQuotedExecutableEnabled( false );
+
+        numericCli.setExecutable( "ls" );
+
+        numericCli.createArg().setLine( options );
+
+        numericCli.createArg().setValue( dir.getAbsolutePath() );
+
+        if ( logger.isDebugEnabled() )
+        {
+            logger.debug( "Executing:\n\n" + numericCli.toString() + "\n" );
+        }
+
+        try
+        {
+            int result = CommandLineUtils.executeCommandLine( numericCli, parser, loggerConsumer );
+
+            if ( result != 0 )
+            {
+                throw new IOException( "Failed to retrieve numeric file attributes using: '" + numericCli.toString()
+                    + "'" );
+            }
+        }
+        catch ( CommandLineException e )
+        {
+            IOException error =
+                new IOException( "Failed to retrieve numeric file attributes using: '" + numericCli.toString() + "'" );
+            error.initCause( e );
+
+            throw error;
+        }
+    }
+
+    private static final class LoggerStreamConsumer
+        implements StreamConsumer
+    {
+        private Logger logger;
+
+        private int level;
+
+        public LoggerStreamConsumer( Logger logger, int level )
+        {
+            this.logger = logger;
+            this.level = level;
+        }
+
+        public void consumeLine( String line )
+        {
+            logger.debug(line);
+//            switch ( level )
+//            {
+//                case Logger.LEVEL_DEBUG:
+//                    logger.debug( line );
+//                    break;
+//                case Logger.LEVEL_ERROR:
+//                    logger.error( line );
+//                    break;
+//                case Logger.LEVEL_FATAL:
+//                    logger.fatalError( line );
+//                    break;
+//                case Logger.LEVEL_WARN:
+//                    logger.warn( line );
+//                    break;
+//                default:
+//                    logger.info( line );
+//                    break;
+//            }
+        }
+    }
+
+    private static final SimpleDateFormat[] LS_DATE_FORMATS =
+        { new SimpleDateFormat( "MMM dd yyyy" ), new SimpleDateFormat( "MMM dd HH:mm" ),
+            new SimpleDateFormat( "yyyy-MM-dd HH:mm" ), };
+
+    private static final int[] LS_LAST_DATE_PART_INDICES = { 7, 7, 6 };
+
+    private static int verifyParsability( String line, String[] parts, Logger logger )
+    {
+        if ( parts.length > 7 )
+        {
+            String dateCandidate = parts[5] + " " + parts[6] + " " + parts[7];
+            for ( int i = 0; i < LS_DATE_FORMATS.length; i++ )
+            {
+                try
+                {
+                    LS_DATE_FORMATS[i].parse( dateCandidate );
+                    return LS_LAST_DATE_PART_INDICES[i];
+                }
+                catch ( ParseException e )
+                {
+                    if ( logger.isDebugEnabled() )
+                    {
+                        logger.debug( "Failed to parse date: '" + dateCandidate + "' using format: "
+                            + LS_DATE_FORMATS[i].toPattern(), e );
+                    }
+                }
+            }
+        }
+
+        if ( logger.isDebugEnabled() )
+        {
+            logger.debug( "Unparseable line: '" + line
+                + "'\nReason: unrecognized date format; ambiguous start-index for path in listing." );
+        }
+
+        return -1;
+    }
+
+    private static final class AttributeParser
+        implements StreamConsumer
+    {
+        private final StreamConsumer delegate;
+
+        private Map attributesByPath = new LinkedHashMap();
+
+        private final Logger logger;
+
+        private boolean nextIsPathPrefix = false;
+
+        private String pathPrefix = "";
+
+        private boolean extractNames = false;
+
+        private boolean secondPass = false;
+
+        public AttributeParser( StreamConsumer delegate, Logger logger )
+        {
+            this.delegate = delegate;
+            this.logger = logger;
+        }
+
+        public void consumeLine( String line )
+        {
+            if ( line.startsWith( "total " ) )
+            {
+                // skip it.
+            }
+            else if ( line.trim().length() == 0 )
+            {
+                nextIsPathPrefix = true;
+
+                if ( logger.isDebugEnabled() )
+                {
+                    logger.debug( "Anticipating path prefix in next line" );
+                }
+            }
+            else if ( nextIsPathPrefix )
+            {
+                if ( !line.endsWith( ":" ) )
+                {
+                    if ( logger.isDebugEnabled() )
+                    {
+                        logger.debug( "Path prefix not found. Checking next line." );
+                    }
+                }
+                else
+                {
+                    nextIsPathPrefix = false;
+                    pathPrefix = line.substring( 0, line.length() - 1 );
+
+                    if ( !pathPrefix.endsWith( "/" ) )
+                    {
+                        pathPrefix += "/";
+                    }
+
+                    if ( logger.isDebugEnabled() )
+                    {
+                        logger.debug( "Set path prefix to: " + pathPrefix );
+                    }
+                }
+            }
+            else
+            {
+                String[] parts = line.split( "\\s+" );
+                int lastDatePart = verifyParsability( line, parts, logger );
+
+                if ( lastDatePart > 0 )
+                {
+                    int idx = line.indexOf( parts[lastDatePart] ) + parts[lastDatePart].length() + 1;
+
+                    String path = pathPrefix + line.substring( idx );
+                    while ( path.length() > 0 && Character.isWhitespace( path.charAt( 0 ) ) )
+                    {
+                        path = path.substring( 1 );
+                    }
+
+                    if ( logger.isDebugEnabled() )
+                    {
+                        logger.debug( "path: '" + path + "'" );
+                        logger.debug( "mode: '" + parts[0] + "'" );
+                        logger.debug( "uid: '" + parts[2] );
+                        logger.debug( "gid: '" + parts[3] );
+                    }
+
+                    FileAttributes attributes = null;
+                    if ( secondPass )
+                    {
+                        attributes = (FileAttributes) attributesByPath.get( path );
+                    }
+                    else
+                    {
+                        attributes = new FileAttributes();
+                        attributes.setLsModeline( parts[0] );
+                        attributesByPath.put( path, attributes );
+                    }
+
+                    if ( attributes != null )
+                    {
+                        if ( extractNames )
+                        {
+                            attributes.setUserName( parts[2] );
+                            attributes.setGroupName( parts[3] );
+                        }
+                        else
+                        {
+                            attributes.setUserId( Integer.parseInt( parts[2] ) );
+                            attributes.setGroupId( Integer.parseInt( parts[3] ) );
+                        }
+                    }
+                }
+            }
+
+            delegate.consumeLine( line );
+        }
+    }
+}
\ No newline at end of file

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

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

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

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/PlexusIoResourceAttributes.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/PlexusIoResourceAttributes.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/PlexusIoResourceAttributes.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/PlexusIoResourceAttributes.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,80 @@
+package org.apache.geronimo.system.plugin.plexus.io.attributes;
+
+/*
+ * Copyright 2007 The Codehaus 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.
+ */
+
+public interface PlexusIoResourceAttributes
+{
+    boolean isOwnerReadable();
+    
+    boolean isOwnerWritable();
+    
+    boolean isOwnerExecutable();
+    
+    boolean isGroupReadable();
+
+    boolean isGroupWritable();
+    
+    boolean isGroupExecutable();
+    
+    boolean isWorldReadable();
+
+    boolean isWorldWritable();
+    
+    boolean isWorldExecutable();
+    
+    int getUserId();
+    
+    int getGroupId();
+    
+    String getUserName();
+    
+    String getGroupName();
+    
+    int getOctalMode();
+    
+    String getOctalModeString();
+    
+    PlexusIoResourceAttributes setOwnerReadable( boolean flag );
+
+    PlexusIoResourceAttributes setOwnerWritable( boolean flag );
+
+    PlexusIoResourceAttributes setOwnerExecutable( boolean flag );
+
+    PlexusIoResourceAttributes setGroupReadable( boolean flag );
+
+    PlexusIoResourceAttributes setGroupWritable( boolean flag );
+
+    PlexusIoResourceAttributes setGroupExecutable( boolean flag );
+
+    PlexusIoResourceAttributes setWorldReadable( boolean flag );
+
+    PlexusIoResourceAttributes setWorldWritable( boolean flag );
+
+    PlexusIoResourceAttributes setWorldExecutable( boolean flag );
+
+    PlexusIoResourceAttributes setUserId( int uid );
+
+    PlexusIoResourceAttributes setGroupId( int gid );
+
+    PlexusIoResourceAttributes setUserName( String name );
+
+    PlexusIoResourceAttributes setGroupName( String name );
+    
+    PlexusIoResourceAttributes setOctalMode( int mode );
+    
+    PlexusIoResourceAttributes setOctalModeString( String mode );
+}
\ No newline at end of file

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

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

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

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/SimpleResourceAttributes.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/SimpleResourceAttributes.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/SimpleResourceAttributes.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/attributes/SimpleResourceAttributes.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,223 @@
+package org.apache.geronimo.system.plugin.plexus.io.attributes;
+
+/*
+ * Copyright 2007 The Codehaus 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.
+ */
+
+public class SimpleResourceAttributes
+    implements PlexusIoResourceAttributes
+{
+    
+    private int gid = -1;
+    
+    private int uid = -1;
+    
+    private String userName;
+    
+    private String groupName;
+    
+    private int mode;
+    
+    public SimpleResourceAttributes( int uid, String userName, int gid, String groupName, int mode )
+    {
+        this.uid = uid;
+        this.userName = userName;
+        this.gid = gid;
+        this.groupName = groupName;
+        this.mode = mode;
+    }
+    
+    public SimpleResourceAttributes()
+    {
+    }
+
+    public int getOctalMode()
+    {
+        return mode;
+    }
+
+    public int getGroupId()
+    {
+        return gid;
+    }
+
+    public String getGroupName()
+    {
+        return groupName;
+    }
+
+    public int getUserId()
+    {
+        return uid;
+    }
+
+    public String getUserName()
+    {
+        return userName;
+    }
+
+    public boolean isGroupExecutable()
+    {
+        return PlexusIoResourceAttributeUtils.isGroupExecutableInOctal( mode );
+    }
+
+    public boolean isGroupReadable()
+    {
+        return PlexusIoResourceAttributeUtils.isGroupReadableInOctal( mode );
+    }
+
+    public boolean isGroupWritable()
+    {
+        return PlexusIoResourceAttributeUtils.isGroupWritableInOctal( mode );
+    }
+
+    public boolean isOwnerExecutable()
+    {
+        return PlexusIoResourceAttributeUtils.isOwnerExecutableInOctal( mode );
+    }
+
+    public boolean isOwnerReadable()
+    {
+        return PlexusIoResourceAttributeUtils.isOwnerReadableInOctal( mode );
+    }
+
+    public boolean isOwnerWritable()
+    {
+        return PlexusIoResourceAttributeUtils.isOwnerWritableInOctal( mode );
+    }
+
+    public boolean isWorldExecutable()
+    {
+        return PlexusIoResourceAttributeUtils.isWorldExecutableInOctal( mode );
+    }
+
+    public boolean isWorldReadable()
+    {
+        return PlexusIoResourceAttributeUtils.isWorldReadableInOctal( mode );
+    }
+
+    public boolean isWorldWritable()
+    {
+        return PlexusIoResourceAttributeUtils.isWorldWritableInOctal( mode );
+    }
+
+    public String getOctalModeString()
+    {
+        return Integer.toString( mode, 8 );
+    }
+
+    public PlexusIoResourceAttributes setOctalMode( int mode )
+    {
+        this.mode = mode;
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setGroupExecutable( boolean flag )
+    {
+        set( AttributeConstants.OCTAL_GROUP_EXECUTE, flag );
+        return this;
+    }
+    
+    public PlexusIoResourceAttributes setGroupId( int gid )
+    {
+        this.gid = gid;
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setGroupName( String name )
+    {
+        this.groupName = name;
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setGroupReadable( boolean flag )
+    {
+        set( AttributeConstants.OCTAL_GROUP_READ, flag );
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setGroupWritable( boolean flag )
+    {
+        set( AttributeConstants.OCTAL_GROUP_WRITE, flag );
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setOwnerExecutable( boolean flag )
+    {
+        set( AttributeConstants.OCTAL_OWNER_EXECUTE, flag );
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setOwnerReadable( boolean flag )
+    {
+        set( AttributeConstants.OCTAL_OWNER_READ, flag );
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setOwnerWritable( boolean flag )
+    {
+        set( AttributeConstants.OCTAL_OWNER_WRITE, flag );
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setUserId( int uid )
+    {
+        this.uid = uid;
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setUserName( String name )
+    {
+        this.userName = name;
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setWorldExecutable( boolean flag )
+    {
+        set( AttributeConstants.OCTAL_WORLD_EXECUTE, flag );
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setWorldReadable( boolean flag )
+    {
+        set( AttributeConstants.OCTAL_WORLD_READ, flag );
+        return this;
+    }
+
+    public PlexusIoResourceAttributes setWorldWritable( boolean flag )
+    {
+        set( AttributeConstants.OCTAL_WORLD_WRITE, flag );
+        return this;
+    }
+
+    private void set( int bit, boolean enabled )
+    {
+        if ( enabled )
+        {
+            mode |= bit;
+        }
+        else
+        {
+            mode &= ~bit;
+        }
+    }
+
+    public PlexusIoResourceAttributes setOctalModeString( String mode )
+    {
+        setOctalMode( Integer.parseInt( mode, 8 ) );
+        return this;
+    }
+
+}
\ No newline at end of file

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

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

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

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/filemappers/AbstractFileMapper.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/filemappers/AbstractFileMapper.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/filemappers/AbstractFileMapper.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/filemappers/AbstractFileMapper.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,39 @@
+package org.apache.geronimo.system.plugin.plexus.io.filemappers;
+
+/*
+ * Copyright 2007 The Codehaus 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.
+ */
+
+
+/**
+ * Abstract base class for deriving file mappers. It is recommended
+ * to use this class, if your implement your own file mappers, as
+ * this might allow to extend the FileMapper interface later on
+ * without loosing upwards compatibility.
+ */
+public abstract class AbstractFileMapper implements FileMapper
+{
+	/**
+	 * Checks the input and returns it without modifications.
+	 */
+	public String getMappedFileName( String pName )
+    {
+        if ( pName == null || pName.length() == 0 )
+        {
+            throw new IllegalArgumentException( "The source name must not be null." );
+        }
+        return pName;
+    }
+}

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

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

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

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/filemappers/FileExtensionMapper.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/filemappers/FileExtensionMapper.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/filemappers/FileExtensionMapper.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/io/filemappers/FileExtensionMapper.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,84 @@
+package org.apache.geronimo.system.plugin.plexus.io.filemappers;
+
+/*
+ * Copyright 2007 The Codehaus 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.
+ */
+
+/**
+ * An implementation of {@link FileMapper}, which changes the files extension.
+ */
+public class FileExtensionMapper extends AbstractFileMapper
+{
+    /**
+     * The file extension mappers role-hint: "fileExtension".
+     */
+    public static final String ROLE_HINT = "fileExtension";
+
+    private String targetExtension;
+
+    /**
+     * Sets the target files extension.
+     * 
+     * @throws IllegalArgumentException
+     *             The target extension is null or empty.
+     */
+    public void setTargetExtension( String pTargetExtension )
+    {
+        if ( pTargetExtension == null )
+        {
+            throw new IllegalArgumentException( "The target extension is null." );
+        }
+        if ( pTargetExtension.length() == 0 )
+        {
+            throw new IllegalArgumentException( "The target extension is empty." );
+        }
+        if ( pTargetExtension.charAt( 0 ) == '.' )
+        {
+            targetExtension = pTargetExtension;
+        }
+        else
+        {
+            targetExtension = '.' + pTargetExtension;
+        }
+    }
+
+    /**
+     * Returns the target files extension.
+     */
+    public String getTargetExtension()
+    {
+        return targetExtension;
+    }
+
+    public String getMappedFileName( String pName )
+    {
+        final String ext = getTargetExtension();
+        if ( ext == null )
+        {
+            throw new IllegalStateException( "The target extension has not been set." );
+        }
+        final String name = super.getMappedFileName( pName ); // Check arguments
+        final int dirSep = Math.max( pName.lastIndexOf( '/' ), pName.lastIndexOf( '\\' ) );
+        final int offset = pName.lastIndexOf( '.' );
+        if ( offset <= dirSep )
+        {
+            return name + ext;
+        }
+        else
+        {
+            return name.substring( 0, offset ) + ext;
+        }
+    }
+}
\ No newline at end of file

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

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

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



Mime
View raw message