geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r821961 [7/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/java...
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/bzip2/PlexusIoBzip2ResourceCollection.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/bzip2/PlexusIoBzip2ResourceCollection.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/bzip2/PlexusIoBzip2ResourceCollection.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/bzip2/PlexusIoBzip2ResourceCollection.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,45 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.bzip2;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoCompressedFileResourceCollection;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoResourceCollection;
+import org.apache.geronimo.system.plugin.plexus.util.IOUtil;
+
+
+/**
+ * Implementation of {@link PlexusIoResourceCollection} for
+ * bzip2 compressed files.
+ */
+public class PlexusIoBzip2ResourceCollection
+    extends PlexusIoCompressedFileResourceCollection
+{
+    protected InputStream getInputStream( File file )
+        throws IOException
+    {
+        InputStream fis = new FileInputStream( file );
+        try
+        {
+            final InputStream result = BZip2UnArchiver.getBZip2InputStream( fis );
+            if ( result == null )
+            {
+                throw new IOException( file.getPath()
+                                       + " is an invalid bzip2 file. " );
+            }
+            fis = null;
+            return result;
+        }
+        finally
+        {
+            IOUtil.close( fis );
+        }
+    }
+
+    protected String getDefaultExtension()
+    {
+        return ".bz2";
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/bzip2/PlexusIoBzip2ResourceCollection.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/dir/DirectoryArchiver.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/dir/DirectoryArchiver.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/dir/DirectoryArchiver.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/dir/DirectoryArchiver.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,174 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.dir;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+
+import 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.ArchiverException;
+import org.apache.geronimo.system.plugin.plexus.archiver.ResourceIterator;
+import org.apache.geronimo.system.plugin.plexus.archiver.util.ArchiveEntryUtils;
+import org.apache.geronimo.system.plugin.plexus.archiver.util.ResourceUtils;
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoResource;
+
+
+/**
+ * A plexus archiver implementation that stores the files to archive in a
+ * directory.
+ */
+public class DirectoryArchiver
+    extends AbstractArchiver
+{
+    public void resetArchiver()
+    {
+        cleanUp();
+    }
+
+    public void execute()
+        throws ArchiverException, IOException
+    {
+        //Most of this method was copied from org.apache.geronimo.system.plugin.plexus.archiver.tar.TarArchiver
+        //and modified to store files in a directory, not a tar archive.
+        ResourceIterator iter = getResources();
+        if ( !iter.hasNext() )
+        {
+            throw new ArchiverException( "You must set at least one file." );
+        }
+
+        File destDirectory = getDestFile();
+        if ( destDirectory == null )
+        {
+            throw new ArchiverException( "You must set the destination directory." );
+        }
+        if ( destDirectory.exists() && !destDirectory.isDirectory() )
+        {
+            throw new ArchiverException( destDirectory + " is not a directory." );
+        }
+        if ( destDirectory.exists() && !destDirectory.canWrite() )
+        {
+            throw new ArchiverException( destDirectory + " is not writable." );
+        }
+
+        getLogger().info( "Copying files to " + destDirectory.getAbsolutePath() );
+
+        try
+        {
+            while( iter.hasNext() )
+            {
+                ArchiveEntry f = iter.next();
+                // Check if we don't add directory file in itself
+                if ( ResourceUtils.isSame( f.getResource(), destDirectory ) )
+                {
+                    throw new ArchiverException( "The destination directory cannot include itself." );
+                }
+                String fileName = f.getName();
+                String destDir = destDirectory.getCanonicalPath();
+                fileName = destDir + File.separator + fileName;
+                copyFile( f, fileName );
+            }
+        }
+        catch ( IOException ioe )
+        {
+            String message = "Problem copying files : " + ioe.getMessage();
+            throw new ArchiverException( message, ioe );
+        }
+    }
+
+    /**
+     * Copies the specified file to the specified path, creating any ancestor directory
+     * structure as necessary.
+     *
+     * @param file  The file to copy (IOException will be thrown if this does not exist)
+     * @param vPath The fully qualified path to copy the file to.
+     * @throws ArchiverException If there is a problem creating the directory structure
+     * @throws IOException       If there is a problem copying the file
+     */
+    protected void copyFile( ArchiveEntry entry, String vPath )
+        throws ArchiverException, IOException
+    {
+        // don't add "" to the archive
+        if ( vPath.length() <= 0 )
+        {
+            return;
+        }
+
+        PlexusIoResource in = entry.getResource();
+        File outFile = new File( vPath );
+        
+        final long inLastModified = in.getLastModified();
+        long outLastModified = outFile.lastModified();
+        if ( ResourceUtils.isUptodate( inLastModified, outLastModified ) )
+        {
+            return;
+        }
+        
+        outFile.setLastModified( inLastModified == PlexusIoResource.UNKNOWN_MODIFICATION_DATE
+                                 ? System.currentTimeMillis() : inLastModified );
+
+        if ( ! in.isDirectory() )
+        {
+            if ( ! outFile.getParentFile().exists() )
+            {
+                //create the parent directory...
+                if ( ! outFile.getParentFile().mkdirs() )
+                {
+                    //Failure, unable to create specified directory for some unknown reason.
+                    throw new ArchiverException( "Unable to create directory or parent directory of " + outFile );
+                }
+            }
+            ResourceUtils.copyFile( in, outFile );
+            ArchiveEntryUtils.chmod( outFile, entry.getMode(), getLogger() );
+        }
+        else
+        { //file is a directory
+            if ( outFile.exists() )
+            {
+                if ( ! outFile.isDirectory() )
+                {
+                    //should we just delete the file and replace it with a directory?
+                    //throw an exception, let the user delete the file manually.
+                    throw new ArchiverException(
+                        "Expected directory and found file at copy destination of " + in.getName() + " to " + outFile );
+                }
+            }
+            else if ( ! outFile.mkdirs() )
+            {
+                //Failure, unable to create specified directory for some unknown reason.
+                throw new ArchiverException( "Unable to create directory or parent directory of " + outFile );
+            }
+        }
+    }
+
+    protected void cleanUp()
+    {
+        super.cleanUp();
+        setIncludeEmptyDirs( false );
+        setIncludeEmptyDirs( true );
+    }
+
+    protected void close()
+        throws IOException
+    {
+    }
+
+    protected String getArchiveType()
+    {
+        return "directory";
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/dir/DirectoryArchiver.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/ear/EarArchiver.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/ear/EarArchiver.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/ear/EarArchiver.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/ear/EarArchiver.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,139 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.ear;
+
+/*
+ * 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 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;
+
+/**
+ * Creates a EAR archive. Based on WAR task
+ */
+public class EarArchiver
+    extends JarArchiver
+{
+
+    private File deploymentDescriptor;
+
+    private boolean descriptorAdded;
+
+    /**
+     * Create an Ear.
+     */
+    public EarArchiver()
+    {
+        super();
+        archiveType = "ear";
+    }
+
+    /**
+     * File to incorporate as application.xml.
+     */
+    public void setAppxml( File descr )
+        throws ArchiverException
+    {
+        deploymentDescriptor = descr;
+        if ( !deploymentDescriptor.exists() )
+        {
+            throw new ArchiverException( "Deployment descriptor: "
+                                         + deploymentDescriptor
+                                         + " does not exist." );
+        }
+
+        addFile( descr, "META-INF/application.xml" );
+    }
+
+    /**
+     * Adds archive.
+     */
+    public void addArchive( File fileName )
+        throws ArchiverException
+    {
+        addDirectory( fileName.getParentFile(), "/", new String[]{fileName.getName()}, null );
+    }
+
+    /**
+     * Adds archives.
+     */
+    public void addArchives( File directoryName, String[] includes, String[] excludes )
+        throws ArchiverException
+    {
+        addDirectory( directoryName, "/", includes, excludes );
+    }
+
+    protected void initZipOutputStream( ZipOutputStream zOut )
+        throws IOException, ArchiverException
+    {
+        // If no webxml file is specified, it's an error.
+        if ( deploymentDescriptor == null && !isInUpdateMode() )
+        {
+            throw new ArchiverException( "appxml attribute is required" );
+        }
+
+        super.initZipOutputStream( zOut );
+    }
+
+    /**
+     * Overridden from ZipArchiver class to deal with application.xml
+     */
+    protected void zipFile( ArchiveEntry entry, ZipOutputStream zOut, String vPath, int mode )
+        throws IOException, ArchiverException
+    {
+        // If the file being added is META-INF/application.xml, we
+        // warn if it's not the one specified in the "appxml"
+        // attribute - or if it's being added twice, meaning the same
+        // file is specified by the "appxml" attribute and in a
+        // <fileset> element.
+        if ( vPath.equalsIgnoreCase( "META-INF/application.xml" ) )
+        {
+            if ( deploymentDescriptor == null
+                 || !ResourceUtils.isCanonicalizedSame( entry.getResource(), deploymentDescriptor )
+                 || descriptorAdded )
+            {
+                getLogger().warn( "Warning: selected " + archiveType
+                                  + " files include a META-INF/application.xml which will"
+                                  + " be ignored (please use appxml attribute to "
+                                  + archiveType + " task)" );
+            }
+            else
+            {
+                super.zipFile( entry, zOut, vPath );
+                descriptorAdded = true;
+            }
+        }
+        else
+        {
+            super.zipFile( entry, zOut, vPath );
+        }
+    }
+
+    /**
+     * Make sure we don't think we already have a application.xml next
+     * time this task gets executed.
+     */
+    protected void cleanUp()
+    {
+        descriptorAdded = false;
+        super.cleanUp();
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/ear/EarArchiver.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/filters/JarSecurityFileFilter.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/filters/JarSecurityFileFilter.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/filters/JarSecurityFileFilter.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/filters/JarSecurityFileFilter.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,34 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.filters;
+
+import java.io.InputStream;
+
+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.util.SelectorUtils;
+
+
+/**
+ * @deprecated Use {@link JarSecurityFileSelector}
+ */
+public class JarSecurityFileFilter
+    implements ArchiveFileFilter
+{
+    
+    public static final String[] SECURITY_FILE_PATTERNS = JarSecurityFileSelector.SECURITY_FILE_PATTERNS;
+    
+    public boolean include( InputStream dataStream, String entryName )
+        throws ArchiveFilterException
+    {
+        for ( int i = 0; i < SECURITY_FILE_PATTERNS.length; i++ )
+        {
+            String pattern = SECURITY_FILE_PATTERNS[i];
+            
+            if ( SelectorUtils.match( pattern, entryName ) )
+            {
+                return false;
+            }
+        }
+        
+        return true;
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/filters/JarSecurityFileFilter.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/filters/JarSecurityFileSelector.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/filters/JarSecurityFileSelector.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/filters/JarSecurityFileSelector.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/filters/JarSecurityFileSelector.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,55 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.filters;
+
+/*
+ * 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.IOException;
+
+import org.apache.geronimo.system.plugin.plexus.io.fileselectors.FileInfo;
+import org.apache.geronimo.system.plugin.plexus.io.fileselectors.FileSelector;
+import org.apache.geronimo.system.plugin.plexus.util.SelectorUtils;
+
+/**
+ * @version $Id$
+ * @since 1.0-alpha-9
+ */
+public class JarSecurityFileSelector
+    implements FileSelector
+{
+    public static final String ROLE_HINT = "jar-security";
+
+    public static final String[] SECURITY_FILE_PATTERNS = {
+        "META-INF/*.RSA",
+        "META-INF/*.DSA",
+        "META-INF/*.SF",
+        "META-INF/*.rsa",
+        "META-INF/*.dsa",
+        "META-INF/*.sf" };
+
+    public boolean isSelected( FileInfo fileInfo )
+        throws IOException
+    {
+        String name = fileInfo.getName();
+        for ( int i = 0; i < SECURITY_FILE_PATTERNS.length; i++ )
+        {
+            String pattern = SECURITY_FILE_PATTERNS[i];
+
+            if ( SelectorUtils.match( pattern, name ) )
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/filters/JarSecurityFileSelector.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/gzip/GZipArchiver.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/gzip/GZipArchiver.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/gzip/GZipArchiver.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/gzip/GZipArchiver.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,67 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.gzip;
+
+/**
+ *
+ * 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.AbstractArchiver;
+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.ResourceIterator;
+
+import java.io.IOException;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class GZipArchiver
+    extends AbstractArchiver
+{
+    GZipCompressor compressor = new GZipCompressor();
+    
+    protected void execute()
+        throws ArchiverException, IOException
+    {
+    	if ( ! checkForced() )
+    	{
+    		return;
+    	}
+    	
+    	ResourceIterator iter = getResources();
+    	ArchiveEntry entry = iter.next();
+        if ( iter.hasNext() )
+        {
+            throw new ArchiverException( "There is more than one file in input." );
+        }
+        compressor.setSource( entry.getResource() );
+        compressor.setDestFile( getDestFile() );
+        compressor.compress();
+    }
+
+	public boolean isSupportingForced() {
+		return true;
+	}
+
+    protected void close()
+    {
+        compressor.close();
+    }
+
+    protected String getArchiveType()
+    {
+        return "gzip";
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/gzip/GZipArchiver.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/gzip/GZipCompressor.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/gzip/GZipCompressor.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/gzip/GZipCompressor.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/gzip/GZipCompressor.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,70 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.gzip;
+
+/**
+ *
+ * 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.util.Compressor;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.zip.GZIPOutputStream;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class GZipCompressor
+    extends Compressor
+{
+    private GZIPOutputStream zOut;
+
+    /**
+     * perform the GZip compression operation.
+     */
+    public void compress()
+        throws ArchiverException
+    {
+        try
+        {
+            zOut = new GZIPOutputStream( new FileOutputStream( getDestFile() ) );
+            compress( getSource(), zOut );
+        }
+        catch ( IOException ioe )
+        {
+            String msg = "Problem creating gzip " + ioe.getMessage();
+            throw new ArchiverException( msg, ioe );
+        }
+    }
+
+    public void close()
+    {
+        if ( zOut != null )
+        {
+            try
+            {
+                // close up
+                zOut.close();
+            }
+            catch ( IOException e )
+            {
+                // do nothing
+            }
+            
+            zOut = null;
+        }
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/gzip/GZipCompressor.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/gzip/GZipUnArchiver.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/gzip/GZipUnArchiver.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/gzip/GZipUnArchiver.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/gzip/GZipUnArchiver.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,118 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.gzip;
+
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+import org.apache.geronimo.system.plugin.plexus.archiver.AbstractUnArchiver;
+import org.apache.geronimo.system.plugin.plexus.archiver.ArchiverException;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.File;
+import java.util.zip.GZIPInputStream;
+
+/**
+ * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
+ * @version $Revision$ $Date$
+ */
+public class GZipUnArchiver
+    extends AbstractUnArchiver
+{
+    public GZipUnArchiver()
+    {
+    }
+
+    public GZipUnArchiver( File sourceFile )
+    {
+        super( sourceFile );
+    }
+
+    protected void execute()
+        throws ArchiverException
+    {
+        if ( getSourceFile().lastModified() > getDestFile().lastModified() )
+        {
+            getLogger().info( "Expanding " + getSourceFile().getAbsolutePath() + " to "
+                              + getDestFile().getAbsolutePath() );
+
+            FileOutputStream out = null;
+            GZIPInputStream zIn = null;
+            FileInputStream fis = null;
+            try
+            {
+                out = new FileOutputStream( getDestFile() );
+                fis = new FileInputStream( getSourceFile() );
+                zIn = new GZIPInputStream( fis );
+                byte[] buffer = new byte[8 * 1024];
+                int count = 0;
+                do
+                {
+                    out.write( buffer, 0, count );
+                    count = zIn.read( buffer, 0, buffer.length );
+                }
+                while ( count != -1 );
+            }
+            catch ( IOException ioe )
+            {
+                String msg = "Problem expanding gzip " + ioe.getMessage();
+                throw new ArchiverException( msg, ioe );
+            }
+            finally
+            {
+                if ( fis != null )
+                {
+                    try
+                    {
+                        fis.close();
+                    }
+                    catch ( IOException ioex )
+                    {
+                        //ignore
+                    }
+                }
+                if ( out != null )
+                {
+                    try
+                    {
+                        out.close();
+                    }
+                    catch ( IOException ioex )
+                    {
+                        //ignore
+                    }
+                }
+                if ( zIn != null )
+                {
+                    try
+                    {
+                        zIn.close();
+                    }
+                    catch ( IOException ioex )
+                    {
+                        //ignore
+                    }
+                }
+            }
+        }
+    }
+
+    protected void execute( String path, File outputDirectory )
+    {
+        throw new UnsupportedOperationException( "Targeted extraction not supported in GZIP format." );
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/gzip/GZipUnArchiver.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/gzip/PlexusIoGzipResourceCollection.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/gzip/PlexusIoGzipResourceCollection.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/gzip/PlexusIoGzipResourceCollection.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/gzip/PlexusIoGzipResourceCollection.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,40 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.gzip;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.GZIPInputStream;
+
+import org.apache.geronimo.system.plugin.plexus.io.resources.PlexusIoCompressedFileResourceCollection;
+import org.apache.geronimo.system.plugin.plexus.util.IOUtil;
+
+
+/**
+ * Abstract base class for compressed files, aka singleton
+ * resource collections.
+ */
+public class PlexusIoGzipResourceCollection
+    extends PlexusIoCompressedFileResourceCollection
+{
+    protected String getDefaultExtension()
+    {
+        return ".gz";
+    }
+
+    protected InputStream getInputStream( File file )
+        throws IOException
+    {
+        InputStream fis = new FileInputStream( file );
+        try
+        {
+            InputStream result = new GZIPInputStream( fis );
+            fis = null;
+            return result;
+        }
+        finally
+        {
+            IOUtil.close( fis );
+        }
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/gzip/PlexusIoGzipResourceCollection.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/jar/JarArchiver.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/jar/JarArchiver.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/jar/JarArchiver.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/archiver/jar/JarArchiver.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,973 @@
+package org.apache.geronimo.system.plugin.plexus.archiver.jar;
+
+/**
+ *
+ * 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.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.TreeMap;
+import java.util.Vector;
+
+import org.apache.geronimo.system.plugin.plexus.archiver.ArchiverException;
+import org.apache.geronimo.system.plugin.plexus.archiver.util.EnumeratedAttribute;
+import org.apache.geronimo.system.plugin.plexus.archiver.zip.ZipArchiver;
+import org.apache.geronimo.system.plugin.plexus.archiver.zip.ZipEntry;
+import org.apache.geronimo.system.plugin.plexus.archiver.zip.ZipFile;
+import org.apache.geronimo.system.plugin.plexus.archiver.zip.ZipOutputStream;
+
+/**
+ * Base class for tasks that build archives in JAR file format.
+ *
+ * @version $Revision$ $Date$
+ */
+public class JarArchiver
+    extends ZipArchiver
+{
+    /**
+     * the name of the meta-inf dir
+     */
+    private static final String META_INF_NAME = "META-INF";
+
+    /**
+     * The index file name.
+     */
+    private static final String INDEX_NAME = "META-INF/INDEX.LIST";
+
+    /**
+     * The manifest file name.
+     */
+    private static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";
+
+    /**
+     * merged manifests added through addConfiguredManifest
+     */
+    private Manifest configuredManifest;
+
+    /**
+     * shadow of the above if upToDate check alters the value
+     */
+    private Manifest savedConfiguredManifest;
+
+    /**
+     * merged manifests added through filesets
+     */
+    private Manifest filesetManifest;
+
+    /**
+     * Manifest of original archive, will be set to null if not in
+     * update mode.
+     */
+    private Manifest originalManifest;
+
+    /**
+     * whether to merge fileset manifests;
+     * value is true if filesetmanifest is 'merge' or 'mergewithoutmain'
+     */
+    private FilesetManifestConfig filesetManifestConfig;
+
+    /**
+     * whether to merge the main section of fileset manifests;
+     * value is true if filesetmanifest is 'merge'
+     */
+    private boolean mergeManifestsMain = true;
+
+    /**
+     * the manifest specified by the 'manifest' attribute *
+     */
+    private Manifest manifest;
+
+    /**
+     * The encoding to use when reading in a manifest file
+     */
+    private String manifestEncoding;
+
+    /**
+     * The file found from the 'manifest' attribute.  This can be
+     * either the location of a manifest, or the name of a jar added
+     * through a fileset.  If its the name of an added jar, the
+     * manifest is looked for in META-INF/MANIFEST.MF
+     */
+    private File manifestFile;
+
+    /**
+     * jar index is JDK 1.3+ only
+     */
+    private boolean index = false;
+
+    /**
+     * whether to really create the archive in createEmptyZip, will
+     * get set in getResourcesToAdd.
+     */
+    private boolean createEmpty = false;
+
+    /**
+     * Stores all files that are in the root of the archive (i.e. that
+     * have a name that doesn't contain a slash) so they can get
+     * listed in the index.
+     * <p/>
+     * Will not be filled unless the user has asked for an index.
+     */
+    private Vector rootEntries;
+
+    /**
+     * Path containing jars that shall be indexed in addition to this archive.
+     */
+    private ArrayList indexJars;
+
+    /**
+     * constructor
+     */
+    public JarArchiver()
+    {
+        super();
+        archiveType = "jar";
+        setEncoding( "UTF8" );
+        rootEntries = new Vector();
+    }
+
+    /**
+     * Set whether or not to create an index list for classes.
+     * This may speed up classloading in some cases.
+     */
+    public void setIndex( boolean flag )
+    {
+        index = flag;
+    }
+
+    /**
+     * Set whether or not to create an index list for classes.
+     * This may speed up classloading in some cases.
+     */
+    public void setManifestEncoding( String manifestEncoding )
+    {
+        this.manifestEncoding = manifestEncoding;
+    }
+
+    /**
+     * Allows the manifest for the archive file to be provided inline
+     * in the build file rather than in an external file.
+     *
+     * @param newManifest
+     * @throws ManifestException
+     */
+    public void addConfiguredManifest( Manifest newManifest )
+        throws ManifestException
+    {
+        if ( configuredManifest == null )
+        {
+            configuredManifest = newManifest;
+        }
+        else
+        {
+            configuredManifest.merge( newManifest );
+        }
+        savedConfiguredManifest = configuredManifest;
+    }
+
+    /**
+     * The manifest file to use. This can be either the location of a manifest,
+     * or the name of a jar added through a fileset. If its the name of an added
+     * jar, the task expects the manifest to be in the jar at META-INF/MANIFEST.MF.
+     *
+     * @param manifestFile the manifest file to use.
+     */
+    public void setManifest( File manifestFile )
+        throws ArchiverException
+    {
+        if ( !manifestFile.exists() )
+        {
+            throw new ArchiverException( "Manifest file: " + manifestFile
+                                         + " does not exist." );
+        }
+
+        this.manifestFile = manifestFile;
+    }
+
+    private Manifest getManifest( File manifestFile )
+        throws ArchiverException
+    {
+        Manifest newManifest = null;
+        FileInputStream fis;
+        InputStreamReader isr = null;
+        try
+        {
+            fis = new FileInputStream( manifestFile );
+            if ( manifestEncoding == null )
+            {
+                isr = new InputStreamReader( fis );
+            }
+            else
+            {
+                isr = new InputStreamReader( fis, manifestEncoding );
+            }
+            newManifest = getManifest( isr );
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            throw new ArchiverException( "Unsupported encoding while reading manifest: "
+                                         + e.getMessage(), e );
+        }
+        catch ( IOException e )
+        {
+            throw new ArchiverException( "Unable to read manifest file: "
+                                         + manifestFile
+                                         + " (" + e.getMessage() + ")", e );
+        }
+        finally
+        {
+            if ( isr != null )
+            {
+                try
+                {
+                    isr.close();
+                }
+                catch ( IOException e )
+                {
+                    // do nothing
+                }
+            }
+        }
+        return newManifest;
+    }
+
+    private Manifest getManifest( Reader r )
+        throws ArchiverException
+    {
+        Manifest newManifest;
+        try
+        {
+            newManifest = new Manifest( r );
+        }
+        catch ( ManifestException e )
+        {
+            getLogger().error( "Manifest is invalid: " + e.getMessage() );
+            throw new ArchiverException( "Invalid Manifest: " + manifestFile,
+                                         e );
+        }
+        catch ( IOException e )
+        {
+            throw new ArchiverException( "Unable to read manifest file"
+                                         + " (" + e.getMessage() + ")", e );
+        }
+        return newManifest;
+    }
+
+    /**
+     * Behavior when a Manifest is found in a zipfileset or zipgroupfileset file.
+     * Valid values are "skip", "merge", and "mergewithoutmain".
+     * "merge" will merge all of manifests together, and merge this into any
+     * other specified manifests.
+     * "mergewithoutmain" merges everything but the Main section of the manifests.
+     * Default value is "skip".
+     * <p/>
+     * Note: if this attribute's value is not "skip", the created jar will not
+     * be readable by using java.util.jar.JarInputStream
+     *
+     * @param config setting for found manifest behavior.
+     */
+    public void setFilesetmanifest( FilesetManifestConfig config )
+    {
+        filesetManifestConfig = config;
+        mergeManifestsMain = "merge".equals( config.getValue() );
+
+        if ( ( filesetManifestConfig != null )
+             && !filesetManifestConfig.getValue().equals( "skip" ) )
+        {
+
+            doubleFilePass = true;
+        }
+    }
+
+    /**
+     * Adds a zipfileset to include in the META-INF directory.
+     *
+     * @param fs zipfileset to add
+     */
+/*    public void addMetainf(ZipFileSet fs) {
+        // We just set the prefix for this fileset, and pass it up.
+        fs.setPrefix("META-INF/");
+        super.addFileset(fs);
+    }
+*/
+
+    /**
+     *
+     */
+    public void addConfiguredIndexJars( File indexJar )
+    {
+        if ( indexJars == null )
+        {
+            indexJars = new ArrayList();
+        }
+        indexJars.add( indexJar.getAbsolutePath() );
+    }
+
+    protected void initZipOutputStream( ZipOutputStream zOut )
+        throws IOException, ArchiverException
+    {
+
+        if ( !skipWriting )
+        {
+            Manifest jarManifest = createManifest();
+            writeManifest( zOut, jarManifest );
+        }
+    }
+
+    protected boolean hasVirtualFiles()
+    {
+        getLogger().debug( "\n\n\nChecking for jar manifest virtual files...\n\n\n" );
+        System.out.flush();
+
+        return ( configuredManifest != null ) || ( manifest != null ) || ( manifestFile != null ) || super.hasVirtualFiles();
+    }
+
+    private Manifest createManifest()
+        throws ArchiverException
+    {
+        try
+        {
+            Manifest finalManifest = Manifest.getDefaultManifest();
+
+            if ( manifest == null )
+            {
+                if ( manifestFile != null )
+                {
+                    // if we haven't got the manifest yet, attempt to
+                    // get it now and have manifest be the final merge
+                    manifest = getManifest( manifestFile );
+                }
+            }
+
+            /*
+             * Precedence: manifestFile wins over inline manifest,
+             * over manifests read from the filesets over the original
+             * manifest.
+             *
+             * merge with null argument is a no-op
+             */
+
+            if ( isInUpdateMode() )
+            {
+                finalManifest.merge( originalManifest );
+            }
+            finalManifest.merge( filesetManifest );
+            finalManifest.merge( configuredManifest );
+            finalManifest.merge( manifest, !mergeManifestsMain );
+
+            return finalManifest;
+
+        }
+        catch ( ManifestException e )
+        {
+            getLogger().error( "Manifest is invalid: " + e.getMessage() );
+            throw new ArchiverException( "Invalid Manifest", e );
+        }
+    }
+
+    private void writeManifest( ZipOutputStream zOut, Manifest manifest )
+        throws IOException, ArchiverException
+    {
+        for ( Enumeration e = manifest.getWarnings();
+              e.hasMoreElements(); )
+        {
+            getLogger().warn( "Manifest warning: " + e.nextElement() );
+        }
+
+        zipDir( null, zOut, "META-INF/", DEFAULT_DIR_MODE );
+        // time to write the manifest
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        OutputStreamWriter osw = new OutputStreamWriter( baos, "UTF-8" );
+        PrintWriter writer = new PrintWriter( osw );
+        manifest.write( writer );
+        writer.flush();
+
+        ByteArrayInputStream bais =
+            new ByteArrayInputStream( baos.toByteArray() );
+        super.zipFile( bais, zOut, MANIFEST_NAME,
+                       System.currentTimeMillis(), null,
+                       DEFAULT_FILE_MODE );
+        super.initZipOutputStream( zOut );
+    }
+
+    protected void finalizeZipOutputStream( ZipOutputStream zOut )
+        throws IOException, ArchiverException
+    {
+
+        if ( index )
+        {
+            createIndexList( zOut );
+        }
+    }
+
+    /**
+     * Create the index list to speed up classloading.
+     * This is a JDK 1.3+ specific feature and is enabled by default. See
+     * <a href="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#JAR%20Index">
+     * the JAR index specification</a> for more details.
+     *
+     * @param zOut the zip stream representing the jar being built.
+     * @throws IOException thrown if there is an error while creating the
+     *                     index and adding it to the zip stream.
+     */
+    private void createIndexList( ZipOutputStream zOut )
+        throws IOException, ArchiverException
+    {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        // encoding must be UTF8 as specified in the specs.
+        PrintWriter writer = new PrintWriter( new OutputStreamWriter( baos,
+                                                                      "UTF8" ) );
+
+        // version-info blankline
+        writer.println( "JarIndex-Version: 1.0" );
+        writer.println();
+
+        // header newline
+        writer.println( getDestFile().getName() );
+
+        // filter out META-INF if it doesn't contain anything other than the index and manifest.
+        // this is what sun.misc.JarIndex does, guess we ought to be consistent.
+        HashSet filteredDirs = new HashSet(addedDirs.keySet());
+        // our added dirs always have a trailing slash
+        if(filteredDirs.contains(META_INF_NAME+"/")) {
+            boolean add = false;
+            Iterator i = entries.keySet().iterator();
+            while(i.hasNext()) {
+                String entry = (String)i.next();
+                if(entry.startsWith(META_INF_NAME+"/") &&
+                        !entry.equals(INDEX_NAME) && !entry.equals(MANIFEST_NAME)) {
+                    add = true;
+                    break;
+                }
+            }
+            if(!add)
+            {
+                filteredDirs.remove(META_INF_NAME+"/");
+            }
+        }
+        writeIndexLikeList( new ArrayList( filteredDirs ),
+                            rootEntries, writer );
+        writer.println();
+
+        if ( indexJars != null )
+        {
+            Manifest mf = createManifest();
+            Manifest.Attribute classpath =
+                mf.getMainSection().getAttribute( Manifest.ATTRIBUTE_CLASSPATH );
+            String[] cpEntries = null;
+            if ( classpath != null )
+            {
+                StringTokenizer tok = new StringTokenizer( classpath.getValue(),
+                                                           " " );
+                cpEntries = new String[tok.countTokens()];
+                int c = 0;
+                while ( tok.hasMoreTokens() )
+                {
+                    cpEntries[ c++ ] = tok.nextToken();
+                }
+            }
+
+            for ( Iterator i = indexJars.iterator(); i.hasNext(); )
+            {
+                String indexJar = (String)i.next();
+                String name = findJarName( indexJar, cpEntries );
+                if ( name != null )
+                {
+                    ArrayList dirs = new ArrayList();
+                    ArrayList files = new ArrayList();
+                    grabFilesAndDirs( indexJar, dirs, files );
+                    if ( dirs.size() + files.size() > 0 )
+                    {
+                        writer.println( name );
+                        writeIndexLikeList( dirs, files, writer );
+                        writer.println();
+                    }
+                }
+            }
+        }
+
+        writer.flush();
+        ByteArrayInputStream bais =
+            new ByteArrayInputStream( baos.toByteArray() );
+        super.zipFile( bais, zOut, INDEX_NAME, System.currentTimeMillis(), null,
+                       DEFAULT_FILE_MODE );
+    }
+
+    /**
+     * Overridden from Zip class to deal with manifests and index lists.
+     */
+    protected void zipFile( InputStream is, ZipOutputStream zOut, String vPath,
+                            long lastModified, File fromArchive, int mode )
+        throws IOException, ArchiverException
+    {
+        if ( MANIFEST_NAME.equalsIgnoreCase( vPath ) )
+        {
+            if ( !doubleFilePass || skipWriting )
+            {
+                filesetManifest( fromArchive, is );
+            }
+        }
+        else if ( INDEX_NAME.equalsIgnoreCase( vPath ) && index )
+        {
+            getLogger().warn( "Warning: selected " + archiveType
+                              + " files include a META-INF/INDEX.LIST which will"
+                              + " be replaced by a newly generated one." );
+        }
+        else
+        {
+            if ( index && ( vPath.indexOf( "/" ) == -1 ) )
+            {
+                rootEntries.addElement( vPath );
+            }
+            super.zipFile( is, zOut, vPath, lastModified, fromArchive, mode );
+        }
+    }
+
+    private void filesetManifest( File file, InputStream is )
+        throws ArchiverException
+    {
+        if ( ( manifestFile != null ) && manifestFile.equals( file ) )
+        {
+            // If this is the same name specified in 'manifest', this
+            // is the manifest to use
+            getLogger().debug( "Found manifest " + file );
+            try
+            {
+                if ( is != null )
+                {
+                    InputStreamReader isr;
+                    if ( manifestEncoding == null )
+                    {
+                        isr = new InputStreamReader( is );
+                    }
+                    else
+                    {
+                        isr = new InputStreamReader( is, manifestEncoding );
+                    }
+                    manifest = getManifest( isr );
+                }
+                else
+                {
+                    manifest = getManifest( file );
+                }
+            }
+            catch ( UnsupportedEncodingException e )
+            {
+                throw new ArchiverException( "Unsupported encoding while reading "
+                                             + "manifest: " + e.getMessage(), e );
+            }
+        }
+        else if ( ( filesetManifestConfig != null )
+                  && !filesetManifestConfig.getValue().equals( "skip" ) )
+        {
+            // we add this to our group of fileset manifests
+            getLogger().debug( "Found manifest to merge in file " + file );
+
+            try
+            {
+                Manifest newManifest;
+                if ( is != null )
+                {
+                    InputStreamReader isr;
+                    if ( manifestEncoding == null )
+                    {
+                        isr = new InputStreamReader( is );
+                    }
+                    else
+                    {
+                        isr = new InputStreamReader( is, manifestEncoding );
+                    }
+                    newManifest = getManifest( isr );
+                }
+                else
+                {
+                    newManifest = getManifest( file );
+                }
+
+                if ( filesetManifest == null )
+                {
+                    filesetManifest = newManifest;
+                }
+                else
+                {
+                    filesetManifest.merge( newManifest );
+                }
+            }
+            catch ( UnsupportedEncodingException e )
+            {
+                throw new ArchiverException( "Unsupported encoding while reading "
+                                             + "manifest: " + e.getMessage(), e );
+            }
+            catch ( ManifestException e )
+            {
+                getLogger().error( "Manifest in file " + file + " is invalid: "
+                                   + e.getMessage() );
+                throw new ArchiverException( "Invalid Manifest", e );
+            }
+        }
+        else
+        {
+            // assuming 'skip' otherwise
+            // don't warn if skip has been requested explicitly, warn if user
+            // didn't set the attribute
+
+            // Hide warning also as it makes no sense since
+            // the filesetmanifest attribute itself has been
+            // hidden
+
+            //int logLevel = filesetManifestConfig == null ?
+            //    Project.MSG_WARN : Project.MSG_VERBOSE;
+            //log("File " + file
+            //    + " includes a META-INF/MANIFEST.MF which will be ignored. "
+            //    + "To include this file, set filesetManifest to a value other "
+            //    + "than 'skip'.", logLevel);
+        }
+    }
+
+    /**
+     * Collect the resources that are newer than the corresponding
+     * entries (or missing) in the original archive.
+     * <p/>
+     * <p>If we are going to recreate the archive instead of updating
+     * it, all resources should be considered as new, if a single one
+     * is.  Because of this, subclasses overriding this method must
+     * call <code>super.getResourcesToAdd</code> and indicate with the
+     * third arg if they already know that the archive is
+     * out-of-date.</p>
+     *
+     * @param filesets    The filesets to grab resources from
+     * @param zipFile     intended archive file (may or may not exist)
+     * @param needsUpdate whether we already know that the archive is
+     *                    out-of-date.  Subclasses overriding this method are supposed to
+     *                    set this value correctly in their call to
+     *                    super.getResourcesToAdd.
+     * @return an map of resources to add for each fileset passed in as well
+     *         as a flag that indicates whether the archive is uptodate.
+     * @throws ArchiverException if it likes
+     */
+/*    protected Map getResourcesToAdd(FileSet[] filesets,
+                                             File zipFile,
+                                             boolean needsUpdate)
+        throws ArchiverException {
+
+        // need to handle manifest as a special check
+        if (zipFile.exists()) {
+            // if it doesn't exist, it will get created anyway, don't
+            // bother with any up-to-date checks.
+
+            try {
+                originalManifest = getManifestFromJar(zipFile);
+                if (originalManifest == null) {
+                    getLogger().debug("Updating jar since the current jar has no manifest");
+                    needsUpdate = true;
+                } else {
+                    Manifest mf = createManifest();
+                    if (!mf.equals(originalManifest)) {
+                        getLogger().debug("Updating jar since jar manifest has changed");
+                        needsUpdate = true;
+                    }
+                }
+            } catch (Throwable t) {
+                getLogger().warn("error while reading original manifest: " + t.getMessage());
+                needsUpdate = true;
+            }
+
+        } else {
+            // no existing archive
+            needsUpdate = true;
+        }
+
+        createEmpty = needsUpdate;
+        return super.getResourcesToAdd(filesets, zipFile, needsUpdate);
+    }
+*/
+
+    /**
+     */
+    protected boolean createEmptyZip( File zipFile )
+        throws ArchiverException
+    {
+        if ( !createEmpty )
+        {
+            return true;
+        }
+
+        ZipOutputStream zOut = null;
+        try
+        {
+            getLogger().debug( "Building MANIFEST-only jar: "
+                               + getDestFile().getAbsolutePath() );
+            zOut = new ZipOutputStream( new FileOutputStream( getDestFile() ) );
+
+            zOut.setEncoding( getEncoding() );
+            if ( isCompress() )
+            {
+                zOut.setMethod( ZipOutputStream.DEFLATED );
+            }
+            else
+            {
+                zOut.setMethod( ZipOutputStream.STORED );
+            }
+            initZipOutputStream( zOut );
+            finalizeZipOutputStream( zOut );
+        }
+        catch ( IOException ioe )
+        {
+            throw new ArchiverException( "Could not create almost empty JAR archive"
+                                         + " (" + ioe.getMessage() + ")", ioe );
+        }
+        finally
+        {
+            // Close the output stream.
+            try
+            {
+                if ( zOut != null )
+                {
+                    zOut.close();
+                }
+            }
+            catch ( IOException ex )
+            {
+            }
+            createEmpty = false;
+        }
+        return true;
+    }
+
+    /**
+     * Make sure we don't think we already have a MANIFEST next time this task
+     * gets executed.
+     *
+     * @see ZipArchiver#cleanUp
+     */
+    protected void cleanUp()
+    {
+        super.cleanUp();
+
+        // we want to save this info if we are going to make another pass
+        if ( !doubleFilePass || !skipWriting )
+        {
+            manifest = null;
+            configuredManifest = savedConfiguredManifest;
+            filesetManifest = null;
+            originalManifest = null;
+        }
+        rootEntries.removeAllElements();
+    }
+
+    /**
+     * reset to default values.
+     *
+     * @see ZipArchiver#reset
+     */
+    public void reset()
+    {
+        super.reset();
+        configuredManifest = null;
+        filesetManifestConfig = null;
+        mergeManifestsMain = false;
+        manifestFile = null;
+        index = false;
+    }
+
+    public static class FilesetManifestConfig
+        extends EnumeratedAttribute
+    {
+        public String[] getValues()
+        {
+            return new String[]{"skip", "merge", "mergewithoutmain"};
+        }
+    }
+
+    /**
+     * Writes the directory entries from the first and the filenames
+     * from the second list to the given writer, one entry per line.
+     */
+    protected final void writeIndexLikeList( List dirs, List files,
+                                             PrintWriter writer )
+    {
+        // JarIndex is sorting the directories by ascending order.
+        // it has no value but cosmetic since it will be read into a
+        // hashtable by the classloader, but we'll do so anyway.
+        Collections.sort( dirs );
+        Collections.sort( files );
+        Iterator iter = dirs.iterator();
+        while ( iter.hasNext() )
+        {
+            String dir = (String) iter.next();
+
+            // try to be smart, not to be fooled by a weird directory name
+            dir = dir.replace( '\\', '/' );
+            if ( dir.startsWith( "./" ) )
+            {
+                dir = dir.substring( 2 );
+            }
+            while ( dir.startsWith( "/" ) )
+            {
+                dir = dir.substring( 1 );
+            }
+            int pos = dir.lastIndexOf( '/' );
+            if ( pos != -1 )
+            {
+                dir = dir.substring( 0, pos );
+            }
+
+            // name newline
+            writer.println( dir );
+        }
+
+        iter = files.iterator();
+        while ( iter.hasNext() )
+        {
+            writer.println( iter.next() );
+        }
+    }
+
+    /**
+     * try to guess the name of the given file.
+     * <p/>
+     * <p>If this jar has a classpath attribute in its manifest, we
+     * can assume that it will only require an index of jars listed
+     * there.  try to find which classpath entry is most likely the
+     * one the given file name points to.</p>
+     * <p/>
+     * <p>In the absence of a classpath attribute, assume the other
+     * files will be placed inside the same directory as this jar and
+     * use their basename.</p>
+     * <p/>
+     * <p>if there is a classpath and the given file doesn't match any
+     * of its entries, return null.</p>
+     */
+    protected static final String findJarName( String fileName,
+                                               String[] classpath )
+    {
+        if ( classpath == null )
+        {
+            return ( new File( fileName ) ).getName();
+        }
+        fileName = fileName.replace( File.separatorChar, '/' );
+        TreeMap matches = new TreeMap( new Comparator()
+        {
+            // longest match comes first
+            public int compare( Object o1, Object o2 )
+            {
+                if ( ( o1 instanceof String ) && ( o2 instanceof String ) )
+                {
+                    return ( (String) o2 ).length()
+                           - ( (String) o1 ).length();
+                }
+                return 0;
+            }
+        } );
+
+        for ( int i = 0; i < classpath.length; i++ )
+        {
+            if ( fileName.endsWith( classpath[ i ] ) )
+            {
+                matches.put( classpath[ i ], classpath[ i ] );
+            }
+            else
+            {
+                int slash = classpath[ i ].indexOf( "/" );
+                String candidate = classpath[ i ];
+                while ( slash > -1 )
+                {
+                    candidate = candidate.substring( slash + 1 );
+                    if ( fileName.endsWith( candidate ) )
+                    {
+                        matches.put( candidate, classpath[ i ] );
+                        break;
+                    }
+                    slash = candidate.indexOf( "/" );
+                }
+            }
+        }
+
+        return matches.size() == 0
+               ? null : (String) matches.get( matches.firstKey() );
+    }
+
+    /**
+     * Grab lists of all root-level files and all directories
+     * contained in the given archive.
+     */
+    protected static final void grabFilesAndDirs( String file, List dirs,
+                                                  List files )
+        throws IOException
+    {
+        ZipFile zf = null;
+        try
+        {
+            zf = new ZipFile( file, "utf-8" );
+            Enumeration entries = zf.getEntries();
+            HashSet dirSet = new HashSet();
+            while ( entries.hasMoreElements() )
+            {
+                ZipEntry ze =
+                    (ZipEntry) entries.nextElement();
+                String name = ze.getName();
+                // avoid index for manifest-only jars.
+                if (!name.equals(META_INF_NAME) && !name.equals(META_INF_NAME+"/") &&
+                        !name.equals(INDEX_NAME) && !name.equals(MANIFEST_NAME))
+                {
+                    if ( ze.isDirectory() )
+                    {
+                        dirSet.add( name );
+                    }
+                    else if ( name.indexOf( "/" ) == -1 )
+                    {
+                        files.add( name );
+                    }
+                    else
+                    {
+                        // a file, not in the root
+                        // since the jar may be one without directory
+                        // entries, add the parent dir of this file as
+                        // well.
+                        dirSet.add( name.substring( 0,
+                                                    name.lastIndexOf( "/" ) + 1 ) );
+                    }
+                }
+            }
+            dirs.addAll( dirSet );
+        }
+        finally
+        {
+            if ( zf != null )
+            {
+                zf.close();
+            }
+        }
+    }
+}

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

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

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



Mime
View raw message