You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ad...@apache.org on 2002/08/22 03:32:49 UTC

cvs commit: jakarta-commons-sandbox/vfs/src/test-data normal.mf test.mf

adammurdoch    2002/08/21 18:32:49

  Modified:    vfs      maven.xml
               vfs/src/java/org/apache/commons/vfs/provider
                        AbstractFileObject.java
               vfs/src/java/org/apache/commons/vfs/provider/ftp
                        FtpFileObject.java
               vfs/src/java/org/apache/commons/vfs/provider/zip
                        ParsedZipUri.java ZipFileObject.java
                        ZipFileSystem.java ZipFileSystemProvider.java
               vfs/src/test/org/apache/commons/vfs/test
                        AbstractFileSystemTestCase.java
  Added:       vfs/src/java/org/apache/commons/vfs/provider/jar
                        JarFileObject.java JarFileSystem.java
                        JarFileSystemProvider.java
                        JarURLConnectionImpl.java Resources.properties
               vfs/src/test/org/apache/commons/vfs/provider/jar/test
                        JarFileSystemTestCase.java
                        NestedJarFileSystemTestCase.java
               vfs/src/test-data normal.mf test.mf
  Log:
  Added a Jar file provider.  Patch submitted by Brian Olsen.
  
  Revision  Changes    Path
  1.5       +18 -4     jakarta-commons-sandbox/vfs/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/maven.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- maven.xml	21 Aug 2002 13:10:56 -0000	1.4
  +++ maven.xml	22 Aug 2002 01:32:48 -0000	1.5
  @@ -2,12 +2,11 @@
   
     <!-- we can customize the Maven build here -->
     <goal name="test:test-data"
  -        description="Generate and copy the test data"
  -        prereqs="test:compile">
  +        description="Generate and copy the test data">
   
       <copy todir="${test.data}">
         <fileset dir="${test.data.src}">
  -        <exclude name="*.policy"/>
  +        <include name="basedir/**"/>
         </fileset>
       </copy>
       
  @@ -37,11 +36,26 @@
           <include name="test.zip"/>
         </zipfileset>
       </zip>
  +    
  +    <jar
  +      jarfile="${test.data}/test.jar"
  +      basedir="${test.data}"
  +      includes="basedir/**"
  +      manifest="${test.data.src}/test.mf"/>
  +
  +    <jar
  +      jarfile="${test.data}/normal.jar"
  +      basedir="${test.data}/basedir"
  +      manifest="${test.data.src}/normal.mf"/>
  +    <jar
  +      jarfile="${test.data}/nested.jar"
  +      basedir="${test.data}"
  +      includes="test.jar,normal.jar"/>
     </goal>
     	
     <goal name="test:test"
           description="Test the application"
  -        prereqs="test:test-data">
  +        prereqs="test:test-data,test:compile">
   
       <junit printSummary="yes" 
              failureProperty="maven.test.failure"
  
  
  
  1.6       +6 -1      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java
  
  Index: AbstractFileObject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractFileObject.java	21 Aug 2002 13:10:57 -0000	1.5
  +++ AbstractFileObject.java	22 Aug 2002 01:32:48 -0000	1.6
  @@ -12,10 +12,10 @@
   import java.io.OutputStream;
   import java.net.MalformedURLException;
   import java.net.URL;
  -import java.security.cert.Certificate;
   import java.security.AccessController;
   import java.security.PrivilegedActionException;
   import java.security.PrivilegedExceptionAction;
  +import java.security.cert.Certificate;
   import java.util.ArrayList;
   import java.util.List;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
  @@ -62,6 +62,11 @@
       {
           this.name = name;
           this.fs = fs;
  +    }
  +
  +    public FileSystem getFileSystem()
  +    {
  +        return fs;
       }
   
       /**
  
  
  
  1.5       +5 -5      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java
  
  Index: FtpFileObject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FtpFileObject.java	21 Aug 2002 14:28:08 -0000	1.4
  +++ FtpFileObject.java	22 Aug 2002 01:32:48 -0000	1.5
  @@ -147,14 +147,14 @@
               }
           }
   
  -        String[] children = new String[ children.length ];
  -        for ( int i = 0; i < this.children.length; i++ )
  +        String[] childNames = new String[ children.length ];
  +        for ( int i = 0; i < children.length; i++ )
           {
  -            FTPFile child = this.children[ i ];
  -            children[ i ] = child.getName();
  +            FTPFile child = children[ i ];
  +            childNames[ i ] = child.getName();
           }
   
  -        return children;
  +        return childNames;
       }
   
       /**
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/jar/JarFileObject.java
  
  Index: JarFileObject.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.commons.vfs.provider.jar;
  
  import java.io.IOException;
  import java.security.cert.Certificate;
  import java.util.jar.Attributes;
  import java.util.jar.Attributes.Name;
  import java.util.jar.JarEntry;
  import java.util.jar.JarFile;
  import java.util.jar.Manifest;
  import java.util.zip.ZipEntry;
  import java.util.zip.ZipFile;
  import org.apache.commons.vfs.FileName;
  import org.apache.commons.vfs.FileSystemException;
  import org.apache.commons.vfs.provider.zip.ZipFileObject;
  
  /**
   * A file in a Jar file system.
   *
   * @author <a href="mailto:brian@mmmanager.org">Brian Olsen</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/22 01:32:49 $
   */
  class JarFileObject extends ZipFileObject
  {
      private Attributes attributes;
  
      public JarFileObject( FileName name,
                            ZipEntry entry,
                            ZipFile zipFile,
                            JarFileSystem fs )
      {
          super( name, entry, zipFile, fs );
      }
  
      Manifest getManifest() throws IOException
      {
          if( file == null )
              return null;
              
          return ((JarFile) file).getManifest();
      }
  
      Attributes getAttributes() throws IOException
      {
          if( attributes == null )
          {
              if( entry == null )
              {
                  attributes = new Attributes( 1 );
              }
              else
              {
                  attributes = ( (JarEntry) entry).getAttributes();
                  if( attributes == null )
                  {
                      attributes = new Attributes( 1 );
                  }
              }
          }
  
          return attributes;
      }
  
      /**
       *
       */
      protected Object doGetAttribute( String attrName )
          throws FileSystemException
      {
          try
          {
              final JarFileSystem fs = (JarFileSystem) getFileSystem();
              final Attributes attr = getAttributes();
              final Name name = fs.lookupName( attrName );
              String value = attr.getValue( name );
              if ( value != null )
              {
                  return value;
              }
  
              return fs.getAttribute( name );
          }
          catch ( IOException ioe )
          {
              throw new FileSystemException( attrName, ioe );
          }
      }
      
      /**
       * Return the certificates of this JarEntry.
       */
      protected Certificate[] doGetCertificates()
      {
          if( entry == null )
              return null;
  
          return ((JarEntry) entry).getCertificates();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/jar/JarFileSystem.java
  
  Index: JarFileSystem.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.commons.vfs.provider.jar;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.jar.Attributes;
  import java.util.jar.Attributes.Name;
  import java.util.jar.JarFile;
  import java.util.jar.Manifest;
  import java.util.zip.ZipEntry;
  import java.util.zip.ZipFile;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.commons.vfs.FileName;
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystemException;
  import org.apache.commons.vfs.provider.DefaultFileName;
  import org.apache.commons.vfs.provider.zip.ZipFileObject;
  import org.apache.commons.vfs.provider.zip.ZipFileSystem;
  
  /**
   * A read-only file system for Jar files.
   *
   * @author <a href="mailto:brian@mmmanager.org">Brian Olsen</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/22 01:32:49 $
   */
  public class JarFileSystem
      extends ZipFileSystem
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( JarFileSystem.class );
  
      private Attributes attributes;
  
      public JarFileSystem( final DefaultFileName rootName,
                            final FileObject file ) throws FileSystemException
      {
          super( rootName, file );
      }
  
      protected ZipFile createZipFile( File file ) throws FileSystemException
      {
          try
          {
              return new JarFile( file );
          }
          catch( IOException ioe )
          {
              final String message = REZ.getString( "open-jar-file.error", file );
              throw new FileSystemException( message, ioe );
          }
      }
  
      protected ZipFileObject createZipFileObject( FileName name,
                                                   ZipEntry entry,
                                                   ZipFile file )
          throws FileSystemException
      {
          return new JarFileObject( name, entry, file, this );
      }
  
  
      Attributes getAttributes() throws IOException
      {
          if ( attributes == null )
          {
              final Manifest man = ( (JarFile) zipFile).getManifest();
              if ( man == null )
              {
                  attributes = new Attributes( 1 );
              }
              else
              {
                  attributes = man.getMainAttributes();
                  if ( attributes == null )
                  {
                      attributes = new Attributes( 1 );
                  }
              }
          }
  
          return attributes;
      }
  
      Object getAttribute( Name attrName )
          throws FileSystemException
      {
          try
          {
              final Attributes attr = getAttributes();
              final String value = attr.getValue( attrName );
              return value;
          }
          catch ( IOException ioe )
          {
              throw new FileSystemException( attrName.toString(), ioe );
          }
      }
  
      Name lookupName( String attrName )
      {
          if ( Name.CLASS_PATH.equals( attrName ) )
          {
              return Name.CLASS_PATH;
          }
          else if ( Name.CONTENT_TYPE.equals( attrName ) )
          {
              return Name.CONTENT_TYPE;
          }
          else if ( Name.EXTENSION_INSTALLATION.equals( attrName ) )
          {
              return Name.EXTENSION_INSTALLATION;
          }
          else if ( Name.EXTENSION_LIST.equals( attrName ) )
          {
              return Name.EXTENSION_LIST;
          }
          else if ( Name.EXTENSION_NAME.equals( attrName ) )
          {
              return Name.EXTENSION_NAME;
          }
          else if ( Name.IMPLEMENTATION_TITLE.equals( attrName ) )
          {
              return Name.IMPLEMENTATION_TITLE;
          }
          else if ( Name.IMPLEMENTATION_URL.equals( attrName ) )
          {
              return Name.IMPLEMENTATION_URL;
          }
          else if ( Name.IMPLEMENTATION_VENDOR.equals( attrName ) )
          {
              return Name.IMPLEMENTATION_VENDOR;
          }
          else if ( Name.IMPLEMENTATION_VENDOR_ID.equals( attrName ) )
          {
              return Name.IMPLEMENTATION_VENDOR_ID;
          }
          else if ( Name.IMPLEMENTATION_VERSION.equals( attrName ) )
          {
              return Name.IMPLEMENTATION_VENDOR;
          }
          else if ( Name.MAIN_CLASS.equals( attrName ) )
          {
              return Name.MAIN_CLASS;
          }
          else if ( Name.MANIFEST_VERSION.equals( attrName ) )
          {
              return Name.MANIFEST_VERSION;
          }
          else if ( Name.SEALED.equals( attrName ) )
          {
              return Name.SEALED;
          }
          else if ( Name.SIGNATURE_VERSION.equals( attrName ) )
          {
              return Name.SIGNATURE_VERSION;
          }
          else if ( Name.SPECIFICATION_TITLE.equals( attrName ) )
          {
              return Name.SPECIFICATION_TITLE;
          }
          else if ( Name.SPECIFICATION_VENDOR.equals( attrName ) )
          {
              return Name.SPECIFICATION_VENDOR;
          }
          else if ( Name.SPECIFICATION_VERSION.equals( attrName ) )
          {
              return Name.SPECIFICATION_VERSION;
          }
          else
          {
              return new Name( attrName );
          }
      }
      
      /**
       * Retrives the attribute with the specified name. The default
       * implementation simply throws an exception.
       */
      public Object getAttribute( String attrName ) throws FileSystemException
      {
          final Name name = lookupName( attrName );
          return getAttribute( name );
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/jar/JarFileSystemProvider.java
  
  Index: JarFileSystemProvider.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.commons.vfs.provider.jar;
  
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystemException;
  import org.apache.commons.vfs.provider.DefaultFileName;
  import org.apache.commons.vfs.provider.FileSystem;
  import org.apache.commons.vfs.provider.ParsedUri;
  import org.apache.commons.vfs.provider.zip.ParsedZipUri;
  import org.apache.commons.vfs.provider.zip.ZipFileSystemProvider;
  
  /**
   * A file system provider for Jar files.  Provides read-only file
   * systems, for local Jar files only.
   * This provides access to Jar specific features like Signing and
   * Manifest Attributes.
   *
   * @author <a href="mailto:brian@mmmanager.org">Brian Olsen</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/22 01:32:49 $
   */
  public class JarFileSystemProvider
      extends ZipFileSystemProvider
  {
      /**
       * Creates the filesystem.
       */
      protected FileSystem createFileSystem( final ParsedUri uri )
          throws FileSystemException
      {
          final ParsedZipUri jarUri = (ParsedZipUri)uri;
          final FileObject file = jarUri.getZipFile();
  
          // Create the file system
          DefaultFileName name = new DefaultFileName( getParser(), jarUri.getRootUri(), "/" );
          return new JarFileSystem( name, file );
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/jar/JarURLConnectionImpl.java
  
  Index: JarURLConnectionImpl.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.commons.vfs.provider.jar;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.net.JarURLConnection;
  import java.net.MalformedURLException;
  import java.net.ProtocolException;
  import java.net.URL;
  import java.security.cert.Certificate;
  import java.util.jar.Attributes;
  import java.util.jar.JarEntry;
  import java.util.jar.JarFile;
  import java.util.jar.Manifest;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.commons.vfs.FileContent;
  import org.apache.commons.vfs.FileSystemException;
  
  /**
   * A default URL connection that will work for most file systems.
   *
   * @author <a href="mailto:brian@mmmanager.org">Brian Olsen</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/22 01:32:49 $
   */
  public class JarURLConnectionImpl
      extends JarURLConnection
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( JarURLConnectionImpl.class );
          
      // This is because JarURLConnection SUCKS
      private static final String HACK_URL = "jar:http://somehost/somejar.jar!/";
  
      FileContent             content;
      protected URL           parentURL;
      protected JarFileObject file;
      protected String        entryName;
  
      public JarURLConnectionImpl( JarFileObject file, FileContent content )
          throws MalformedURLException, FileSystemException
      {
          //This is because JarURLConnection SUCKS!!
          super( new URL( HACK_URL ) );
  
          this.url = file.getURL();
          this.content = content;
          this.parentURL = file.getURL();
          this.entryName =
              file.getRoot().getName().getRelativeName( file.getName() );
          this.file = file;
      }
  
  
      public URL getJarFileURL()
      {
          return parentURL;
      }
  
  
      public String getEntryName()
      {
          return entryName;
      }
  
  
      public JarFile getJarFile() throws IOException
      {
          final String message = REZ.getString( "jar-file-no-access.error" );
          throw new UnsupportedOperationException( message );
      }
  
  
      public Manifest getManifest() throws IOException
      {
          return file.getManifest();
      }
  
  
      public JarEntry getJarEntry() throws IOException
      {
          final String message = REZ.getString( "jar-entry-no-access.error" );
          throw new UnsupportedOperationException( message );
      }
  
  
      public Attributes getAttributes() throws IOException
      {
          return file.getAttributes();
      }
      
  
      public Certificate[] getCertificates()
      {
          return file.doGetCertificates();
      }
      
  
      public void connect()
      {
          connected = true;
      }
  
      public InputStream getInputStream()
          throws IOException
      {
          try{
              return content.getInputStream();
          }
          catch ( FileSystemException fse )
          {
              throw new ProtocolException( fse.getMessage() );
          }
      }
  
      public OutputStream getOutputStream()
          throws IOException
      {
          try{
              return content.getOutputStream();
          }
          catch ( FileSystemException fse )
          {
              throw new ProtocolException( fse.getMessage() );
          }
      }
  
      public int getContentLength()
      {
          try{
              return (int) content.getSize();
          }
          catch ( FileSystemException fse ) {}
  
          return -1;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/jar/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  #JarFileSystem
  open-jar-file.error=Could not open Jar file "{0}".
  #JarURLConnectionImpl
  jar-file-no-access.error=JarURLConnections in VFS does not give access to the JarFile.
  jar-entry-no-access.error=JarURLConnections in VFS does not give access to the JarEntry.
  
  
  
  1.5       +1 -1      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ParsedZipUri.java
  
  Index: ParsedZipUri.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ParsedZipUri.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ParsedZipUri.java	21 Aug 2002 13:10:57 -0000	1.4
  +++ ParsedZipUri.java	22 Aug 2002 01:32:49 -0000	1.5
  @@ -16,7 +16,7 @@
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    * @version $Revision$ $Date$
    */
  -class ParsedZipUri
  +public class ParsedZipUri
       extends ParsedUri
   {
       private String zipFileName;
  
  
  
  1.3       +18 -17    jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileObject.java
  
  Index: ZipFileObject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileObject.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ZipFileObject.java	21 Aug 2002 07:00:13 -0000	1.2
  +++ ZipFileObject.java	22 Aug 2002 01:32:49 -0000	1.3
  @@ -22,14 +22,14 @@
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    * @version $Revision$ $Date$
    */
  -final class ZipFileObject
  +public class ZipFileObject
       extends AbstractFileObject
       implements FileObject
   {
  -    private final ZipEntry entry;
  -    private final ZipFile file;
  -    private final FileType type;
       private final HashSet children = new HashSet();
  +    protected final ZipFile file;
  +    protected ZipEntry entry;
  +    private FileType type;
   
       public ZipFileObject( FileName name,
                             ZipEntry entry,
  @@ -37,26 +37,27 @@
                             ZipFileSystem fs )
       {
           super( name, fs );
  -        type = FileType.FILE;
  -        this.entry = entry;
  +        setZipEntry( entry );
           file = zipFile;
  +        if ( file == null )
  +        {
  +            type = null;
  +        }
       }
   
  -    public ZipFileObject( final FileName name,
  -                          final boolean exists,
  -                          final ZipFileSystem fs )
  +    protected void setZipEntry( ZipEntry entry )
       {
  -        super( name, fs );
  -        entry = null;
  -        file = null;
  -        if ( exists )
  +        if ( entry == null || this.entry != null )
           {
  -            type = FileType.FOLDER;
  +            return;
           }
  +          
  +        if ( entry.isDirectory() )
  +            type = FileType.FOLDER;
           else
  -        {
  -            type = null;
  -        }
  +            type = FileType.FILE;
  +
  +        this.entry = entry;
       }
   
       /**
  
  
  
  1.7       +36 -27    jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileSystem.java
  
  Index: ZipFileSystem.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileSystem.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ZipFileSystem.java	21 Aug 2002 14:28:08 -0000	1.6
  +++ ZipFileSystem.java	22 Aug 2002 01:32:49 -0000	1.7
  @@ -14,10 +14,10 @@
   import java.util.zip.ZipFile;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  +import org.apache.commons.vfs.FileConstants;
   import org.apache.commons.vfs.FileName;
   import org.apache.commons.vfs.FileObject;
   import org.apache.commons.vfs.FileSystemException;
  -import org.apache.commons.vfs.FileConstants;
   import org.apache.commons.vfs.provider.AbstractFileSystem;
   import org.apache.commons.vfs.provider.DefaultFileName;
   import org.apache.commons.vfs.provider.FileSystem;
  @@ -28,7 +28,7 @@
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    * @version $Revision$ $Date$
    */
  -class ZipFileSystem
  +public class ZipFileSystem
       extends AbstractFileSystem
       implements FileSystem
   {
  @@ -36,7 +36,7 @@
           ResourceManager.getPackageResources( ZipFileSystem.class );
   
       private final File file;
  -    private final ZipFile zipFile;
  +    protected final ZipFile zipFile;
   
       public ZipFileSystem( final DefaultFileName rootName,
                             final FileObject parentLayer )
  @@ -57,15 +57,7 @@
               return;
           }
   
  -        try
  -        {
  -            zipFile = new ZipFile( this.file );
  -        }
  -        catch ( IOException ioe )
  -        {
  -            final String message = REZ.getString( "open-zip-file.error", this.file );
  -            throw new FileSystemException( message, ioe );
  -        }
  +        zipFile = createZipFile( this.file );
   
           // Build the index
           Enumeration entries = zipFile.entries();
  @@ -76,33 +68,29 @@
   
               // Create the file
               ZipFileObject fileObj;
  -            if ( entry.isDirectory() )
  +            if ( entry.isDirectory() &&
  +                 getFile( name ) != null )
               {
  -                if ( getFile( name ) != null )
  -                {
  -                    // Already created implicitly
  -                    continue;
  -                }
  -                fileObj = new ZipFileObject( name, true, this );
  -            }
  -            else
  -            {
  -                fileObj = new ZipFileObject( name, entry, zipFile, this );
  +                fileObj = (ZipFileObject) getFile( name );
  +                fileObj.setZipEntry( entry );
  +                continue;
               }
  +            
  +            fileObj = createZipFileObject( name, entry, zipFile );
               putFile( fileObj );
   
               // Make sure all ancestors exist
               // TODO - create these on demand
  -            ZipFileObject parent;
  +            ZipFileObject parent = null;
               for ( FileName parentName = name.getParent();
                     parentName != null;
                     fileObj = parent, parentName = parentName.getParent() )
               {
                   // Locate the parent
  -                parent = (ZipFileObject)getFile( parentName );
  +                parent = (ZipFileObject) getFile( parentName );
                   if ( parent == null )
                   {
  -                    parent = new ZipFileObject( parentName, true, this );
  +                    parent = createZipFileObject( parentName, null, null );
                       putFile( parent );
                   }
   
  @@ -112,6 +100,27 @@
           }
       }
   
  +    protected ZipFileObject createZipFileObject( FileName name, 
  +                                                 ZipEntry entry,
  +                                                 ZipFile file )
  +        throws FileSystemException
  +    {
  +        return new ZipFileObject( name, entry, file, this );
  +    }
  +
  +    protected ZipFile createZipFile( File file ) throws FileSystemException
  +    {
  +        try
  +        {
  +            return new ZipFile( file );
  +        }
  +        catch ( IOException ioe )
  +        {
  +            final String message = REZ.getString( "open-zip-file.error", file );
  +            throw new FileSystemException( message, ioe );
  +        }
  +    }
  +
       public void close()
       {
           // Release the zip file
  @@ -137,6 +146,6 @@
       protected FileObject createFile( FileName name ) throws FileSystemException
       {
           // This is only called for files which do not exist in the Zip file
  -        return new ZipFileObject( name, false, this );
  +        return new ZipFileObject( name, null, null, this );
       }
   }
  
  
  
  1.6       +9 -3      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileSystemProvider.java
  
  Index: ZipFileSystemProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileSystemProvider.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ZipFileSystemProvider.java	21 Aug 2002 14:28:08 -0000	1.5
  +++ ZipFileSystemProvider.java	22 Aug 2002 01:32:49 -0000	1.6
  @@ -7,11 +7,9 @@
    */
   package org.apache.commons.vfs.provider.zip;
   
  -import java.io.File;
   import java.security.AccessController;
   import java.security.PrivilegedActionException;
   import java.security.PrivilegedExceptionAction;
  -import org.apache.commons.vfs.FileConstants;
   import org.apache.commons.vfs.FileObject;
   import org.apache.commons.vfs.FileSystemException;
   import org.apache.commons.vfs.provider.AbstractFileSystemProvider;
  @@ -29,7 +27,7 @@
    *
    * @ant.type type="file-provider" name="zip"
    */
  -public final class ZipFileSystemProvider
  +public class ZipFileSystemProvider
       extends AbstractFileSystemProvider
       implements FileProvider
   {
  @@ -73,6 +71,14 @@
           uri.setRootUri( rootUri );
           uri.setPath( "/" );
           return uri;
  +    }
  +
  +    /**
  +     * Returns the URI parser.
  +     */
  +    protected ZipFileNameParser getParser()
  +    {
  +        return parser;
       }
   
       /**
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/jar/test/JarFileSystemTestCase.java
  
  Index: JarFileSystemTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.commons.vfs.provider.jar.test;
  
  import java.io.File;
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.provider.jar.JarFileSystemProvider;
  import org.apache.commons.vfs.test.AbstractReadOnlyFileSystemTestCase;
  
  /**
   * Tests for the Jar file system.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   */
  public class JarFileSystemTestCase
      extends AbstractReadOnlyFileSystemTestCase
  {
      public JarFileSystemTestCase( String name )
      {
          super( name );
      }
  
      /**
       * Returns the URI for the base folder.
       */
      protected FileObject getBaseFolder() throws Exception
      {
          File jarFile = getTestResource( "test.jar" );
          String uri = "jar:" + jarFile.getAbsolutePath() + "!basedir";
          m_manager.addProvider( "jar", new JarFileSystemProvider() );
          return m_manager.resolveFile( uri );
      }
  
      /**
       * Verify the package loaded with class loader.
       * If the provider supports attributes override this method.
       */
      protected boolean verifyPackage( Package pack )
      {
          return "code".equals( pack.getName() ) &&
                 "ImplTitle".equals( pack.getImplementationTitle() ) &&
                 "ImplVendor".equals( pack.getImplementationVendor() ) &&
                 "1.1".equals( pack.getImplementationVersion() ) &&
                 "SpecTitle".equals( pack.getSpecificationTitle() ) &&
                 "SpecVendor".equals( pack.getSpecificationVendor() ) &&
                 "1.0".equals( pack.getSpecificationVersion() ) &&
                 !pack.isSealed();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/jar/test/NestedJarFileSystemTestCase.java
  
  Index: NestedJarFileSystemTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.commons.vfs.provider.jar.test;
  
  import java.io.File;
  import java.net.URL;
  import java.net.URLConnection;
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.impl.VFSClassLoader;
  import org.apache.commons.vfs.provider.jar.JarFileSystemProvider;
  import org.apache.commons.vfs.test.AbstractReadOnlyFileSystemTestCase;
  
  /**
   * Tests for the Zip file system.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   */
  public class NestedJarFileSystemTestCase
          extends AbstractReadOnlyFileSystemTestCase
  {
      public NestedJarFileSystemTestCase( String name )
      {
          super( name );
      }
  
      protected FileObject topFolder;
  
      protected FileObject getTopFolder() throws Exception
      {
          m_manager.addProvider( "jar", new JarFileSystemProvider() );
  
          File jarFile = getTestResource( "nested.jar" );
          String uri = "jar:" + jarFile.getAbsolutePath() + "!/";
          return m_manager.resolveFile( uri );
      }
  
      /**
       * Returns the URI for the base folder.
       */
      protected FileObject getBaseFolder() throws Exception
      {
          topFolder = getTopFolder();
          final FileObject jarFile = topFolder.resolveFile( "test.jar" );
          // Now build the nested file system
          final FileObject nestedFS =
              m_manager.createFileSystem( "jar", jarFile );
          return nestedFS.resolveFile( "/basedir" );
      }
  
      /**
       * Verify the package loaded with class loader.
       * If the provider supports attributes override this method.
       */
      protected boolean verifyPackage( Package pack )
      {
          return "code".equals( pack.getName() ) &&
                 "ImplTitle".equals( pack.getImplementationTitle() ) &&
                 "ImplVendor".equals( pack.getImplementationVendor() ) &&
                 "1.1".equals( pack.getImplementationVersion() ) &&
                 "SpecTitle".equals( pack.getSpecificationTitle() ) &&
                 "SpecVendor".equals( pack.getSpecificationVendor() ) &&
                 "1.0".equals( pack.getSpecificationVersion() ) &&
                 !pack.isSealed();
      }
  
  
      public void testJarClassLoader() throws Exception
      { 
          FileObject test = topFolder.resolveFile( "normal.jar" );
          final FileObject[] objects = { test };
          VFSClassLoader loader =
              new VFSClassLoader( objects, m_manager );
  
          Class testClass = loader.loadClass( "code.ClassToLoad" );
          assertTrue( verifyNormalPackage( testClass.getPackage() ) );
          
          Object testObject = testClass.newInstance();
          assertSame( "**PRIVATE**", testObject.toString() );
  
          URL resource = loader.getResource( "file1.txt" );
          assertNotNull( resource );
          URLConnection urlCon = resource.openConnection();
          assertSameURLContent( m_charContent, urlCon );
      }
  
      /**
       * Verify the package loaded with class loader.
       * If the provider supports attributes override this method.
       */
      protected boolean verifyNormalPackage( Package pack )
      {
          return "code".equals( pack.getName() ) &&
                 "NormalTitle".equals( pack.getImplementationTitle() ) &&
                 "NormalVendor".equals( pack.getImplementationVendor() ) &&
                 "1.2".equals( pack.getImplementationVersion() ) &&
                 "NormalSpec".equals( pack.getSpecificationTitle() ) &&
                 "NormalSpecVendor".equals( pack.getSpecificationVendor() ) &&
                 "0.1".equals( pack.getSpecificationVersion() ) &&
                 pack.isSealed();
      }
  }
  
  
  
  1.8       +21 -3     jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/AbstractFileSystemTestCase.java
  
  Index: AbstractFileSystemTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/AbstractFileSystemTestCase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractFileSystemTestCase.java	21 Aug 2002 14:28:08 -0000	1.7
  +++ AbstractFileSystemTestCase.java	22 Aug 2002 01:32:49 -0000	1.8
  @@ -26,10 +26,10 @@
   import org.apache.commons.vfs.FileSystemException;
   import org.apache.commons.vfs.FileType;
   import org.apache.commons.vfs.NameScope;
  +import org.apache.commons.vfs.impl.DefaultFileReplicator;
   import org.apache.commons.vfs.impl.DefaultFileSystemManager;
  -import org.apache.commons.vfs.impl.VFSClassLoader;
   import org.apache.commons.vfs.impl.PrivilegedFileReplicator;
  -import org.apache.commons.vfs.impl.DefaultFileReplicator;
  +import org.apache.commons.vfs.impl.VFSClassLoader;
   import org.apache.commons.vfs.provider.AbstractFileObject;
   import org.apache.commons.vfs.provider.local.DefaultLocalFileSystemProvider;
   
  @@ -101,7 +101,7 @@
           dir.addChild( "file1.txt", FileType.FILE );
           dir.addChild( "file2.txt", FileType.FILE );
           dir.addChild( "file3.txt", FileType.FILE );
  -        
  +
           final FileInfo code = new FileInfo( "code", FileType.FOLDER );
           base.addChild( code );
           code.addChild( "ClassToLoad.class", FileType.FILE );
  @@ -760,6 +760,8 @@
               new VFSClassLoader( objects, m_manager );
   
           Class testClass = loader.loadClass( "code.ClassToLoad" );
  +        assertTrue( verifyPackage( testClass.getPackage() ) );
  +
           Object testObject = testClass.newInstance();
           assertSame( "**PRIVATE**", testObject.toString() );
   
  @@ -767,6 +769,22 @@
           assertNotNull( resource );
           URLConnection urlCon = resource.openConnection();
           assertSameURLContent( m_charContent, urlCon );
  +    }
  +
  +    /**
  +     * Verify the package loaded with class loader.
  +     * If the provider supports attributes override this method.
  +     */
  +    protected boolean verifyPackage( Package pack )
  +    {
  +        return "code".equals( pack.getName() ) &&
  +               pack.getImplementationTitle() == null &&
  +               pack.getImplementationVendor() == null &&
  +               pack.getImplementationVersion() == null &&
  +               pack.getSpecificationTitle() == null &&
  +               pack.getSpecificationVendor() == null &&
  +               pack.getSpecificationVersion() == null &&
  +               !pack.isSealed();
       }
   
       /**
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/test-data/normal.mf
  
  Index: normal.mf
  ===================================================================
  Manifest-Version: 1.0
  Specification-Title: NormalSpec
  Specification-Vendor: NormalSpecVendor
  Specification-Version: 0.1
  Implementation-Title: NormalTitle
  Implementation-Vendor: NormalVendor
  Implementation-Version: 1.2
  
  Name: code/
  Sealed: true
  
  
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/test-data/test.mf
  
  Index: test.mf
  ===================================================================
  Manifest-Version: 1.0
  Specification-Title: SpecTitle
  Specification-Vendor: SpecVendor
  Specification-Version: 1.0
  Implementation-Title: ImplTitle
  Implementation-Vendor: ImplVendor
  Implementation-Version: 1.1
  
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>