[jboss-cvs] JBossAS SVN: r80785 - 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
Mon Nov 10 23:19:47 EST 2008
Author: anil.saldhana at jboss.com
Date: 2008-11-10 23:19:46 -0500 (Mon, 10 Nov 2008)
New Revision: 80785
Modified:
projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSUtilTestCase.java
Log:
VFS-77
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java 2008-11-11 04:01:11 UTC (rev 80784)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java 2008-11-11 04:19:46 UTC (rev 80785)
@@ -117,6 +117,9 @@
*/
public static final String FILE_PROTOCOL = "file";
+ /** Standard separator for JAR URL */
+ public static final String JAR_URL_SEPARATOR = "!/";
+
/**
* Stop cache.
*/
@@ -165,11 +168,23 @@
public static URL getRealURL(URL vfsURL) throws Exception
{
if(vfsURL.getPath().endsWith("jar"))
- return JarUtils.createJarURL(vfsURL);
+ {
+ String urlStr = "jar:" + FILE_PROTOCOL + ":" + vfsURL.getPath() + JAR_URL_SEPARATOR;
+ return new URL(urlStr);
+ }
if(vfsURL.getProtocol().startsWith("vfsfile"))
return new URL(FILE_PROTOCOL, vfsURL.getHost(), vfsURL.getPort(), vfsURL.getFile());
+ if(vfsURL.getProtocol().startsWith("vfszip"))
+ {
+ String urlStr = vfsURL.toExternalForm();
+ //nested file
+ int indexJar = urlStr.indexOf(".jar");
+ String beforejar = urlStr.substring("vfszip:".length(), urlStr.indexOf(".jar"));
+ String afterjar = urlStr.substring(indexJar + 1 + ".jar".length());
+ return new URL("jar:file:" + beforejar + ".jar " + JAR_URL_SEPARATOR + afterjar);
+ }
if(log.isTraceEnabled())
log.trace("getRealURL did not have a match for:"+vfsURL.toExternalForm());
return vfsURL;
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSUtilTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSUtilTestCase.java 2008-11-11 04:01:11 UTC (rev 80784)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSUtilTestCase.java 2008-11-11 04:19:46 UTC (rev 80785)
@@ -21,6 +21,7 @@
*/
package org.jboss.test.virtual.test;
+import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -63,16 +64,25 @@
public void testRealURL() throws Exception
{
+ //Regular jar
URL url = getResource("/vfs/test");
VirtualFile root = VFS.getRoot(url);
VirtualFile jarFile = root.getChild("badmf.jar");
-
- URL vfsURL = jarFile.toURL();
+
+ URL vfsURL = jarFile.toURL();
assertTrue(vfsURL.toExternalForm().startsWith("vfszip"));
URL realURL = VFSUtils.getRealURL(vfsURL);
assertTrue(realURL.toExternalForm().startsWith("jar:"));
-
+ //Nested file in a jar
+ url = getResource("/vfs/test/nested");
+ root = VFS.getRoot(url);
+ VirtualFile nestedFile = root.getChild("/nested.jar/META-INF/empty.txt");
+ URL fileURL = nestedFile.toURL();
+ realURL = VFSUtils.getRealURL(fileURL);
+ assertTrue(realURL.toExternalForm().startsWith("jar:"));
+
+ //Regular file
url = getResource("/vfs/context/file/simple");
VirtualFile regularFile = VFS.getRoot(url).getChild("tomodify");
vfsURL = regularFile.toURL();
More information about the jboss-cvs-commits
mailing list