[jboss-cvs] JBossAS SVN: r72996 - in projects/vfs/branches/jar-alter-work/src: main/java/org/jboss/virtual/plugins/context/zip and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 2 06:59:13 EDT 2008


Author: mstruk
Date: 2008-05-02 06:59:13 -0400 (Fri, 02 May 2008)
New Revision: 72996

Modified:
   projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java
   projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
   projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContextFactory.java
   projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java
   projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/protocol/vfszip/Handler.java
   projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/spi/VFSContextFactoryLocator.java
   projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/ZipEntryHandlerUnitTestCase.java
   projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java
Log:
Got most of the unit tests passing.

Modified: projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java
===================================================================
--- projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java	2008-05-02 10:56:04 UTC (rev 72995)
+++ projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java	2008-05-02 10:59:13 UTC (rev 72996)
@@ -140,7 +140,9 @@
    public URL getChildURL(VirtualFileHandler parent, String name) throws IOException
    {
       StringBuilder urlStr = new StringBuilder(256);
-      urlStr.append(getRootURI().toString());
+      URI rootUri = getRootURI();
+      urlStr.append(rootUri.getScheme())
+              .append(":").append(rootUri.getPath());
       if(parent != null)
       {
          String pPathName = null;

Modified: projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
===================================================================
--- projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java	2008-05-02 10:56:04 UTC (rev 72995)
+++ projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java	2008-05-02 10:59:13 UTC (rev 72996)
@@ -110,15 +110,7 @@
       if(!rootFile.isFile())
          throw new RuntimeException("File not found: " + rootFile);
 
-      //try
-      //{
-         zipFile = new ZipFileWrapper(rootFile);
-      //}
-      //catch(Exception ex)
-      //{
-      //   throw new RuntimeException("Failed to open the file as zip: " + rootFile, ex);
-      //}
-
+      zipFile = new ZipFileWrapper(rootFile);
       setRootPeer(peer);
 
       String name = getRootURI().toString();   // rootFile.getName()
@@ -128,7 +120,7 @@
 
       int namePos = name.lastIndexOf("/", toPos-1);
       name = name.substring(namePos+1, toPos);
-
+      
       if(name.length() != 0 && name.charAt(name.length()-1) == '!')
          name = name.substring(0, name.length()-1);
 
@@ -136,7 +128,6 @@
       entries.put("", new EntryInfo(new ZipEntryHandler(this, null, name), null));
 
       initEntries();
-
       ZipEntryContextFactory.registerContext(this);
    }
 
@@ -149,48 +140,6 @@
          return rootFile.getName();
    }
 
