[jboss-cvs] JBossAS SVN: r93608 - in projects/vfs/branches/Branch_2_1/src: main/java/org/jboss/virtual/plugins/cache and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Sep 16 09:25:34 EDT 2009
Author: alesj
Date: 2009-09-16 09:25:33 -0400 (Wed, 16 Sep 2009)
New Revision: 93608
Modified:
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/VFSUtils.java
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/cache/PathMatchingVFSCache.java
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java
projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java
Log:
[JBVFS-118]; fix canonical url cache lookup.
Modified: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/VFSUtils.java 2009-09-16 13:20:28 UTC (rev 93607)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/VFSUtils.java 2009-09-16 13:25:33 UTC (rev 93608)
@@ -48,6 +48,7 @@
import org.jboss.virtual.plugins.copy.TempCopyMechanism;
import org.jboss.virtual.plugins.copy.UnjarCopyMechanism;
import org.jboss.virtual.plugins.copy.UnpackCopyMechanism;
+import org.jboss.virtual.plugins.vfs.helpers.PathTokenizer;
import org.jboss.virtual.spi.LinkInfo;
import org.jboss.virtual.spi.Options;
import org.jboss.virtual.spi.VFSContext;
@@ -1079,12 +1080,13 @@
}
/**
- * Strip protocol from url string.
+ * Get path.
+ * Apply Carlo's fix as well.
*
* @param uri the uri
- * @return uri's path string
+ * @return uri's path
*/
- public static String stripProtocol(URI uri)
+ protected static String getPath(URI uri)
{
String path = uri.getPath();
if(path == null)
@@ -1093,23 +1095,51 @@
if(s.startsWith("jar:file:"))
path = s.substring("jar:file:".length()).replaceFirst("!/", "/") + "/";
}
- if (path != null && path.length() > 0)
+ return path;
+ }
+
+ /**
+ * Strip protocol from url string, return tokens.
+ *
+ * @param uri the uri
+ * @return uri's path string tokens
+ */
+ public static List<String> stripProtocolToTokens(URI uri)
+ {
+ String path = getPath(uri);
+ try
{
- StringBuilder sb = new StringBuilder(path);
+ return PathTokenizer.applySpecialPathsToTokens(path);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
- if (sb.charAt(0) != '/')
- sb.insert(0, '/');
- if (sb.charAt(sb.length() - 1) != '/')
- sb.append('/');
-
- path = sb.toString();
+ /**
+ * Strip protocol from url string.
+ *
+ * @param uri the uri
+ * @return uri's path string
+ */
+ public static String stripProtocol(URI uri)
+ {
+ List<String> tokens = stripProtocolToTokens(uri);
+ if (tokens.isEmpty() == false)
+ {
+ StringBuilder builder = new StringBuilder();
+ for (String token : tokens)
+ {
+ builder.append("/").append(token);
+ }
+ builder.append("/");
+ return builder.toString();
}
else
{
- path = "/";
+ return "/";
}
-
- return path;
}
/**
Modified: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/cache/PathMatchingVFSCache.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/cache/PathMatchingVFSCache.java 2009-09-16 13:20:28 UTC (rev 93607)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/cache/PathMatchingVFSCache.java 2009-09-16 13:25:33 UTC (rev 93608)
@@ -25,7 +25,6 @@
import java.util.List;
import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.plugins.vfs.helpers.PathTokenizer;
import org.jboss.virtual.spi.VFSContext;
/**
@@ -43,8 +42,7 @@
*/
public VFSContext findContext(URI uri)
{
- String uriString = VFSUtils.stripProtocol(uri);
- List<String> tokens = PathTokenizer.getTokens(uriString);
+ List<String> tokens = VFSUtils.stripProtocolToTokens(uri);
StringBuilder sb = new StringBuilder("/");
readLock();
try
Modified: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java 2009-09-16 13:20:28 UTC (rev 93607)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java 2009-09-16 13:25:33 UTC (rev 93608)
@@ -221,18 +221,15 @@
}
/**
- * Apply any . or .. paths in the path param.
+ * Handle special tokens.
*
+ * @param tokens the tokens
* @param path the path
- * @return simple path, containing no . or .. paths
- * @throws IOException if reverse path goes over the top path
+ * @return index of last token
+ * @throws IOException for any error
*/
- public static String applySpecialPaths(String path) throws IOException
+ protected static int applySpecialTokens(List<String> tokens, String path) throws IOException
{
- List<String> tokens = getTokens(path);
- if (tokens == null)
- return null;
-
int i = 0;
for(int j = 0; j < tokens.size(); j++)
{
@@ -248,10 +245,44 @@
if (i < 0)
throw new IOException("Using reverse path on top path: " + path);
}
- return getRemainingPath(tokens, 0, i);
+ return i;
}
/**
+ * Apply any . or .. paths in the path param.
+ *
+ * @param path the path
+ * @return simple path, containing no . or .. paths
+ * @throws IOException if reverse path goes over the top path
+ */
+ public static List<String> applySpecialPathsToTokens(String path) throws IOException
+ {
+ List<String> tokens = getTokens(path);
+ if (tokens == null)
+ return null;
+
+ int index = applySpecialTokens(tokens, path);
+ return tokens.subList(0, index);
+ }
+
+ /**
+ * Apply any . or .. paths in the path param.
+ *
+ * @param path the path
+ * @return simple path, containing no . or .. paths
+ * @throws IOException if reverse path goes over the top path
+ */
+ public static String applySpecialPaths(String path) throws IOException
+ {
+ List<String> tokens = getTokens(path);
+ if (tokens == null)
+ return null;
+
+ int index = applySpecialTokens(tokens, path);
+ return getRemainingPath(tokens, 0, index);
+ }
+
+ /**
* Is current token.
*
* @param token the token to check
Modified: projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java 2009-09-16 13:20:28 UTC (rev 93607)
+++ projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java 2009-09-16 13:25:33 UTC (rev 93608)
@@ -24,9 +24,11 @@
import java.io.IOException;
import java.net.URI;
import java.net.URL;
+import java.security.ProtectionDomain;
import java.util.Collections;
import java.util.Map;
+import org.jboss.util.Strings;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.plugins.context.jar.JarContextFactory;
@@ -246,6 +248,41 @@
}
}
+ public void testCanonicalPath() throws Exception
+ {
+ ProtectionDomain pd = getClass().getProtectionDomain();
+ URL url = pd.getCodeSource().getLocation();
+ String urlString = url.toExternalForm();
+ if (urlString.endsWith("/") == false)
+ urlString += "/";
+ String testDir = urlString + "vfs/../vfs/test/";
+ URL testURL = Strings.toURL(testDir);
+
+ VFSCache cache = createCache();
+ cache.start();
+ try
+ {
+ VFSCacheFactory.setInstance(cache);
+ try
+ {
+ configureCache(cache);
+
+ VirtualFile testVF = VFS.getRoot(testURL);
+ URL jar1URL = new URL(testDir + "jar1.jar/");
+ VirtualFile jar1VF = VFS.getRoot(jar1URL);
+ assertEquals(testVF, jar1VF.getParent()); // should find previous root
+ }
+ finally
+ {
+ VFSCacheFactory.setInstance(null);
+ }
+ }
+ finally
+ {
+ stopCache(cache);
+ }
+ }
+
private class WrapperVFSCache implements VFSCache
{
private VFSCache delegate;
More information about the jboss-cvs-commits
mailing list