[jboss-cvs] JBossAS SVN: r86758 - in projects/vfs/trunk/src: main/java/org/jboss/virtual/protocol/vfsjar and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Apr 3 13:31:06 EDT 2009


Author: wolfc
Date: 2009-04-03 13:31:06 -0400 (Fri, 03 Apr 2009)
New Revision: 86758

Added:
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JarFileURLTestCase.java
Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarContext.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsjar/Handler.java
Log:
JBVFS-102: fixed JarContext to initialize the full jar with a top level URL instead of entry URL

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	2009-04-03 17:27:05 UTC (rev 86757)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarContext.java	2009-04-03 17:31:06 UTC (rev 86758)
@@ -87,6 +87,12 @@
       String jarName = extractJarName(urlStr);
       String entryPath = urlStr;
       entryPath = entryPath(entryPath);
+      // make sure that JarHandler.initJar works on the jar itself
+      if(entryPath != null)
+      {
+         String s = url.toExternalForm();
+         url = new URL(s.substring(0, s.length() - entryPath.length()));
+      }
       JarHandler jar =  new JarHandler(this, parent, url, jarName);
       if (entryPath == null)
          return jar;

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsjar/Handler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsjar/Handler.java	2009-04-03 17:27:05 UTC (rev 86757)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsjar/Handler.java	2009-04-03 17:31:06 UTC (rev 86758)
@@ -40,7 +40,14 @@
    {
       String urlString = u.toString();
       int index = urlString.indexOf("!/");
-      String file = urlString.substring(3, index + 2); // strip out vfs
+      // because we trim the url in JarContext.createVirtualFileHandler we can
+      // actually end up with a vfsjar:file: URL which does not point to an entry.
+      String file;
+      // strip out vfs
+      if(index == -1)
+         file = urlString.substring(3);
+      else
+         file = urlString.substring(3, index + 2);
       String path = urlString.substring(index + 2);
       URL url = new URL(file);
       return new VirtualFileURLConnection(u, url, path);

Added: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JarFileURLTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JarFileURLTestCase.java	                        (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JarFileURLTestCase.java	2009-04-03 17:31:06 UTC (rev 86758)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.virtual.test;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class JarFileURLTestCase extends AbstractVFSTest
+{
+   public JarFileURLTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void test1() throws Exception
+   {
+      URL url = getResource("/vfs/test/jar1.jar");
+      URL manifestURL = new URL("jar:" + url.toExternalForm() + "!/META-INF/MANIFEST.MF");
+      
+      // first we ask for a jar:file: resource
+      
+      VirtualFile manifest = VFS.getRoot(manifestURL);
+      
+      InputStream in = manifest.openStream();
+      in.close();
+      
+      in = manifest.toURL().openStream();
+      in.close();
+   }
+}




More information about the jboss-cvs-commits mailing list