[jboss-cvs] JBossAS SVN: r74363 - in projects/vfs/trunk/src: main/java/org/jboss/virtual/plugins/context/file and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 10 19:26:10 EDT 2008
Author: mstruk
Date: 2008-06-10 19:26:10 -0400 (Tue, 10 Jun 2008)
New Revision: 74363
Modified:
projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
Log:
JBVFS-11 case sensitive path checking
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java 2008-06-10 22:12:30 UTC (rev 74362)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java 2008-06-10 23:26:10 UTC (rev 74363)
@@ -84,6 +84,12 @@
public static final String NO_REAPER_QUERY = "noReaper";
/**
+ * Key used to force case sensitive path checking in vfsfile
+ */
+ public static final String FORCE_CASE_SENSITIVE_KEY = "jboss.vfs.forceCaseSensitive";
+ public static final String CASE_SENSITIVE_QUERY = "caseSensitive";
+
+ /**
* Get the paths string for a collection of virtual files
*
* @param paths the paths
@@ -534,31 +540,4 @@
VirtualFileHandler handler = file.getHandler();
return handler.isNested();
}
-
- /**
- * Get spec compatilbe url from virtual file.
- *
- * @param file the virtual file
- * @return spec compatible url
- * @throws IOException for any error
- * @throws URISyntaxException for any uri syntax error
- */
- public static URL getCompatibleURL(VirtualFile file) throws IOException, URISyntaxException
- {
- URL url = file.toURL();
- // is not nested, so direct VFS URL is not an option
- if (isNestedFile(file) == false)
- {
- String urlString = url.toExternalForm();
- if (urlString.startsWith("vfs"))
- {
- // treat vfszip as file
- if (urlString.startsWith("vfszip"))
- url = new URL("file" + urlString.substring(6));
- else
- url = new URL(urlString.substring(3)); // (vfs)file and (vfs)jar are ok
- }
- }
- return url;
- }
}
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java 2008-06-10 22:12:30 UTC (rev 74362)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java 2008-06-10 23:26:10 UTC (rev 74363)
@@ -49,7 +49,14 @@
* Jar archives are processed through {@link org.jboss.virtual.plugins.context.zip.ZipEntryContext}.
*
* To switch back to {@link org.jboss.virtual.plugins.context.jar.JarHandler}
- * set a system property <em>jboss.vfs.forceVfsJar=true</em>
+ * set a system property <em>jboss.vfs.forceVfsJar=true</em>
+ *
+ * Explicit case sensitive path checking can be turned on by adding an option parameter
+ * <em>?caseSensitive=true<em> to context URL. This may be desired when native filesystem is not
+ * case sensitive (i.e. if running on Windows).
+ *
+ * Case sesitivity can be turned on for all context URLs by setting system property
+ * <em>jboss.vfs.forceCaseSensitive=true</em>.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @author <a href="ales.justin at jboss.com">Ales Justin</a>
@@ -64,12 +71,20 @@
/** true if forcing fallback to vfsjar from default vfszip */
private static boolean forceVfsJar;
+ /** true if case sensitivity should be enforced */
+ private static boolean forceCaseSensitive;
+
static
{
forceVfsJar = AccessController.doPrivileged(new CheckForceVfsJar());
if (forceVfsJar)
log.warn("VFS forced fallback to vfsjar is enabled.");
+
+ forceCaseSensitive = AccessController.doPrivileged(new CheckForceCaseSensitive());
+
+ if (forceCaseSensitive)
+ log.debug("VFS forced case sensitivity is enabled.");
}
/** The root file */
@@ -213,6 +228,9 @@
String name = file.getName();
if (file.isFile() && JarUtils.isArchive(name))
{
+ if (exists(file) == false)
+ return null;
+
if (forceVfsJar)
{
try
@@ -313,7 +331,7 @@
}
}
}
- else if (file.exists() == false && parent != null)
+ else if (exists(file) == false && parent != null)
{
// See if we can resolve this to a link in the parent
List<VirtualFileHandler> children = parent.getChildren(true);
@@ -326,13 +344,48 @@
}
}
}
- else if (file.exists())
+ else if (exists(file))
{
handler = new FileHandler(this, parent, file, uri);
}
return handler;
}
-
+
+ /**
+ * Tests if file exists taking case sensitivity into account - if it's enabled
+ *
+ * @param file file to check
+ * @return true if file exists
+ * @throws IOException
+ */
+ protected boolean exists(File file) throws IOException
+ {
+ // if force case sensitive is enabled - extra check is required
+ boolean isCaseSensitive = forceCaseSensitive;
+ if (isCaseSensitive == false)
+ {
+ String flag = getOptions().get(VFSUtils.CASE_SENSITIVE_QUERY);
+ isCaseSensitive = Boolean.valueOf(flag);
+ }
+
+ if (isCaseSensitive && file.getCanonicalFile().getName().equals(file.getName()) == false)
+ return false;
+
+ return file.exists();
+ }
+
+ /**
+ * Is forceCaseSensitive enabled
+ *
+ * Only relevant for native filesystems
+ * that are not case sensitive
+ *
+ * @return true if case sensitivity is enabled
+ */
+ public boolean isForcedCaseSensitive() {
+ return forceCaseSensitive;
+ }
+
@Override
protected void finalize() throws Throwable
{
@@ -349,4 +402,13 @@
return Boolean.valueOf(forceString);
}
}
+
+ private static class CheckForceCaseSensitive implements PrivilegedAction<Boolean>
+ {
+ public Boolean run()
+ {
+ String forceString = System.getProperty(VFSUtils.FORCE_CASE_SENSITIVE_KEY, "false");
+ return Boolean.valueOf(forceString);
+ }
+ }
}
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java 2008-06-10 22:12:30 UTC (rev 74362)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java 2008-06-10 23:26:10 UTC (rev 74363)
@@ -50,6 +50,7 @@
import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.VisitorAttributes;
+import org.jboss.virtual.plugins.context.file.FileSystemContext;
import org.jboss.virtual.plugins.context.jar.NestedJarFromStream;
import org.jboss.virtual.plugins.vfs.helpers.SuffixMatchFilter;
import org.jboss.virtual.spi.LinkInfo;
@@ -1438,4 +1439,50 @@
assertFalse(tmpVF.getPathName()+".exists()", tmpVF.exists());
assertTrue(tmpRoot+".delete()", tmpRoot.delete());
}
+
+ /**
+ * Test for <em>caseSensitive=true</em>
+ *
+ * If this test passes on unixes, it doesn't mean much, because there it should pass without
+ * case sensitivity turned on as well.
+ *
+ * If it passes on windows, it means the functionality works as expected.
+ *
+ * @throws Exception for any error
+ */
+ public void testCaseSensitive() throws Exception
+ {
+ URL rootURL = getResource("/vfs");
+
+ FileSystemContext ctx = new FileSystemContext(new URL(rootURL.toString() + "?caseSensitive=true"));
+ VirtualFileHandler root = ctx.getRoot();
+
+ String path = "context/file/simple/child";
+ VirtualFileHandler child = root.getChild(path);
+ assertTrue("getChild('" + path + "')", child != null);
+
+ path = "context/file/simple/CHILD";
+ child = root.getChild(path);
+ assertTrue("getChild('" + path + "')", child == null);
+
+ path = "context/jar/archive.jar";
+ child = root.getChild(path);
+ assertTrue("getChild('" + path + "')", child != null);
+
+ path = "context/JAR/archive.jar";
+ child = root.getChild(path);
+ assertTrue("getChild('" + path + "')", child == null);
+
+ path = "context/jar/archive.JAR";
+ child = root.getChild(path);
+ assertTrue("getChild('" + path + "')", child == null);
+
+ path = "context/jar/archive.jar/child";
+ child = root.getChild(path);
+ assertTrue("getChild('" + path + "')", child != null);
+
+ path = "context/jar/archive.jar/CHILD";
+ child = root.getChild(path);
+ assertTrue("getChild('" + path + "')", child == null);
+ }
}
More information about the jboss-cvs-commits
mailing list