[jboss-cvs] JBossAS SVN: r80755 - 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 17:11:45 EST 2008
Author: anil.saldhana at jboss.com
Date: 2008-11-10 17:11:44 -0500 (Mon, 10 Nov 2008)
New Revision: 80755
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:
JBVFS-77: VFSUtils.getRealURL
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-10 22:11:29 UTC (rev 80754)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java 2008-11-10 22:11:44 UTC (rev 80755)
@@ -43,6 +43,7 @@
import org.jboss.logging.Logger;
import org.jboss.util.StringPropertyReplacer;
import org.jboss.util.collection.CollectionsFactory;
+import org.jboss.virtual.plugins.context.jar.JarUtils;
import org.jboss.virtual.plugins.copy.CopyMechanism;
import org.jboss.virtual.plugins.copy.ExplodedCopyMechanism;
import org.jboss.virtual.plugins.copy.TempCopyMechanism;
@@ -112,6 +113,11 @@
public static final String VFS_CACHE_KEY = "jboss.vfs.cache";
/**
+ * Constant representing the URL file protocol
+ */
+ public static final String FILE_PROTOCOL = "file";
+
+ /**
* Stop cache.
*/
public static void stopCache()
@@ -149,6 +155,25 @@
return buffer.toString();
}
+
+ /**
+ * Get the Real URL
+ * @param vfsURL
+ * @return
+ * @throws Exception
+ */
+ public static URL getRealURL(URL vfsURL) throws Exception
+ {
+ if(vfsURL.getPath().endsWith("jar"))
+ return JarUtils.createJarURL(vfsURL);
+
+ if(vfsURL.getProtocol().startsWith("vfsfile"))
+ return new URL(FILE_PROTOCOL, vfsURL.getHost(), vfsURL.getPort(), vfsURL.getFile());
+
+ if(log.isTraceEnabled())
+ log.trace("getRealURL did not have a match for:"+vfsURL.toExternalForm());
+ return vfsURL;
+ }
/**
* Add manifest paths
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-10 22:11:29 UTC (rev 80754)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSUtilTestCase.java 2008-11-10 22:11:44 UTC (rev 80755)
@@ -22,19 +22,21 @@
package org.jboss.test.virtual.test;
import java.net.URL;
+import java.util.ArrayList;
import java.util.List;
-import java.util.ArrayList;
import junit.framework.Test;
import junit.framework.TestSuite;
+
import org.jboss.virtual.VFS;
+import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.VFSUtils;
/**
* VFSUtilTestCase.
*
* @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @author anil.saldhana at jboss.com
*/
public class VFSUtilTestCase extends AbstractMockVFSTest
{
@@ -58,4 +60,24 @@
VFSUtils.addManifestLocations(file, paths);
assertEquals(3, paths.size());
}
+
+ public void testRealURL() throws Exception
+ {
+ URL url = getResource("/vfs/test");
+ VirtualFile root = VFS.getRoot(url);
+ VirtualFile jarFile = root.getChild("badmf.jar");
+
+ URL vfsURL = jarFile.toURL();
+ assertTrue(vfsURL.toExternalForm().startsWith("vfszip"));
+ URL realURL = VFSUtils.getRealURL(vfsURL);
+ assertTrue(realURL.toExternalForm().startsWith("jar:"));
+
+
+ url = getResource("/vfs/context/file/simple");
+ VirtualFile regularFile = VFS.getRoot(url).getChild("tomodify");
+ vfsURL = regularFile.toURL();
+ assertTrue(vfsURL.getProtocol().startsWith("vfsfile"));
+ realURL = VFSUtils.getRealURL(vfsURL);
+ assertTrue(realURL.toExternalForm().startsWith("file:"));
+ }
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list