[jboss-cvs] JBossAS SVN: r61764 - in projects/vfs/trunk/src: test/java/org/jboss/test/virtual/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 27 18:43:10 EDT 2007


Author: bill.burke at jboss.com
Date: 2007-03-27 18:43:09 -0400 (Tue, 27 Mar 2007)
New Revision: 61764

Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarContext.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java
Log:
JarEntry as root of VFS was not working correctly

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarContext.java	2007-03-27 22:30:58 UTC (rev 61763)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarContext.java	2007-03-27 22:43:09 UTC (rev 61764)
@@ -72,22 +72,49 @@
     * @throws IOException for any error accessing the file system
     * @throws IllegalArgumentException for a null entry or url
     */
-   public VirtualFileHandler createVirtualFileHandler(VirtualFileHandler parent, URL url) throws IOException
+   protected VirtualFileHandler createVirtualFileHandler(VirtualFileHandler parent, URL url) throws IOException
    {
       if (url == null)
          throw new IllegalArgumentException("Null url");
 
-      String name = url.toString();
-      int index = name.indexOf('!');
+      String urlStr = url.toString();
+      String jarName = extractJarName(urlStr);
+      String entryPath = urlStr;
+      entryPath = entryPath(entryPath);
+      JarHandler jar =  new JarHandler(this, parent, url, jarName);
+      if (entryPath == null) return jar;
+      return jar.findChild(entryPath);
+   }
+
+   public static String entryPath(String entryName)
+   {
+      int index;
+      index = entryName.indexOf("!/");
       if (index != -1)
-         name = name.substring(0, index);
-      index = name.lastIndexOf('/');
-      if (index != -1 && index < name.length()-1)
-         name = name.substring(index+1);
+      {
+         entryName = entryName.substring(index + 2);
+      }
+      else
+      {
+         entryName = null;
+      }
+      if (entryName.trim().equals("")) return null;
       
-      return new JarHandler(this, parent, url, name);
+      return entryName;
    }
-   
+
+   public static String extractJarName(String urlStr)
+   {
+      String jarName = urlStr;
+      int index = jarName.indexOf('!');
+      if (index != -1)
+         jarName = jarName.substring(0, index);
+      index = jarName.lastIndexOf('/');
+      if (index != -1 && index < jarName.length()-1)
+         jarName = jarName.substring(index+1);
+      return jarName;
+   }
+
    @Override
    protected void finalize() throws Throwable
    {
@@ -95,4 +122,5 @@
          rootFile.close();
       super.finalize();
    }
+
 }

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java	2007-03-27 22:30:58 UTC (rev 61763)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java	2007-03-27 22:43:09 UTC (rev 61764)
@@ -21,19 +21,18 @@
 */
 package org.jboss.test.virtual.test;
 
-import java.net.URL;
-
 import junit.framework.Test;
 import junit.framework.TestSuite;
-
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.plugins.context.jar.JarContext;
 import org.jboss.virtual.plugins.context.jar.JarUtils;
 import org.jboss.virtual.spi.VFSContext;
 
+import java.net.URL;
+
 /**
  * JARVFSContextUnitTestCase.
- * 
+ *
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @version $Revision: 1.1 $
  */
@@ -47,7 +46,7 @@
    public static Test suite()
    {
       VFS.init();
-      System.out.println("java.protocol.handler.pkgs: "+System.getProperty("java.protocol.handler.pkgs"));
+      System.out.println("java.protocol.handler.pkgs: " + System.getProperty("java.protocol.handler.pkgs"));
       return new TestSuite(JARVFSContextUnitTestCase.class);
    }
 
@@ -57,4 +56,49 @@
       url = JarUtils.createJarURL(url);
       return new JarContext(url);
    }
+
+
+   /**
+    * Was having problems with a jar entry as root of VFS.
+    *
+    * @throws Exception
+    */
+   public void testJarEntryAsRoot() throws Exception
+   {
+      URL url = getResource("/vfs/context/jar/simple.jar");
+      URL entry = new URL("jar:" + url.toString() + "!/child");
+      //entry.openStream().close();
+      JarContext context = new JarContext(entry);
+      assertEquals("child", context.getRoot().getName());
+
+      url = getResource("/vfs/test/outer.jar");
+      entry = new URL("jar:" + url.toString() + "!/jar2.jar ");
+      //entry.openStream().close();
+      context = new JarContext(entry);
+      assertEquals("jar2.jar", context.getRoot().getName());
+   }
+
+   /**
+    * 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 ""
+    *
+    * @throws Exception
+    */
+   public void testPathIsEmptryForJarEntryAsRoot() throws Exception
+   {
+      URL url = getResource("/vfs/context/jar/simple.jar");
+      URL entry = new URL("jar:" + url.toString() + "!/child");
+      //entry.openStream().close();
+      JarContext context = new JarContext(entry);
+      assertEquals("child", context.getRoot().getName());
+      assertEquals("", context.getRoot().getPathName());
+
+      url = getResource("/vfs/test/outer.jar");
+      entry = new URL("jar:" + url.toString() + "!/jar2.jar ");
+      //entry.openStream().close();
+      context = new JarContext(entry);
+      assertEquals("jar2.jar", context.getRoot().getName());
+      assertEquals("", context.getRoot().getPathName());
+   }
+
 }




More information about the jboss-cvs-commits mailing list