[jboss-cvs] JBossAS SVN: r101975 - in projects/vfs/trunk/src: main/java/org/jboss/vfs/protocol and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Mar 5 12:58:42 EST 2010
Author: johnbailey
Date: 2010-03-05 12:58:42 -0500 (Fri, 05 Mar 2010)
New Revision: 101975
Added:
projects/vfs/trunk/src/main/java/org/jboss/vfs/protocol/vfs/
projects/vfs/trunk/src/main/java/org/jboss/vfs/protocol/vfs/Handler.java
Modified:
projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java
projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java
projects/vfs/trunk/src/test/java/org/jboss/test/vfs/FileVFSUnitTestCase.java
projects/vfs/trunk/src/test/java/org/jboss/test/vfs/JARSerializationUnitTestCase.java
projects/vfs/trunk/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java
projects/vfs/trunk/src/test/java/org/jboss/test/vfs/support/ClassPathIterator.java
Log:
[JBVFS-145] - Introduced supoort for the vfs: URL protocol and updated VirtualFile to always return vfs: URLs
Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java 2010-03-05 17:56:57 UTC (rev 101974)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java 2010-03-05 17:58:42 UTC (rev 101975)
@@ -75,14 +75,10 @@
private static final String DEFAULT_ENCODING = "UTF-8";
/**
- * Constant representing the URL file protocol
+ * Constant representing the URL vfs protocol
*/
- public static final String FILE_PROTOCOL = "file";
+ public static final String VFS_PROTOCOL = "vfs";
- /**
- * Standard separator for JAR URL
- */
- public static final String JAR_URL_SEPARATOR = "!/";
/**
* The default buffer size to use for copies
@@ -497,7 +493,7 @@
*/
public static URL getVirtualURL(VirtualFile file) throws MalformedURLException {
// todo: specify the URL handler directly as a minor optimization
- return new URL("file", "", -1, file.getPathName(true));
+ return new URL(VFS_PROTOCOL, "", -1, file.getPathName(true));
}
/**
@@ -516,7 +512,7 @@
* @see VirtualFile#asFileURI()
*/
public static URI getVirtualURI(VirtualFile file) throws URISyntaxException {
- return new URI("file", "", file.getPathName(true), null);
+ return new URI(VFS_PROTOCOL, "", file.getPathName(true), null);
}
/**
Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java 2010-03-05 17:56:57 UTC (rev 101974)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java 2010-03-05 17:58:42 UTC (rev 101975)
@@ -476,7 +476,7 @@
*/
public URL asDirectoryURL() throws MalformedURLException {
final String pathName = getPathName(false);
- return new URL("file", "", -1, parent == null ? pathName : pathName + "/");
+ return new URL(VFSUtils.VFS_PROTOCOL, "", -1, parent == null ? pathName : pathName + "/");
}
/**
@@ -488,7 +488,7 @@
*/
public URI asDirectoryURI() throws URISyntaxException {
final String pathName = getPathName(false);
- return new URI("file", "", parent == null ? pathName : pathName + "/", null);
+ return new URI(VFSUtils.VFS_PROTOCOL, "", parent == null ? pathName : pathName + "/", null);
}
/**
@@ -500,7 +500,7 @@
* @throws MalformedURLException if the URL is somehow malformed
*/
public URL asFileURL() throws MalformedURLException {
- return new URL("file", "", -1, getPathName(false));
+ return new URL(VFSUtils.VFS_PROTOCOL, "", -1, getPathName(false));
}
/**
@@ -512,7 +512,7 @@
* @throws URISyntaxException if the URI is somehow malformed
*/
public URI asFileURI() throws URISyntaxException {
- return new URI("file", "", getPathName(false), null);
+ return new URI(VFSUtils.VFS_PROTOCOL, "", getPathName(false), null);
}
/**
Added: projects/vfs/trunk/src/main/java/org/jboss/vfs/protocol/vfs/Handler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/protocol/vfs/Handler.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/protocol/vfs/Handler.java 2010-03-05 17:58:42 UTC (rev 101975)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.vfs.protocol.vfs;
+
+import org.jboss.vfs.protocol.VirtualFileURLStreamHandler;
+
+/**
+ * Stub handler class.
+ */
+public final class Handler extends VirtualFileURLStreamHandler {
+
+}
\ No newline at end of file
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/vfs/FileVFSUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/vfs/FileVFSUnitTestCase.java 2010-03-05 17:56:57 UTC (rev 101974)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/vfs/FileVFSUnitTestCase.java 2010-03-05 17:58:42 UTC (rev 101975)
@@ -784,7 +784,7 @@
long size = tmp.length();
String name = tmp.getName();
- URL url = tmp.toURI().toURL();
+ URL url = toVfsUrl(tmp.toURI().toURL());
String vfsPath = url.getPath();
log.debug("name: " + name);
log.debug("vfsPath: " + vfsPath);
@@ -995,7 +995,7 @@
log.debug("outerURI: " + outerURI);
assertTrue(outerURI + " ends in '/'", outerURI.getPath().endsWith("/"));
// Validate that jar1 is under unpacked-outer.jar
- URI jar1URI = new URI(outerURI + "jar1.jar/");
+ URI jar1URI = toVfsUri(new URI(outerURI + "jar1.jar/"));
log.debug("jar1URI: " + jar1URI + ", path=" + jar1URI.getPath());
assertTrue("jar1URI path ends in unpacked-outer.jar/jar1.jar!/", jar1URI.getPath().endsWith("unpacked-outer.jar/jar1.jar/"));
VirtualFile jar1 = outerJar.getChild("jar1.jar");
@@ -1178,7 +1178,7 @@
{
assertNotNull("tstjar != null", tstjar);
URI uri = tstjar.toURI();
- URI expectedURI = new URI("vfs" + rootURL.toString() + "/path%20with%20spaces/tst.jar/");
+ URI expectedURI = toVfsUri(new URI(rootURL.toString() + "/path%20with%20spaces/tst.jar/"));
assertEquals(expectedURI.getPath(), uri.getPath());
InputStream is = uri.toURL().openStream();
@@ -1188,7 +1188,7 @@
mounts.addAll(recursiveMount(tstjar));
assertNotNull("tstjar != null", tstjar);
uri = tstjar.toURI();
- expectedURI = new URI("vfs" + rootURL.toString() + "/path%20with%20spaces/tst%2520nospace.jar/");
+ expectedURI = toVfsUri(new URI(rootURL.toString() + "/path%20with%20spaces/tst%2520nospace.jar/"));
assertEquals(expectedURI.getPath(), uri.getPath());
is = uri.toURL().openStream();
@@ -1211,7 +1211,7 @@
assertNotNull("spaces.ear != null", tstear);
assertTrue(tstear.isDirectory());
URI uri = tstear.toURI();
- URI expectedURI = new URI("vfs" + rootURL.toString() + "/spaces.ear/");
+ URI expectedURI = toVfsUri(new URI(rootURL.toString() + "/spaces.ear/"));
assertEquals(expectedURI.getPath(), uri.getPath());
InputStream is = uri.toURL().openStream();
@@ -1220,7 +1220,7 @@
VirtualFile tstjar = tstear.getChild("spaces-ejb.jar");
assertNotNull("spaces-ejb.jar != null", tstjar);
uri = tstjar.toURI();
- expectedURI = new URI("vfs" + rootURL.toString() + "/spaces.ear/spaces-ejb.jar/");
+ expectedURI = toVfsUri(new URI(rootURL.toString() + "/spaces.ear/spaces-ejb.jar/"));
assertEquals(expectedURI.getPath(), uri.getPath());
assertFalse(tstjar.isFile());
assertTrue(tstjar.isDirectory());
@@ -1231,7 +1231,7 @@
tstjar = tstear.getChild("spaces-lib.jar");
assertNotNull("spaces-lib.jar != null", tstjar);
uri = tstjar.toURI();
- expectedURI = new URI("vfs" + rootURL.toString() + "/spaces.ear/spaces-lib.jar/");
+ expectedURI = toVfsUri(new URI(rootURL.toString() + "/spaces.ear/spaces-lib.jar/"));
assertEquals(expectedURI.getPath(), uri.getPath());
assertFalse(tstjar.isFile());
assertTrue(tstjar.isDirectory());
@@ -1257,8 +1257,8 @@
VirtualFile tstjar = testdir.getChild("path with spaces/unpacked-tst.jar");
assertNotNull("tstjar != null", tstjar);
URI uri = tstjar.toURI();
- URI expectedURI = new URI(rootURL.toString() + "/path%20with%20spaces/unpacked-tst.jar/");
- assertEquals(uri, expectedURI);
+ URI expectedURI = toVfsUri(new URI(rootURL.toString() + "/path%20with%20spaces/unpacked-tst.jar/"));
+ assertEquals(expectedURI, uri);
}
// /**
@@ -1469,6 +1469,15 @@
assertTrue(tmpRoot + ".delete()", root.delete());
}
+ private URL toVfsUrl(URL fileUrl) throws Exception
+ {
+ return new URL(VFSUtils.VFS_PROTOCOL, fileUrl.getHost(), fileUrl.getFile());
+ }
+
+ private URI toVfsUri(URI fileUri) throws Exception {
+ return new URI(VFSUtils.VFS_PROTOCOL, fileUri.getHost(), fileUri.getPath(), fileUri.getFragment());
+ }
+
/**
* Test for <em>caseSensitive=true</em>
*
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/vfs/JARSerializationUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/vfs/JARSerializationUnitTestCase.java 2010-03-05 17:56:57 UTC (rev 101974)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/vfs/JARSerializationUnitTestCase.java 2010-03-05 17:58:42 UTC (rev 101975)
@@ -344,7 +344,7 @@
List<Closeable> mounts = recursiveMount(VFS.getChild(url));
try
{
- url = new URL("file" + urlString.substring(p) + "/lib/spring-beans.jar/org/jboss/test/spring");
+ url = new URL(VFSUtils.VFS_PROTOCOL + urlString.substring(p) + "/lib/spring-beans.jar/org/jboss/test/spring");
VirtualFile file = VFS.getChild(url);
assertNotNull("No beans dir", file.getChild("beans"));
testVirtualFileAdaptor(file, "beans");
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java 2010-03-05 17:56:57 UTC (rev 101974)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java 2010-03-05 17:58:42 UTC (rev 101975)
@@ -33,6 +33,7 @@
import junit.framework.Test;
import org.jboss.vfs.VFS;
+import org.jboss.vfs.VFSUtils;
import org.jboss.vfs.VirtualFile;
/**
@@ -65,6 +66,13 @@
return file;
}
+ protected URL getURLAndAssertProtocol(VirtualFile file) throws Exception
+ {
+ URL url = file.toURL();
+ assertEquals(VFSUtils.VFS_PROTOCOL, url.getProtocol());
+ return url;
+ }
+
/**
* Test url connection content.
*
@@ -73,7 +81,7 @@
public void testContent() throws Exception
{
VirtualFile file = getFile();
- URL url = file.toURL();
+ URL url = getURLAndAssertProtocol(file);
URLConnection conn = url.openConnection();
assertEquals(file, conn.getContent());
}
@@ -86,7 +94,7 @@
public void testContentLenght() throws Exception
{
VirtualFile file = getFile();
- URL url = file.toURL();
+ URL url = getURLAndAssertProtocol(file);
URLConnection conn = url.openConnection();
assertEquals(file.getSize(), conn.getContentLength());
}
@@ -99,7 +107,7 @@
public void testLastModified() throws Exception
{
VirtualFile file = getFile();
- URL url = file.toURL();
+ URL url = getURLAndAssertProtocol(file);
URLConnection conn = url.openConnection();
assertEquals(file.getLastModified(), conn.getLastModified());
}
@@ -112,7 +120,7 @@
public void testInputStream() throws Exception
{
VirtualFile file = getFile();
- URL url = file.toURL();
+ URL url = getURLAndAssertProtocol(file);
URLConnection conn = url.openConnection();
assertTrue(Arrays.equals(readBytes(file.openStream()), readBytes(conn.getInputStream())));
}
@@ -123,7 +131,7 @@
VirtualFile file = root.getChild("path with spaces/spaces.ear");
File real = file.getPhysicalFile();
assertTrue(real.exists());
- URL url = file.toURL();
+ URL url = getURLAndAssertProtocol(file);
URLConnection conn = url.openConnection();
assertTrue(Arrays.equals(readBytes(conn.getInputStream()), readBytes(file.openStream())));
}
@@ -134,11 +142,22 @@
temp.deleteOnExit();
VirtualFile file = VFS.getChild(temp.toURI());
assertTrue(file.exists());
- URL url = file.toURL();
+ URL url = getURLAndAssertProtocol(file);
URLConnection conn = url.openConnection();
assertEquals(file.getLastModified(), conn.getLastModified());
}
-
+
+ public void testOutsideUrl() throws Exception
+ {
+ URL url = getResource("/vfs/test/outer.jar");
+ File file = new File(url.toURI());
+
+ url = new URL(VFSUtils.VFS_PROTOCOL, url.getHost(), url.getPort(), url.getFile());
+
+ URLConnection conn = url.openConnection();
+ assertEquals(file.lastModified(), conn.getLastModified());
+ }
+
protected static byte[] readBytes(InputStream inputStream) throws Exception
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/vfs/support/ClassPathIterator.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/vfs/support/ClassPathIterator.java 2010-03-05 17:56:57 UTC (rev 101974)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/vfs/support/ClassPathIterator.java 2010-03-05 17:58:42 UTC (rev 101975)
@@ -34,6 +34,7 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
+import org.jboss.vfs.VFSUtils;
import org.jboss.vfs.VirtualFile;
import org.jboss.vfs.VirtualFileFilter;
@@ -58,7 +59,7 @@
if( protocol == null )
{
}
- else if( protocol.equals("file") || protocol.startsWith("vfs"))
+ else if( protocol.equals(VFSUtils.VFS_PROTOCOL))
{
URLConnection conn = url.openConnection();
vf = (VirtualFile) conn.getContent();
More information about the jboss-cvs-commits
mailing list