You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2009/10/05 20:54:56 UTC

svn commit: r821961 [10/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...

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/tar/TarResource.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/tar/TarResource.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/tar/TarResource.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/tar/TarResource.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,70 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.tar;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+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.AbstractPlexusIoResource;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoResource;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoResourceWithAttributes;
+
+public class TarResource
+    extends AbstractPlexusIoResource
+    implements PlexusIoResourceWithAttributes
+{
+
+    private final TarFile tarFile;
+    private final TarEntry entry;
+    private PlexusIoResourceAttributes attributes;
+
+    public TarResource( TarFile tarFile, TarEntry entry )
+    {
+        this.tarFile = tarFile;
+        this.entry = entry;
+        final boolean dir = entry.isDirectory();
+        
+        setName( entry.getName() );
+        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()
+    {
+        if ( attributes == null )
+        {
+            attributes = new SimpleResourceAttributes();
+            attributes.setUserId( entry.getUserId() );
+            attributes.setUserName( entry.getUserName() );
+            attributes.setGroupId( entry.getGroupId() );
+            attributes.setGroupName( entry.getGroupName() );
+            attributes.setOctalMode( entry.getMode() );
+        }
+        
+        return attributes;
+    }
+
+    public synchronized void setAttributes( PlexusIoResourceAttributes attributes )
+    {
+        this.attributes = attributes;
+    }
+
+    public URL getURL()
+        throws IOException
+    {
+        return null;
+    }
+
+    public InputStream getContents()
+        throws IOException
+    {
+        return tarFile.getInputStream( entry );
+    }
+
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/tar/TarResource.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/tar/TarUnArchiver.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/tar/TarUnArchiver.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/tar/TarUnArchiver.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/tar/TarUnArchiver.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,220 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.tar;
+
+/**
+ *
+ * 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.ArchiverException;
+import org.apache.geronimo.system.plugin.plexus.archiver.bzip2.CBZip2InputStream;
+import org.apache.geronimo.system.plugin.plexus.archiver.util.EnumeratedAttribute;
+import org.apache.geronimo.system.plugin.plexus.archiver.zip.AbstractZipUnArchiver;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.GZIPInputStream;
+
+/**
+ * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
+ * @version $Revision$ $Date$
+ */
+public class TarUnArchiver
+    extends AbstractZipUnArchiver
+{
+    public TarUnArchiver()
+    {
+    }
+
+    public TarUnArchiver( File sourceFile )
+    {
+        super( sourceFile );
+    }
+
+    /**
+     * compression method
+     */
+    private UntarCompressionMethod compression = new UntarCompressionMethod();
+
+    /**
+     * Set decompression algorithm to use; default=none.
+     * <p/>
+     * Allowable values are
+     * <ul>
+     * <li>none - no compression
+     * <li>gzip - Gzip compression
+     * <li>bzip2 - Bzip2 compression
+     * </ul>
+     *
+     * @param method compression method
+     */
+    public void setCompression( UntarCompressionMethod method )
+    {
+        compression = method;
+    }
+
+    /**
+     * No encoding support in Untar.
+     */
+    public void setEncoding( String encoding )
+    {
+        getLogger().warn( "The TarUnArchiver doesn't support the encoding attribute" );
+    }
+
+    protected void execute()
+        throws ArchiverException
+    {
+        TarInputStream tis = null;
+        try
+        {
+            getLogger().info( "Expanding: " + getSourceFile() + " into " + getDestDirectory() );
+            tis = new TarInputStream( compression.decompress( getSourceFile(),
+                                                              new BufferedInputStream(
+                                                                  new FileInputStream( getSourceFile() ) ) ) );
+            TarEntry te;
+
+            while ( ( te = tis.getNextEntry() ) != null )
+            {
+                extractFile( getSourceFile(), getDestDirectory(), tis, te.getName(), te.getModTime(),
+                             te.isDirectory(), new Integer( te.getMode() ) );
+            }
+            getLogger().debug( "expand complete" );
+
+        }
+        catch ( IOException ioe )
+        {
+            throw new ArchiverException( "Error while expanding " + getSourceFile().getAbsolutePath(), ioe );
+        }
+        finally
+        {
+            if ( tis != null )
+            {
+                try
+                {
+                    tis.close();
+                }
+                catch ( IOException e )
+                {
+                    // ignore
+                }
+            }
+        }
+    }
+
+    /**
+     * Valid Modes for Compression attribute to Untar Task
+     */
+    public static final class UntarCompressionMethod
+        extends EnumeratedAttribute
+    {
+
+        // permissible values for compression attribute
+
+        /**
+         * No compression
+         */
+        public static final String NONE = "none";
+
+        /**
+         * GZIP compression
+         */
+        public static final String GZIP = "gzip";
+
+        /**
+         * BZIP2 compression
+         */
+        public static final String BZIP2 = "bzip2";
+
+
+        /**
+         * Constructor
+         */
+        public UntarCompressionMethod()
+        {
+            super();
+            try
+            {
+                setValue( NONE );
+            }
+            catch ( ArchiverException ae )
+            {
+                //Do nothing
+            }
+        }
+
+        /**
+         * Constructor
+         */
+        public UntarCompressionMethod( String method )
+        {
+            super();
+            try
+            {
+                setValue( method );
+            }
+            catch ( ArchiverException ae )
+            {
+                //Do nothing
+            }
+        }
+
+        /**
+         * Get valid enumeration values
+         *
+         * @return valid values
+         */
+        public String[] getValues()
+        {
+            return new String[]{NONE, GZIP, BZIP2};
+        }
+
+        /**
+         * This method wraps the input stream with the
+         * corresponding decompression method
+         *
+         * @param file    provides location information for BuildException
+         * @param istream input stream
+         * @return input stream with on-the-fly decompression
+         * @throws IOException    thrown by GZIPInputStream constructor
+         */
+        private InputStream decompress( final File file, final InputStream istream )
+            throws IOException, ArchiverException
+        {
+            final String value = getValue();
+            if ( GZIP.equals( value ) )
+            {
+                return new GZIPInputStream( istream );
+            }
+            else
+            {
+                if ( BZIP2.equals( value ) )
+                {
+                    final char[] magic = new char[]{'B', 'Z'};
+                    for ( int i = 0; i < magic.length; i++ )
+                    {
+                        if ( istream.read() != magic[ i ] )
+                        {
+                            throw new ArchiverException( "Invalid bz2 file." + file.toString() );
+                        }
+                    }
+                    return new CBZip2InputStream( istream );
+                }
+            }
+            return istream;
+        }
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/tar/TarUnArchiver.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/tar/TarUtils.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/tar/TarUtils.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/tar/TarUtils.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/tar/TarUtils.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,219 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.tar;
+
+/*
+ * Copyright  2000,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.
+ *
+ */
+
+/*
+ * This package is based on the work done by Timothy Gerard Endres
+ * (time@ice.com) to whom the Ant project is very grateful for his great code.
+ */
+
+/**
+ * This class provides static utility methods to work with byte streams.
+ *
+ * @version $Revision$ $Date$
+ *          from org.apache.ant.tools.tar.TarUtils v1.11
+ */
+public class TarUtils
+{
+
+    /**
+     * Parse an octal string from a header buffer. This is used for the
+     * file permission mode value.
+     *
+     * @param header The header buffer from which to parse.
+     * @param offset The offset into the buffer from which to parse.
+     * @param length The number of header bytes to parse.
+     * @return The long value of the octal string.
+     */
+    public static long parseOctal( byte[] header, int offset, int length )
+    {
+        long result = 0;
+        boolean stillPadding = true;
+        int end = offset + length;
+
+        for ( int i = offset; i < end; ++i )
+        {
+            if ( header[ i ] == 0 )
+            {
+                break;
+            }
+
+            if ( header[ i ] == (byte) ' ' || header[ i ] == '0' )
+            {
+                if ( stillPadding )
+                {
+                    continue;
+                }
+
+                if ( header[ i ] == (byte) ' ' )
+                {
+                    break;
+                }
+            }
+
+            stillPadding = false;
+            result = ( result << 3 ) + ( header[ i ] - '0' );
+        }
+
+        return result;
+    }
+
+    /**
+     * Parse an entry name from a header buffer.
+     *
+     * @param header The header buffer from which to parse.
+     * @param offset The offset into the buffer from which to parse.
+     * @param length The number of header bytes to parse.
+     * @return The header's entry name.
+     */
+    public static StringBuffer parseName( byte[] header, int offset, int length )
+    {
+        StringBuffer result = new StringBuffer( length );
+        int end = offset + length;
+
+        for ( int i = offset; i < end; ++i )
+        {
+            if ( header[ i ] == 0 )
+            {
+                break;
+            }
+
+            result.append( (char) header[ i ] );
+        }
+
+        return result;
+    }
+
+    /**
+     * Determine the number of bytes in an entry name.
+     *
+     * @param name   The header name from which to parse.
+     * @param offset The offset into the buffer from which to parse.
+     * @param length The number of header bytes to parse.
+     * @return The number of bytes in a header's entry name.
+     */
+    public static int getNameBytes( StringBuffer name, byte[] buf, int offset, int length )
+    {
+        int i;
+
+        for ( i = 0; i < length && i < name.length(); ++i )
+        {
+            buf[ offset + i ] = (byte) name.charAt( i );
+        }
+
+        for ( ; i < length; ++i )
+        {
+            buf[ offset + i ] = 0;
+        }
+
+        return offset + length;
+    }
+
+    /**
+     * Parse an octal integer from a header buffer.
+     *
+     * @param value  The header value
+     * @param offset The offset into the buffer from which to parse.
+     * @param length The number of header bytes to parse.
+     * @return The integer value of the octal bytes.
+     */
+    public static int getOctalBytes( long value, byte[] buf, int offset, int length )
+    {
+        int idx = length - 1;
+
+        buf[ offset + idx ] = 0;
+        --idx;
+        buf[ offset + idx ] = (byte) ' ';
+        --idx;
+
+        if ( value == 0 )
+        {
+            buf[ offset + idx ] = (byte) '0';
+            --idx;
+        }
+        else
+        {
+            for ( long val = value; idx >= 0 && val > 0; --idx )
+            {
+                buf[ offset + idx ] = (byte) ( (byte) '0' + (byte) ( val & 7 ) );
+                val = val >> 3;
+            }
+        }
+
+        for ( ; idx >= 0; --idx )
+        {
+            buf[ offset + idx ] = (byte) ' ';
+        }
+
+        return offset + length;
+    }
+
+    /**
+     * Parse an octal long integer from a header buffer.
+     *
+     * @param value  The header value
+     * @param offset The offset into the buffer from which to parse.
+     * @param length The number of header bytes to parse.
+     * @return The long value of the octal bytes.
+     */
+    public static int getLongOctalBytes( long value, byte[] buf, int offset, int length )
+    {
+        byte[] temp = new byte[length + 1];
+
+        getOctalBytes( value, temp, 0, length + 1 );
+        System.arraycopy( temp, 0, buf, offset, length );
+
+        return offset + length;
+    }
+
+    /**
+     * Parse the checksum octal integer from a header buffer.
+     *
+     * @param value  The header value
+     * @param offset The offset into the buffer from which to parse.
+     * @param length The number of header bytes to parse.
+     * @return The integer value of the entry's checksum.
+     */
+    public static int getCheckSumOctalBytes( long value, byte[] buf, int offset, int length )
+    {
+        getOctalBytes( value, buf, offset, length );
+
+        buf[ offset + length - 1 ] = (byte) ' ';
+        buf[ offset + length - 2 ] = 0;
+
+        return offset + length;
+    }
+
+    /**
+     * Compute the checksum of a tar entry header.
+     *
+     * @param buf The tar entry's header buffer.
+     * @return The computed checksum.
+     */
+    public static long computeCheckSum( byte[] buf )
+    {
+        long sum = 0;
+
+        for ( int i = 0; i < buf.length; ++i )
+        {
+            sum += 255 & buf[ i ];
+        }
+
+        return sum;
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/tar/TarUtils.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/util/AbstractFileSet.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/util/AbstractFileSet.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/AbstractFileSet.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/AbstractFileSet.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,124 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.util;
+
+import org.apache.geronimo.system.plugin.plexus.archiver.BaseFileSet;
+import org.apache.geronimo.system.plugin.plexus.io.fileselectors.FileSelector;
+
+
+/**
+ * Default implementation of {@link BaseFileSet}.
+ * @since 1.0-alpha-9
+ */
+public abstract class AbstractFileSet implements BaseFileSet
+{
+    private String prefix;
+
+    private String[] includes;
+
+    private String[] excludes;
+
+    private FileSelector[] fileSelectors;
+
+    private boolean caseSensitive = true;
+
+    private boolean usingDefaultExcludes = true;
+
+    private boolean includingEmptyDirectories = true;
+
+    /**
+     * Sets a string of patterns, which excluded files
+     * should match.
+     */
+    public void setExcludes( String[] excludes )
+    {
+        this.excludes = excludes;
+    }
+
+    public String[] getExcludes()
+    {
+        return excludes;
+    }
+
+    /**
+     * Sets a set of file selectors, which should be used
+     * to select the included files.
+     */
+    public void setFileSelectors( FileSelector[] fileSelectors )
+    {
+        this.fileSelectors = fileSelectors;
+    }
+
+    public FileSelector[] getFileSelectors()
+    {
+        return fileSelectors;
+    }
+
+    /**
+     * Sets a string of patterns, which included files
+     * should match.
+     */
+    public void setIncludes( String[] includes )
+    {
+        this.includes = includes;
+    }
+
+    public String[] getIncludes()
+    {
+        return includes;
+    }
+
+    /**
+     * Sets the prefix, which the file sets contents shall
+     * have.
+     */
+    public void setPrefix( String prefix )
+    {
+        this.prefix = prefix;
+    }
+
+    public String getPrefix()
+    {
+        return prefix;
+    }
+
+    /**
+     * Sets, whether the include/exclude patterns are
+     * case sensitive. Defaults to true.
+     */
+    public void setCaseSensitive( boolean caseSensitive )
+    {
+        this.caseSensitive = caseSensitive;
+    }
+
+    public boolean isCaseSensitive()
+    {
+        return caseSensitive;
+    }
+
+    /**
+     * Sets, whether the default excludes are being
+     * applied. Defaults to true.
+     */
+    public void setUsingDefaultExcludes( boolean usingDefaultExcludes )
+    {
+        this.usingDefaultExcludes = usingDefaultExcludes;
+    }
+
+    public boolean isUsingDefaultExcludes()
+    {
+        return usingDefaultExcludes;
+    }
+
+    /**
+     * Sets, whether empty directories are being included. Defaults
+     * to true.
+     */
+    public void setIncludingEmptyDirectories( boolean includingEmptyDirectories )
+    {
+        this.includingEmptyDirectories = includingEmptyDirectories;
+    }
+
+    public boolean isIncludingEmptyDirectories()
+    {
+        return includingEmptyDirectories;
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/AbstractFileSet.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/util/ArchiveEntryUtils.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/util/ArchiveEntryUtils.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/ArchiveEntryUtils.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/ArchiveEntryUtils.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,74 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.util;
+
+import org.apache.geronimo.system.plugin.plexus.archiver.ArchiverException;
+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.slf4j.Logger;
+
+import java.io.File;
+
+public final class ArchiveEntryUtils
+{
+
+    private ArchiveEntryUtils()
+    {
+    }
+
+    public static void chmod( File file, int mode, Logger logger )
+        throws ArchiverException
+    {
+        if ( !Os.isFamily( Os.FAMILY_UNIX ) )
+        {
+            return;
+        }
+
+        String m = Integer.toOctalString( mode & 0xfff );
+
+        try
+        {
+            Commandline commandline = new Commandline();
+
+            commandline.setWorkingDirectory( file.getParentFile().getAbsolutePath() );
+
+            commandline.setExecutable( "chmod" );
+
+            commandline.createArg().setValue( m );
+
+            String path = file.getAbsolutePath();
+
+            commandline.createArg().setValue( path );
+
+            // commenting this debug statement, since it can produce VERY verbose output...
+            // this method is called often during archive creation.
+//            logger.debug( "Executing:\n\n" + commandline.toString() + "\n\n" );
+
+            CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
+
+            CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
+
+            int exitCode = CommandLineUtils.executeCommandLine( commandline, stderr, stdout );
+
+            if ( exitCode != 0 )
+            {
+                logger.warn( "-------------------------------" );
+                logger.warn( "Standard error:" );
+                logger.warn( "-------------------------------" );
+                logger.warn( stderr.getOutput() );
+                logger.warn( "-------------------------------" );
+                logger.warn( "Standard output:" );
+                logger.warn( "-------------------------------" );
+                logger.warn( stdout.getOutput() );
+                logger.warn( "-------------------------------" );
+
+                throw new ArchiverException( "chmod exit code was: " + exitCode );
+            }
+        }
+        catch ( CommandLineException e )
+        {
+            throw new ArchiverException( "Error while executing chmod.", e );
+        }
+    }
+
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/ArchiveEntryUtils.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/util/Compressor.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/util/Compressor.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/Compressor.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/Compressor.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,231 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.util;
+
+/**
+ *
+ * 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 java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.geronimo.system.plugin.plexus.archiver.ArchiverException;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoFileResource;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoResource;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public abstract class Compressor
+{
+    private File destFile;
+
+    private PlexusIoResource source;
+    
+    /**
+     * the required destination file.
+     *
+     * @param compressFile
+     */
+    public void setDestFile( File compressFile )
+    {
+        this.destFile = compressFile;
+    }
+
+    public File getDestFile()
+    {
+        return destFile;
+    }
+
+    /**
+     * The resource to compress; required.
+     */
+    public void setSource( PlexusIoResource source )
+    {
+        this.source = source;
+    }
+
+    /**
+     * The resource to compress; required.
+     */
+    public PlexusIoResource getSource()
+    {
+        return source;
+    }
+
+    /**
+     * the file to compress; required.
+     * @deprecated Use {@link #getSource()}.
+     */
+    public void setSourceFile( File srcFile )
+    {
+        final PlexusIoFileResource res = new PlexusIoFileResource( srcFile );
+        setSource( res );
+    }
+
+    /**
+     * @deprecated Use {@link #getSource()}.
+     */
+    public File getSourceFile()
+    {
+        final PlexusIoResource res = getSource();
+        if ( res instanceof PlexusIoFileResource )
+        {
+            return ((PlexusIoFileResource) res).getFile();
+        }
+        return null;
+    }
+
+    /**
+     * validation routine
+     *
+     * @throws ArchiverException if anything is invalid
+     */
+    private void validate()
+        throws ArchiverException
+    {
+        if ( destFile == null )
+        {
+            throw new ArchiverException( "Destination file attribute is required" );
+        }
+
+        if ( destFile.isDirectory() )
+        {
+            throw new ArchiverException( "Destination file attribute must not "
+                                         + "represent a directory!" );
+        }
+
+        if ( source == null )
+        {
+            throw new ArchiverException( "Source file attribute is required" );
+        }
+
+        if ( source.isDirectory() )
+        {
+            throw new ArchiverException( "Source file attribute must not "
+                                         + "represent a directory!" );
+        }
+    }
+
+    /**
+     * validate, then hand off to the subclass
+     *
+     */
+    public void execute()
+        throws ArchiverException
+    {
+        validate();
+
+        try
+        {
+            if ( !source.isExisting() )
+            {
+//                getLogger().info( "Nothing to do: " + sourceFile.getAbsolutePath()
+//                    + " doesn't exist." );
+            }
+            else
+            {
+                final long l = source.getLastModified();
+                if ( l == PlexusIoResource.UNKNOWN_MODIFICATION_DATE
+                                ||  destFile.lastModified() == 0
+                                ||  destFile.lastModified() < l )
+                {
+                    compress();
+                }
+                else
+                {
+//                    getLogger().info( "Nothing to do: " + destFile.getAbsolutePath()
+//                        + " is up to date." );
+                }
+            }
+        }
+        finally
+        {
+            close();
+        }
+    }
+
+    /**
+     * compress a stream to an output stream
+     *
+     * @param in
+     * @param zOut
+     * @throws IOException
+     */
+    private void compressFile( InputStream in, OutputStream zOut )
+        throws IOException
+    {
+        byte[] buffer = new byte[8 * 1024];
+        int count = 0;
+        do
+        {
+            zOut.write( buffer, 0, count );
+            count = in.read( buffer, 0, buffer.length );
+        }
+        while ( count != -1 );
+    }
+
+    /**
+     * compress a file to an output stream
+     * @deprecated Use {@link #compress(PlexusIoResource, OutputStream)}.
+     */
+    protected void compressFile( File file, OutputStream zOut )
+        throws IOException
+    {
+        FileInputStream fIn = new FileInputStream( file );
+        try
+        {
+            compressFile( fIn, zOut );
+        }
+        finally
+        {
+            fIn.close();
+        }
+    }
+
+    /**
+     * compress a resource to an output stream
+     */
+    protected void compress( PlexusIoResource resource, OutputStream zOut )
+        throws IOException
+    {
+        InputStream fIn = resource.getContents();
+        try
+        {
+            compressFile( fIn, zOut );
+        }
+        finally
+        {
+            fIn.close();
+        }
+    }
+
+    /**
+     * subclasses must implement this method to do their compression
+     * 
+     * this is public so the process of compression and closing can be dealt with separately.
+     */
+    public abstract void compress()
+        throws ArchiverException;
+    
+    /**
+     * subclasses must implement this method to cleanup after compression
+     * 
+     * this is public so the process of compression and closing can be dealt with separately.
+     */
+    public abstract void close();
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/Compressor.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/util/DefaultArchivedFileSet.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/util/DefaultArchivedFileSet.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/DefaultArchivedFileSet.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/DefaultArchivedFileSet.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,28 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.util;
+
+import java.io.File;
+
+import org.apache.geronimo.system.plugin.plexus.archiver.ArchivedFileSet;
+
+
+/**
+ * Default implementation of {@link ArchivedFileSet}.
+ * @since 1.0-alpha-9
+ */
+public class DefaultArchivedFileSet extends AbstractFileSet implements ArchivedFileSet
+{
+    private File archive;
+
+    /**
+     * Sets the file sets archive.
+     */
+    public void setArchive( File archive )
+    {
+        this.archive = archive;
+    }
+
+    public File getArchive()
+    {
+        return archive;
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/DefaultArchivedFileSet.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/util/DefaultFileSet.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/util/DefaultFileSet.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/DefaultFileSet.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/DefaultFileSet.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,28 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.util;
+
+import java.io.File;
+
+import org.apache.geronimo.system.plugin.plexus.archiver.FileSet;
+
+
+/**
+ * Default implementation of {@link FileSet}.
+ * @since 1.0-alpha-9
+ */
+public class DefaultFileSet extends AbstractFileSet implements FileSet
+{
+    private File directory;
+
+    /**
+     * Sets the file sets base directory.
+     */
+    public void setDirectory( File directory )
+    {
+        this.directory = directory;
+    }
+
+    public File getDirectory()
+    {
+        return directory;
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/DefaultFileSet.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/util/EnumeratedAttribute.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/util/EnumeratedAttribute.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/EnumeratedAttribute.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/EnumeratedAttribute.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,133 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.util;
+
+/**
+ *
+ * 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.ArchiverException;
+
+/**
+ * Helper class for attributes that can only take one of a fixed list
+ * of values.
+ * <p/>
+ * <p>See {@link org.apache.tools.ant.taskdefs.FixCRLF FixCRLF} for an
+ * example.
+ */
+public abstract class EnumeratedAttribute
+{
+    /**
+     * The selected value in this enumeration.
+     */
+    protected String value;
+
+    /**
+     * the index of the selected value in the array.
+     */
+    private int index = -1;
+
+    /**
+     * This is the only method a subclass needs to implement.
+     *
+     * @return an array holding all possible values of the enumeration.
+     *         The order of elements must be fixed so that <tt>indexOfValue(String)</tt>
+     *         always return the same index for the same value.
+     */
+    public abstract String[] getValues();
+
+    /**
+     * bean constructor
+     */
+    protected EnumeratedAttribute()
+    {
+    }
+
+    /**
+     * Invoked by {@link org.apache.tools.ant.IntrospectionHelper IntrospectionHelper}.
+     */
+    public final void setValue( String value )
+        throws ArchiverException
+    {
+        int index = indexOfValue( value );
+        if ( index == -1 )
+        {
+            throw new ArchiverException( value + " is not a legal value for this attribute" );
+        }
+        this.index = index;
+        this.value = value;
+    }
+
+    /**
+     * Is this value included in the enumeration?
+     */
+    public final boolean containsValue( String value )
+    {
+        return ( indexOfValue( value ) != -1 );
+    }
+
+    /**
+     * get the index of a value in this enumeration.
+     *
+     * @param value the string value to look for.
+     * @return the index of the value in the array of strings
+     *         or -1 if it cannot be found.
+     * @see #getValues()
+     */
+    public final int indexOfValue( String value )
+    {
+        String[] values = getValues();
+        if ( values == null || value == null )
+        {
+            return -1;
+        }
+        for ( int i = 0; i < values.length; i++ )
+        {
+            if ( value.equals( values[ i ] ) )
+            {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    /**
+     * @return the selected value.
+     */
+    public final String getValue()
+    {
+        return value;
+    }
+
+    /**
+     * @return the index of the selected value in the array.
+     * @see #getValues()
+     */
+    public final int getIndex()
+    {
+        return index;
+    }
+
+
+    /**
+     * Convert the value to its string form.
+     *
+     * @return the string form of the value.
+     */
+    public String toString()
+    {
+        return getValue();
+    }
+
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/EnumeratedAttribute.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/util/FilterSupport.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/util/FilterSupport.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/FilterSupport.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/FilterSupport.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,57 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.util;
+
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.geronimo.system.plugin.plexus.archiver.ArchiveFileFilter;
+import org.apache.geronimo.system.plugin.plexus.archiver.ArchiveFilterException;
+import org.apache.geronimo.system.plugin.plexus.archiver.Archiver;
+import org.apache.geronimo.system.plugin.plexus.io.fileselectors.FileSelector;
+import org.slf4j.Logger;
+
+
+/**
+ * @deprecated Use {@link FileSelector} and {@link Archiver#addFileSet}.
+ */
+public class FilterSupport
+{
+    
+    private final List filters;
+    private final Logger logger;
+    
+    public FilterSupport( List filters, Logger logger )
+    {
+        this.filters = filters;
+        this.logger = logger;
+    }
+    
+    public boolean include( InputStream dataStream, String entryName )
+        throws ArchiveFilterException
+    {
+        boolean included = true;
+        
+        if ( filters != null && !filters.isEmpty() )
+        {
+            for ( Iterator it = filters.iterator(); it.hasNext(); )
+            {
+                ArchiveFileFilter filter = (ArchiveFileFilter) it.next();
+                
+                included = filter.include( dataStream, entryName );
+                
+                if ( !included )
+                {
+                    if ( logger.isDebugEnabled() )
+                    {
+                        logger.debug( "Entry: \'" + entryName + "\' excluded by filter: " + filter.getClass().getName() );
+                    }
+                    
+                    break;
+                }
+            }
+        }
+        
+        return included;
+    }
+
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/FilterSupport.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/util/ResourceUtils.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/util/ResourceUtils.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/ResourceUtils.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/ResourceUtils.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,127 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.util;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoFileResource;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoResource;
+import org.apache.geronimo.system.plugin.plexus.util.IOUtil;
+
+/**
+ * Utility class for work with {@link PlexusIoResource} instances.
+ */
+public class ResourceUtils
+{
+    /**
+     * Private constructor, to prevent accidental implementation.
+     */
+    private ResourceUtils()
+    {
+        // Does nothing
+    }
+
+    /**
+     * Queries, whether the given source is uptodate relative to
+     * the given destination.
+     */
+    public static boolean isUptodate( PlexusIoResource source, File destination )
+    {
+        return isUptodate( source, destination.lastModified() );
+    }
+
+    /**
+     * Queries, whether the given source is uptodate relative to
+     * the given modification date.
+     */
+    public static boolean isUptodate( PlexusIoResource source, long destinationDate )
+    {
+        final long s = source.getLastModified();
+        if ( s == PlexusIoResource.UNKNOWN_MODIFICATION_DATE )
+        {
+            return false;
+        }
+
+        if ( destinationDate == 0 )
+        {
+            return false;
+        }
+
+        return destinationDate > s;
+    }
+
+    /**
+     * Queries, whether the given source is uptodate relative to
+     * the given modification date.
+     */
+    public static boolean isUptodate( long sourceDate, long destinationDate )
+    {
+        if ( sourceDate == PlexusIoResource.UNKNOWN_MODIFICATION_DATE )
+        {
+            return false;
+        }
+
+        if ( destinationDate == 0 )
+        {
+            return false;
+        }
+
+        return destinationDate > sourceDate;
+    }
+
+    /**
+     * Copies the sources contents to the given destination file.
+     */
+    public static void copyFile( PlexusIoResource in, File outFile )
+        throws IOException
+    {
+        InputStream input = null;
+        OutputStream output = null;
+        try
+        {
+            input = in.getContents();
+            output = new FileOutputStream( outFile );
+            IOUtil.copy( input, output );
+            input.close();
+            input = null;
+            output.close();
+            output = null;
+        }
+        finally
+        {
+            IOUtil.close( input );
+            IOUtil.close( output );
+        }
+    }
+
+    /**
+     * Checks, whether the resource and the file are identical.
+     */
+    public static boolean isSame( PlexusIoResource resource, File file )
+    {
+        if ( resource instanceof PlexusIoFileResource )
+        {
+            File resourceFile = ((PlexusIoFileResource) resource).getFile();
+            return file.equals( resourceFile );
+        }
+        return false;
+    }
+
+    /**
+     * Checks, whether the resource and the file are identical.
+     * Uses {@link File#getCanonicalFile()} for comparison, which is much
+     * slower than comparing the files.
+     */
+    public static boolean isCanonicalizedSame( PlexusIoResource resource, File file )
+        throws IOException
+    {
+        if ( resource instanceof PlexusIoFileResource )
+        {
+            File resourceFile = ((PlexusIoFileResource) resource).getFile();
+            return file.getCanonicalFile().equals( resourceFile.getCanonicalFile() );
+        }
+        return false;
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/util/ResourceUtils.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/war/WarArchiver.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/war/WarArchiver.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/war/WarArchiver.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/war/WarArchiver.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,197 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.war;
+
+/*
+ * Copyright  2000-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.ArchiveEntry;
+import org.apache.geronimo.system.plugin.plexus.archiver.ArchiverException;
+import org.apache.geronimo.system.plugin.plexus.archiver.jar.JarArchiver;
+import org.apache.geronimo.system.plugin.plexus.archiver.util.ResourceUtils;
+import org.apache.geronimo.system.plugin.plexus.archiver.zip.ZipOutputStream;
+
+import java.io.File;
+import java.io.IOException;
+
+
+/**
+ * An extension of &lt;jar&gt; to create a WAR archive.
+ * Contains special treatment for files that should end up in the
+ * <code>WEB-INF/lib</code>, <code>WEB-INF/classes</code> or
+ * <code>WEB-INF</code> directories of the Web Application Archive.</p>
+ * <p>(The War task is a shortcut for specifying the particular layout of a WAR file.
+ * The same thing can be accomplished by using the <i>prefix</i> and <i>fullpath</i>
+ * attributes of zipfilesets in a Zip or Jar task.)</p>
+ * <p>The extended zipfileset element from the zip task
+ * (with attributes <i>prefix</i>, <i>fullpath</i>, and <i>src</i>)
+ * is available in the War task.</p>
+ *
+ * @see JarArchiver
+ */
+public class WarArchiver
+    extends JarArchiver
+{
+
+    /**
+     * our web.xml deployment descriptor
+     */
+    private File deploymentDescriptor;
+
+    /**
+     * flag set if finding the webxml is to be expected.
+     */
+    private boolean ignoreWebxml = true;
+
+    /**
+     * flag set if the descriptor is added
+     */
+    private boolean descriptorAdded;
+
+    public void setIgnoreWebxml( boolean ignore ) {
+        ignoreWebxml = ignore;
+    }
+
+    public WarArchiver()
+    {
+        super();
+        archiveType = "war";
+    }
+
+    /**
+     * set the deployment descriptor to use (WEB-INF/web.xml);
+     * required unless <tt>update=true</tt>
+     */
+    public void setWebxml( File descr )
+        throws ArchiverException
+    {
+        deploymentDescriptor = descr;
+        if ( !deploymentDescriptor.exists() )
+        {
+            throw new ArchiverException( "Deployment descriptor: "
+                                         + deploymentDescriptor
+                                         + " does not exist." );
+        }
+
+        addFile( descr, "WEB-INF/web.xml" );
+    }
+
+    /**
+     * add a file under WEB-INF/lib/
+     */
+
+    public void addLib( File fileName )
+        throws ArchiverException
+    {
+        addDirectory( fileName.getParentFile(), "WEB-INF/lib/", new String[]{fileName.getName()}, null );
+    }
+
+    /**
+     * add files under WEB-INF/lib/
+     */
+
+    public void addLibs( File directoryName, String[] includes, String[] excludes )
+        throws ArchiverException
+    {
+        addDirectory( directoryName, "WEB-INF/lib/", includes, excludes );
+    }
+
+    /**
+     * add a file under WEB-INF/lib/
+     */
+
+    public void addClass( File fileName )
+        throws ArchiverException
+    {
+        addDirectory( fileName.getParentFile(), "WEB-INF/classes/", new String[]{fileName.getName()}, null );
+    }
+
+    /**
+     * add files under WEB-INF/classes
+     */
+    public void addClasses( File directoryName, String[] includes, String[] excludes )
+        throws ArchiverException
+    {
+        addDirectory( directoryName, "WEB-INF/classes/", includes, excludes );
+    }
+
+    /**
+     * files to add under WEB-INF;
+     */
+    public void addWebinf( File directoryName, String[] includes, String[] excludes )
+        throws ArchiverException
+    {
+        addDirectory( directoryName, "WEB-INF/", includes, excludes );
+    }
+
+    /**
+     * override of  parent; validates configuration
+     * before initializing the output stream.
+     */
+    protected void initZipOutputStream( ZipOutputStream zOut )
+        throws IOException, ArchiverException
+    {
+        // If no webxml file is specified, it's an error.
+        if ( ignoreWebxml && deploymentDescriptor == null && !isInUpdateMode() )
+        {
+            throw new ArchiverException( "webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)" );
+        }
+        super.initZipOutputStream( zOut );
+    }
+
+    /**
+     * Overridden from ZipArchiver class to deal with web.xml
+     */
+    protected void zipFile( ArchiveEntry entry, ZipOutputStream zOut, String vPath, int mode )
+        throws IOException, ArchiverException
+    {
+        // If the file being added is WEB-INF/web.xml, we warn if it's
+        // not the one specified in the "webxml" attribute - or if
+        // it's being added twice, meaning the same file is specified
+        // by the "webxml" attribute and in a <fileset> element.
+        if ( vPath.equalsIgnoreCase( "WEB-INF/web.xml" ) )
+        {
+            if ( descriptorAdded || ( ignoreWebxml
+                 && ( deploymentDescriptor == null
+                     || !ResourceUtils.isCanonicalizedSame( entry.getResource(), deploymentDescriptor ) ) ) )
+            {
+                getLogger().warn( "Warning: selected " + archiveType
+                                  + " files include a WEB-INF/web.xml which will be ignored "
+                                  + "\n(webxml attribute is missing from "
+                                  + archiveType + " task, or ignoreWebxml attribute is specified as 'true')" );
+            }
+            else
+            {
+                super.zipFile( entry, zOut, vPath );
+                descriptorAdded = true;
+            }
+        }
+        else
+        {
+            super.zipFile( entry, zOut, vPath );
+        }
+    }
+
+    /**
+     * Make sure we don't think we already have a web.xml next time this task
+     * gets executed.
+     */
+    protected void cleanUp()
+    {
+        descriptorAdded = false;
+        ignoreWebxml = true;
+        super.cleanUp();
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/war/WarArchiver.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/AbstractZipArchiver.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/AbstractZipArchiver.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AbstractZipArchiver.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/zip/AbstractZipArchiver.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,812 @@
+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 java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Stack;
+import java.util.Vector;
+import java.util.zip.CRC32;
+
+import org.apache.geronimo.system.plugin.plexus.archiver.AbstractArchiver;
+import org.apache.geronimo.system.plugin.plexus.archiver.ArchiveEntry;
+import org.apache.geronimo.system.plugin.plexus.archiver.Archiver;
+import org.apache.geronimo.system.plugin.plexus.archiver.ArchiverException;
+import org.apache.geronimo.system.plugin.plexus.archiver.ResourceIterator;
+import org.apache.geronimo.system.plugin.plexus.archiver.UnixStat;
+import org.apache.geronimo.system.plugin.plexus.archiver.util.ResourceUtils;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoFileResource;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoResource;
+import org.apache.geronimo.system.plugin.plexus.util.FileUtils;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public abstract class AbstractZipArchiver
+    extends AbstractArchiver
+{
+    
+    private String comment;
+
+    /**
+     * Encoding to use for filenames, defaults to the platform's
+     * default encoding.
+     */
+    private String encoding;
+
+    private boolean doCompress = true;
+
+    private boolean doUpdate = false;
+
+    // shadow of the above if the value is altered in execute
+    private boolean savedDoUpdate = false;
+
+    protected String archiveType = "zip";
+
+    /*
+     * Whether the original compression of entries coming from a ZIP
+     * archive should be kept (for example when updating an archive).
+     */
+    //not used: private boolean keepCompression = false;
+    private boolean doFilesonly = false;
+
+    protected Hashtable entries = new Hashtable();
+
+    protected Hashtable addedDirs = new Hashtable();
+
+    private Vector addedFiles = new Vector();
+
+    private static final long EMPTY_CRC = new CRC32().getValue();
+
+    protected boolean doubleFilePass = false;
+
+    protected boolean skipWriting = false;
+    
+    /**
+     * @deprecated Use {@link Archiver#setDuplicateBehavior(String)} instead.
+     */
+    protected String duplicate = Archiver.DUPLICATES_SKIP;
+
+    /**
+     * true when we are adding new files into the Zip file, as opposed
+     * to adding back the unchanged files
+     */
+    protected boolean addingNewFiles = false;
+
+    /**
+     * Whether the file modification times will be rounded up to the
+     * next even number of seconds.
+     */
+    private boolean roundUp = true;
+
+    // Renamed version of original file, if it exists
+    private File renamedFile = null;
+
+    private File zipFile;
+
+    private boolean success;
+
+    private ZipOutputStream zOut;
+
+    public String getComment()
+    {
+        return comment;
+    }
+
+    public void setComment( String comment )
+    {
+        this.comment = comment;
+    }
+
+    public String getEncoding()
+    {
+        return encoding;
+    }
+
+    public void setEncoding( String encoding )
+    {
+        this.encoding = encoding;
+    }
+
+    public void setCompress( boolean compress )
+    {
+        this.doCompress = compress;
+    }
+
+    public boolean isCompress()
+    {
+        return doCompress;
+    }
+
+    public void setUpdateMode( boolean update )
+    {
+        this.doUpdate = update;
+        savedDoUpdate = doUpdate;
+    }
+
+    public boolean isInUpdateMode()
+    {
+        return doUpdate;
+    }
+
+//    /**
+//     * A 3 digit octal string, specify the user, group and
+//     * other modes in the standard Unix fashion;
+//     * optional, default=0644
+//     *
+//     * @deprecated use AbstractArchiver.setDefaultFileMode(int) instead.
+//     */
+//    public void setFileMode( String octalString )
+//    {
+//        setDefaultFileMode( Integer.parseInt( octalString, 8 ) );
+//    }
+//
+//    /**
+//     * @deprecated use AbstractArchiver.getDefaultFileMode() instead.
+//     */
+//    public int getFileMode()
+//    {
+//        return getDefaultFileMode();
+//    }
+//
+//    /**
+//     * A 3 digit octal string, specify the user, group and
+//     * other modes in the standard Unix fashion;
+//     * optional, default=0755
+//     *
+//     * @deprecated use AbstractArchiver.setDefaultDirectoryMode(int).
+//     */
+//    public void setDirMode( String octalString )
+//    {
+//        setDefaultDirectoryMode( Integer.parseInt( octalString, 8 ) );
+//    }
+//
+//    /**
+//     * @deprecated use AbstractArchiver.getDefaultDirectoryMode() instead.
+//     */
+//    public int getDirMode()
+//    {
+//        return getDefaultDirectoryMode();
+//    }
+//
+    /**
+     * If true, emulate Sun's jar utility by not adding parent directories;
+     * optional, defaults to false.
+     */
+    public void setFilesonly( boolean f )
+    {
+        doFilesonly = f;
+    }
+
+    public boolean isFilesonly()
+    {
+        return doFilesonly;
+    }
+
+    /**
+     * Whether the file modification times will be rounded up to the
+     * next even number of seconds.
+     * <p/>
+     * <p>Zip archives store file modification times with a
+     * granularity of two seconds, so the times will either be rounded
+     * up or down.  If you round down, the archive will always seem
+     * out-of-date when you rerun the task, so the default is to round
+     * up.  Rounding up may lead to a different type of problems like
+     * JSPs inside a web archive that seem to be slightly more recent
+     * than precompiled pages, rendering precompilation useless.</p>
+     */
+    public void setRoundUp( boolean r )
+    {
+        roundUp = r;
+    }
+
+    public boolean isRoundUp()
+    {
+        return roundUp;
+    }
+
+    protected void execute()
+        throws ArchiverException, IOException
+    {
+        if ( ! checkForced() )
+        {
+            return;
+        }
+
+        if ( doubleFilePass )
+        {
+            skipWriting = true;
+            createArchiveMain();
+            skipWriting = false;
+            createArchiveMain();
+        }
+        else
+        {
+            createArchiveMain();
+        }
+        
+        finalizeZipOutputStream( zOut );
+    }
+
+    protected void finalizeZipOutputStream( ZipOutputStream zOut )
+        throws IOException, ArchiverException
+    {
+    }
+
+    private void createArchiveMain()
+        throws ArchiverException, IOException
+    {
+        if ( !Archiver.DUPLICATES_SKIP.equals( duplicate ) )
+        {
+            setDuplicateBehavior( duplicate );
+        }
+        
+        ResourceIterator iter = getResources();
+        if ( !iter.hasNext() && !hasVirtualFiles() )
+        {
+            throw new ArchiverException( "You must set at least one file." );
+        }
+
+        zipFile = getDestFile();
+
+        if ( zipFile == null )
+        {
+            throw new ArchiverException( "You must set the destination " + archiveType + "file." );
+        }
+
+        if ( zipFile.exists() && !zipFile.isFile() )
+        {
+            throw new ArchiverException( zipFile + " isn't a file." );
+        }
+
+        if ( zipFile.exists() && !zipFile.canWrite() )
+        {
+            throw new ArchiverException( zipFile + " is read-only." );
+        }
+
+        // Whether or not an actual update is required -
+        // we don't need to update if the original file doesn't exist
+
+        addingNewFiles = true;
+
+        if ( doUpdate && !zipFile.exists() )
+        {
+            doUpdate = false;
+            getLogger().debug( "ignoring update attribute as " + archiveType + " doesn't exist." );
+        }
+
+        success = false;
+
+        if ( doUpdate )
+        {
+            renamedFile = FileUtils.createTempFile( "zip", ".tmp", zipFile.getParentFile() );
+            renamedFile.deleteOnExit();
+
+            try
+            {
+                FileUtils.rename( zipFile, renamedFile );
+            }
+            catch ( SecurityException e )
+            {
+                getLogger().debug( e.toString() );
+                throw new ArchiverException( "Not allowed to rename old file (" + zipFile.getAbsolutePath()
+                    + ") to temporary file", e );
+            }
+            catch ( IOException e )
+            {
+                getLogger().debug( e.toString() );
+                throw new ArchiverException( "Unable to rename old file (" + zipFile.getAbsolutePath()
+                    + ") to temporary file", e );
+            }
+        }
+
+        String action = doUpdate ? "Updating " : "Building ";
+
+        getLogger().info( action + archiveType + ": " + zipFile.getAbsolutePath() );
+
+        if ( !skipWriting )
+        {
+            zOut = new ZipOutputStream( zipFile );
+
+            zOut.setEncoding( encoding );
+            if ( doCompress )
+            {
+                zOut.setMethod( ZipOutputStream.DEFLATED );
+            }
+            else
+            {
+                zOut.setMethod( ZipOutputStream.STORED );
+            }
+        }
+        initZipOutputStream( zOut );
+
+        // Add the new files to the archive.
+        addResources( iter, zOut );
+
+        // If we've been successful on an update, delete the
+        // temporary file
+        if ( doUpdate )
+        {
+            if ( !renamedFile.delete() )
+            {
+                getLogger().warn( "Warning: unable to delete temporary file " + renamedFile.getName() );
+            }
+        }
+        success = true;
+    }
+
+    protected Map getZipEntryNames( File file )
+        throws IOException
+    {
+        if ( !file.exists()  ||  !doUpdate )
+        {
+            return Collections.EMPTY_MAP;
+        }
+        final Map entries = new HashMap();
+        final ZipFile zipFile = new ZipFile( file );
+        for ( Enumeration en = zipFile.getEntries();  en.hasMoreElements();  )
+        {
+            ZipEntry ze = (ZipEntry) en.nextElement();
+            entries.put( ze.getName(), new Long( ze.getLastModificationTime() ) );
+        }
+        return entries;
+    }
+
+    protected boolean isFileAdded( ArchiveEntry entry, Map entries )
+    {
+        return !entries.containsKey( entry.getName() );
+    }
+
+    protected boolean isFileUpdated( ArchiveEntry entry, Map entries )
+    {
+        Long l = (Long) entries.get( entry.getName() );
+        if ( l == null )
+        {
+            return false;
+        }
+        return l.longValue() == -1  ||  !ResourceUtils.isUptodate( entry.getResource(), l.longValue() );
+    }
+
+    /**
+     * Add the given resources.
+     *
+     * @param resources the resources to add
+     * @param zOut      the stream to write to
+     */
+    protected final void addResources( ResourceIterator resources, ZipOutputStream zOut )
+        throws IOException, ArchiverException
+    {
+        File base = null;
+
+        while ( resources.hasNext() )
+        {
+            ArchiveEntry entry = resources.next();
+            String name = entry.getName();
+            name = name.replace( File.separatorChar, '/' );
+            
+            if ( "".equals( name ) )
+            {
+                continue;
+            }
+
+            if ( entry.getResource().isDirectory() && !name.endsWith( "/" ) )
+            {
+                name = name + "/";
+            }
+
+            addParentDirs( base, name, zOut, "" );
+
+            if ( entry.getResource().isFile() )
+            {
+                zipFile( entry, zOut, name );
+            }
+            else
+            {
+                zipDir( entry.getResource(), zOut, name, entry.getMode() );
+            }
+        }
+    }
+
+    /**
+     * Ensure all parent dirs of a given entry have been added.
+     */
+    protected final void addParentDirs( File baseDir, String entry, ZipOutputStream zOut, String prefix )
+        throws IOException
+    {
+        if ( !doFilesonly && getIncludeEmptyDirs() )
+        {
+            Stack directories = new Stack();
+
+            // Don't include the last entry itself if it's
+            // a dir; it will be added on its own.
+            int slashPos = entry.length() - ( entry.endsWith( "/" ) ? 1 : 0 );
+
+            while ( ( slashPos = entry.lastIndexOf( '/', slashPos - 1 ) ) != -1 )
+            {
+                String dir = entry.substring( 0, slashPos + 1 );
+
+                if ( addedDirs.contains( prefix + dir ) )
+                {
+                    break;
+                }
+
+                directories.push( dir );
+            }
+
+            while ( !directories.isEmpty() )
+            {
+                String dir = (String) directories.pop();
+                File f;
+                if ( baseDir != null )
+                {
+                    f = new File( baseDir, dir );
+                }
+                else
+                {
+                    f = new File( dir );
+                }
+                final PlexusIoFileResource res = new PlexusIoFileResource( f );
+                zipDir( res, zOut, prefix + dir, getRawDefaultDirectoryMode() );
+            }
+        }
+    }
+
+    /**
+     * Adds a new entry to the archive, takes care of duplicates as well.
+     *
+     * @param in           the stream to read data for the entry from.
+     * @param zOut         the stream to write to.
+     * @param vPath        the name this entry shall have in the archive.
+     * @param lastModified last modification time for the entry.
+     * @param fromArchive  the original archive we are copying this
+     *                     entry from, will be null if we are not copying from an archive.
+     * @param mode         the Unix permissions to set.
+     */
+    protected void zipFile( InputStream in, ZipOutputStream zOut, String vPath, long lastModified, File fromArchive,
+                            int mode )
+        throws IOException, ArchiverException
+    {
+        getLogger().debug( "adding entry " + vPath );
+
+        entries.put( vPath, vPath );
+
+        if ( !skipWriting )
+        {
+            ZipEntry ze = new ZipEntry( vPath );
+            ze.setTime( lastModified );
+            ze.setMethod( doCompress ? ZipEntry.DEFLATED : ZipEntry.STORED );
+
+            /*
+             * ZipOutputStream.putNextEntry expects the ZipEntry to
+             * know its size and the CRC sum before you start writing
+             * the data when using STORED mode - unless it is seekable.
+             *
+             * This forces us to process the data twice.
+             */
+            if ( !zOut.isSeekable() && !doCompress )
+            {
+                long size = 0;
+                CRC32 cal = new CRC32();
+                if ( !in.markSupported() )
+                {
+                    // Store data into a byte[]
+                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+                    byte[] buffer = new byte[8 * 1024];
+                    int count = 0;
+
+                    do
+                    {
+                        size += count;
+                        cal.update( buffer, 0, count );
+                        bos.write( buffer, 0, count );
+                        count = in.read( buffer, 0, buffer.length );
+                    }
+                    while ( count != -1 );
+
+                    in = new ByteArrayInputStream( bos.toByteArray() );
+                }
+                else
+                {
+                    in.mark( Integer.MAX_VALUE );
+                    byte[] buffer = new byte[8 * 1024];
+                    int count = 0;
+
+                    do
+                    {
+                        size += count;
+                        cal.update( buffer, 0, count );
+                        count = in.read( buffer, 0, buffer.length );
+                    }
+                    while ( count != -1 );
+
+                    in.reset();
+                }
+                ze.setSize( size );
+                ze.setCrc( cal.getValue() );
+            }
+
+            ze.setUnixMode( UnixStat.FILE_FLAG | mode );
+            zOut.putNextEntry( ze );
+
+            byte[] buffer = new byte[8 * 1024];
+            int count = 0;
+            do
+            {
+                if ( count != 0 )
+                {
+                    zOut.write( buffer, 0, count );
+                }
+                count = in.read( buffer, 0, buffer.length );
+            }
+            while ( count != -1 );
+        }
+
+        addedFiles.addElement( vPath );
+    }
+
+    /**
+     * Method that gets called when adding from java.io.File instances.
+     * <p/>
+     * <p>This implementation delegates to the six-arg version.</p>
+     *
+     * @param entry the file to add to the archive
+     * @param zOut  the stream to write to
+     * @param vPath the name this entry shall have in the archive
+     */
+    protected void zipFile( ArchiveEntry entry, ZipOutputStream zOut, String vPath )
+        throws IOException, ArchiverException
+    {
+        if ( ResourceUtils.isSame( entry.getResource(), getDestFile() ) )
+        {
+            throw new ArchiverException( "A zip file cannot include itself" );
+        }
+
+        InputStream fIn = entry.getInputStream();
+        try
+        {
+            // ZIPs store time with a granularity of 2 seconds, round up
+            final long lastModified = entry.getResource().getLastModified() + ( roundUp ? 1999 : 0 );
+            zipFile( fIn, zOut, vPath, lastModified, null, entry.getMode() );
+        }
+        finally
+        {
+            fIn.close();
+        }
+    }
+
+    /**
+     *
+     */
+    protected void zipDir( PlexusIoResource dir, ZipOutputStream zOut, String vPath, int mode )
+        throws IOException
+    {
+        if ( addedDirs.get( vPath ) != null )
+        {
+            // don't add directories we've already added.
+            // no warning if we try, it is harmless in and of itself
+            return;
+        }
+
+        getLogger().debug( "adding directory " + vPath );
+        addedDirs.put( vPath, vPath );
+
+        if ( !skipWriting )
+        {
+            ZipEntry ze = new ZipEntry( vPath );
+
+            if ( dir != null && dir.isExisting() )
+            {
+                // ZIPs store time with a granularity of 2 seconds, round up
+                final long lastModified = dir.getLastModified() + ( roundUp ? 1999 : 0 );
+                ze.setTime( lastModified );
+            }
+            else
+            {
+                // ZIPs store time with a granularity of 2 seconds, round up
+                ze.setTime( System.currentTimeMillis() + ( roundUp ? 1999 : 0 ) );
+            }
+            ze.setSize( 0 );
+            ze.setMethod( ZipEntry.STORED );
+            // This is faintly ridiculous:
+            ze.setCrc( EMPTY_CRC );
+            ze.setUnixMode( mode );
+
+            zOut.putNextEntry( ze );
+        }
+    }
+
+    /**
+     * Create an empty zip file
+     *
+     * @return true for historic reasons
+     */
+    protected boolean createEmptyZip( File zipFile )
+        throws ArchiverException
+    {
+        // In this case using java.util.zip will not work
+        // because it does not permit a zero-entry archive.
+        // Must create it manually.
+        getLogger().info( "Note: creating empty " + archiveType + " archive " + zipFile );
+        OutputStream os = null;
+        try
+        {
+            os = new FileOutputStream( zipFile );
+            // Cf. PKZIP specification.
+            byte[] empty = new byte[22];
+            empty[0] = 80; // P
+            empty[1] = 75; // K
+            empty[2] = 5;
+            empty[3] = 6;
+            // remainder zeros
+            os.write( empty );
+        }
+        catch ( IOException ioe )
+        {
+            throw new ArchiverException( "Could not create empty ZIP archive " + "(" + ioe.getMessage() + ")", ioe );
+        }
+        finally
+        {
+            if ( os != null )
+            {
+                try
+                {
+                    os.close();
+                }
+                catch ( IOException e )
+                {
+                    //ignore
+                }
+            }
+        }
+        return true;
+    }
+
+    /**
+     * Do any clean up necessary to allow this instance to be used again.
+     * <p/>
+     * <p>When we get here, the Zip file has been closed and all we
+     * need to do is to reset some globals.</p>
+     * <p/>
+     * <p>This method will only reset globals that have been changed
+     * during execute(), it will not alter the attributes or nested
+     * child elements.  If you want to reset the instance so that you
+     * can later zip a completely different set of files, you must use
+     * the reset method.</p>
+     *
+     * @see #reset
+     */
+    protected void cleanUp()
+    {
+        super.cleanUp();
+        addedDirs.clear();
+        addedFiles.removeAllElements();
+        entries.clear();
+        addingNewFiles = false;
+        doUpdate = savedDoUpdate;
+        success = false;
+        zOut = null;
+        renamedFile = null;
+        zipFile = null;
+    }
+
+    /**
+     * Makes this instance reset all attributes to their default
+     * values and forget all children.
+     *
+     * @see #cleanUp
+     */
+    public void reset()
+    {
+        setDestFile( null );
+//        duplicate = "add";
+        archiveType = "zip";
+        doCompress = true;
+        doUpdate = false;
+        doFilesonly = false;
+        encoding = null;
+    }
+
+    /**
+     * method for subclasses to override
+     */
+    protected void initZipOutputStream( ZipOutputStream zOut )
+        throws IOException, ArchiverException
+    {
+    }
+
+    /**
+     * method for subclasses to override
+     */
+    public boolean isSupportingForced()
+    {
+        return true;
+    }
+
+    protected boolean revert( StringBuffer messageBuffer )
+    {
+        int initLength = messageBuffer.length();
+
+        // delete a bogus ZIP file (but only if it's not the original one)
+        if ( ( !doUpdate || renamedFile != null ) && !zipFile.delete() )
+        {
+            messageBuffer.append( " (and the archive is probably corrupt but I could not delete it)" );
+        }
+
+        if ( doUpdate && renamedFile != null )
+        {
+            try
+            {
+                FileUtils.rename( renamedFile, zipFile );
+            }
+            catch ( IOException e )
+            {
+                messageBuffer.append( " (and I couldn't rename the temporary file " );
+                messageBuffer.append( renamedFile.getName() );
+                messageBuffer.append( " back)" );
+            }
+        }
+
+        return messageBuffer.length() == initLength;
+    }
+
+    protected void close()
+        throws IOException
+    {
+        // Close the output stream.
+        try
+        {
+            if ( zOut != null )
+            {
+                zOut.close();
+            }
+        }
+        catch ( IOException ex )
+        {
+            // If we're in this finally clause because of an
+            // exception, we don't really care if there's an
+            // exception when closing the stream. E.g. if it
+            // throws "ZIP file must have at least one entry",
+            // because an exception happened before we added
+            // any files, then we must swallow this
+            // exception. Otherwise, the error that's reported
+            // will be the close() error, which is not the
+            // real cause of the problem.
+            if ( success )
+            {
+                throw ex;
+            }
+        }
+    }
+
+    protected String getArchiveType()
+    {
+        return archiveType;
+    }
+
+}

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