-
-/*
-   public URL getChildURL(AbstractVirtualFileHandler parent, String name) {
-      try
-      {
- // --
-         StringBuilder url = new StringBuilder();
-         VirtualFileHandler peer = getRootPeer();
-         if (peer != null)
-         {
-            VFSContext peerCtx = peer.getVFSContext();
-            if (peerCtx instanceof AbstractVFSContext)
-
-               url.append( ((AbstractVirtualFileHandler) peer).getGlobalChildURI() );
-         }
-         String parentPath = parent.getLocalPathName();
-         url.append(parentPath);
-         if(!"".equals(parentPath))
-            url.append("/");
-         url.append(name);
- // --
-
-         StringBuilder urlStr = new StringBuilder(250);
-         urlStr.append(getRootURI().toString());
-         if(parent != null)
-         {
-            String pPathName = parent.getLocalPathName();
-            if(pPathName.length() != 0)
-               urlStr.append("/").append(pPathName);
-
-            urlStr.append("/").append(name);
-         }
-
-         return new URL(urlStr.toString());
-      }
-      catch(Exception ex)
-      {
-         throw new IllegalArgumentException("Name could not be converted to URL: " + name, ex);
-      }
-   }
-*/
-
    private synchronized void initEntries() throws IOException, URISyntaxException
    {
 
@@ -374,6 +323,9 @@
 
    public List<VirtualFileHandler> getChildren(VirtualFileHandler parent, boolean ignoreErrors) throws IOException
    {
+      if (parent == null)
+         throw new IllegalArgumentException("Null parent");
+
       checkIfModified();
       if(parent instanceof AbstractVirtualFileHandler)
       {

Modified: projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContextFactory.java
===================================================================
--- projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContextFactory.java	2008-05-02 10:56:04 UTC (rev 72995)
+++ projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContextFactory.java	2008-05-02 10:59:13 UTC (rev 72996)
@@ -27,7 +27,7 @@
 
    public ZipEntryContextFactory()
    {
-      super("jar", "vfsjar", "zip", "vfszip");
+      super("zip", "vfszip");  // "jar", "vfsjar",  
    }
 
    public VFSContext getVFS(URI rootURI) throws IOException

Modified: projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java
===================================================================
--- projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java	2008-05-02 10:56:04 UTC (rev 72995)
+++ projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java	2008-05-02 10:59:13 UTC (rev 72996)
@@ -83,16 +83,19 @@
 
    public boolean isLeaf() throws IOException
    {
+      checkClosed();
       return getZipEntryContext().isLeaf(this);
    }
 
    public boolean isHidden() throws IOException
    {
+      checkClosed();
       return false;
    }
 
    public InputStream openStream() throws IOException
    {
+      checkClosed();
       return getZipEntryContext().openStream(this);
    }
 

Modified: projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/protocol/vfszip/Handler.java
===================================================================
--- projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/protocol/vfszip/Handler.java	2008-05-02 10:56:04 UTC (rev 72995)
+++ projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/protocol/vfszip/Handler.java	2008-05-02 10:59:13 UTC (rev 72996)
@@ -1,6 +1,7 @@
 package org.jboss.virtual.protocol.vfszip;
 
 import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.spi.VirtualFileHandler;
 import org.jboss.virtual.plugins.context.zip.ZipEntryContext;
 import org.jboss.virtual.plugins.context.zip.ZipEntryContextFactory;
 import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
@@ -24,13 +25,15 @@
       String url = u.toString();
       ZipEntryContext ctx = (ZipEntryContext) ZipEntryContextFactory.getInstance().getVFS(u);
       if (ctx == null)
-         throw new IOException("vfs does not exist: " + url);
+         throw new IOException("No VFS context found for URL: " + url);
 
       String rootPath = ctx.getRootURI().getPath();
       String entryPath = u.getFile().substring(rootPath.length());
-      VirtualFile vf = ctx.getChild(ctx.getRoot(), entryPath).getVirtualFile();
+      
+      VirtualFileHandler child = ctx.getChild(ctx.getRoot(), entryPath);
+      VirtualFile vf = child == null ? null : child.getVirtualFile();
       if (vf == null)
-         throw new IOException("vfs does not exist: " + url);
+         throw new IOException("No VFS file found for URL: " + url);
 
       return new VirtualFileURLConnection(u, vf);
    }

Modified: projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/spi/VFSContextFactoryLocator.java
===================================================================
--- projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/spi/VFSContextFactoryLocator.java	2008-05-02 10:56:04 UTC (rev 72995)
+++ projects/vfs/branches/jar-alter-work/src/main/java/org/jboss/virtual/spi/VFSContextFactoryLocator.java	2008-05-02 10:59:13 UTC (rev 72996)
@@ -41,6 +41,7 @@
 import org.jboss.virtual.plugins.context.file.FileSystemContextFactory;
 import org.jboss.virtual.plugins.context.jar.JarContextFactory;
 import org.jboss.virtual.plugins.context.memory.MemoryContextFactory;
+import org.jboss.virtual.plugins.context.zip.ZipEntryContextFactory;
 import org.jboss.virtual.plugins.context.VfsArchiveBrowserFactory;
 import org.jboss.util.file.ArchiveBrowser;
 
@@ -250,6 +251,9 @@
       if (factoryByProtocol.containsKey("vfsmemory") == false)
          registerFactory(MemoryContextFactory.getInstance());
 
+      if (factoryByProtocol.containsKey("vfszip") == false)
+         registerFactory(ZipEntryContextFactory.getInstance());
+      
       initialized = true;
    }
    

Modified: projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/ZipEntryHandlerUnitTestCase.java
===================================================================
--- projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/ZipEntryHandlerUnitTestCase.java	2008-05-02 10:56:04 UTC (rev 72995)
+++ projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/ZipEntryHandlerUnitTestCase.java	2008-05-02 10:59:13 UTC (rev 72996)
@@ -37,12 +37,12 @@
 import java.util.jar.*;
 
 /**
- * JARVirtualFileHandlerUnitTestCase.
+ * ZipEntryHandlerUnitTestCase.
  *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
+ * @author <a href="strukelj at parsek.net">Marko Strukelj</a>
+ * @version $Revision: 1.0 $
  */
-public class ZipEntryHandlerUnitTestCase extends AbstractVirtualFileHandlerTest
+public class ZipEntryHandlerUnitTestCase extends JARVirtualFileHandlerUnitTestCase
 {
    public ZipEntryHandlerUnitTestCase(String name)
    {
@@ -54,93 +54,6 @@
       return new TestSuite(ZipEntryHandlerUnitTestCase.class);
    }
 
-
-
-   /*
-   public void testJarCache() throws Exception
-   {
-      // Create a test.jar with v1 in manifest
-      File testFile = new File("test.jar");
-      {
-         Manifest manifest = new Manifest();
-         manifest.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1");
-         manifest.getMainAttributes().putValue("test", "v1");
-         JarOutputStream out = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(testFile)), manifest);
-         out.flush();
-         out.close();
-      }
-
-      // Verify it via VFS
-      File root = new File(".");
-      {
-         VirtualFile vf = VFS.getVirtualFile(root.toURL(), "test.jar");
-//         System.err.println("lastModified = " + vf.getLastModified());
-         VirtualFile manifestFile = vf.findChild("META-INF/MANIFEST.MF");
-         Manifest manifest = new Manifest(manifestFile.openStream());
-         String actual = manifest.getMainAttributes().getValue("test");
-         assertEquals("v1", actual);
-      }
-
-      // If we don't delete, VFS will give ZIP errors (related issue?)
-      assertTrue("test file deleted: " + testFile, testFile.delete());
-
-      // Create a new test.jar with manifest v2
-      {
-         Manifest manifest = new Manifest();
-         manifest.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1");
-         manifest.getMainAttributes().putValue("test", "v2");
-         JarOutputStream out = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(testFile)), manifest);
-         out.flush();
-         out.close();
-      }
-
-      // Verify the manifest the JDK way
-      {
-         JarFile jarFile = new JarFile(testFile);
-         String actual = jarFile.getManifest().getMainAttributes().getValue("test");
-         assertEquals("JDK found the wrong manifest", "v2", actual);
-         jarFile.close();
-      }
-
-      // Verify the manifest the VFS way
-      {
-         VirtualFile vf = VFS.getVirtualFile(root.toURL(), "test.jar");
-         // Note that the modification date has not changed according to VFS
-//         System.err.println("lastModified = " + vf.getLastModified());
-//         System.err.println("modified = " + vf.hasBeenModified());
-
-         VirtualFile manifestFile = vf.findChild("META-INF/MANIFEST.MF");
-         Manifest manifest = new Manifest(manifestFile.openStream());
-         String actual = manifest.getMainAttributes().getValue("test");
-         assertEquals("VFS found the wrong manifest", "v2", actual);
-      }
-   }
-   */
-
-
-   protected URL getRootResource(String name) throws Exception
-   {
-      if (name.endsWith(".jar"))
-         return getResource("/vfs/context/jar/" + name);
-      else
-         return getResource("/vfs/context/jar/" + name + ".jar");
-   }
-
-   protected File getRealJarFile(String name) throws Exception
-   {
-      URL url = getRootResource(name);
-      return new File(url.getPath());
-   }
-
-   protected JarEntry getRealJarEntry(String name, String path) throws Exception
-   {
-      URL url = getRootResource(name);
-      url = JarUtils.createJarURL(url);
-      JarURLConnection c = (JarURLConnection) url.openConnection();
-      JarFile jarFile = c.getJarFile();
-      return jarFile.getJarEntry(path);
-   }
-
    protected VFSContext getVFSContext(String name) throws Exception
    {
       URL url = getRootResource(name);
@@ -148,36 +61,4 @@
       return new ZipEntryContext(url);
    }
 
-   protected String getRootName(String name) throws Exception
-   {
-      return name + ".jar";
-   }
-
-   protected long getRealLastModified(String name, String path) throws Exception
-   {
-      if (path != null)
-      {
-         JarEntry entry = getRealJarEntry(name, path);
-         return entry.getTime();
-      }
-      else
-      {
-         File file = getRealJarFile(name);
-         return file.lastModified();
-      }
-   }
-
-   protected long getRealSize(String name, String path) throws Exception
-   {
-      if (path != null)
-      {
-         JarEntry entry = getRealJarEntry(name, path);
-         return entry.getSize();
-      }
-      else
-      {
-         File file = getRealJarFile(name);
-         return file.length();
-      }
-   }
 }
\ No newline at end of file

Modified: projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java
===================================================================
--- projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java	2008-05-02 10:56:04 UTC (rev 72995)
+++ projects/vfs/branches/jar-alter-work/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java	2008-05-02 10:59:13 UTC (rev 72996)
@@ -33,12 +33,12 @@
 import java.net.URL;
 
 /**
- * JARVFSContextUnitTestCase.
+ * ZipEntryVFSContextUnitTestCase.
  *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
+ * @author <a href="strukelj at parsek.net">Marko Strukelj</a>
+ * @version $Revision: 1.0 $
  */
-public class ZipEntryVFSContextUnitTestCase extends AbstractVFSContextTest
+public class ZipEntryVFSContextUnitTestCase extends JARVFSContextUnitTestCase
 {
    public ZipEntryVFSContextUnitTestCase(String name)
    {
@@ -59,19 +59,10 @@
       return new ZipEntryContext(url);
    }
 
-   protected VFSContext getParentVFSContext() throws Exception
-   {
-      URL url = getResource("/vfs/context/jar/");
-      return new FileSystemContext(url);
-   }
 
-   protected String getSuffix()
-   {
-      return ".jar";
-   }
 
    /**
-    * Was having problems with a jar entry as root of VFS.
+    * Analog to the same test in {@link JARVFSContextUnitTestCase}
     *
     * @throws Exception
     */
@@ -91,8 +82,7 @@
    }
 
    /**
-    * Was having problems with a jar entry as root of VFS.
-    * A JarEntry that is the root of the VFS should have a VFS Path of ""
+    * Analog to the same test in {@link JARVFSContextUnitTestCase}
     *
     * @throws Exception
     */




More information about the jboss-cvs-commits mailing list