[jboss-cvs] JBossAS SVN: r74009 - in projects/vfs/trunk/src: main/java/org/jboss/virtual/plugins/context/zip and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 3 14:51:49 EDT 2008
Author: mstruk
Date: 2008-06-03 14:51:49 -0400 (Tue, 03 Jun 2008)
New Revision: 74009
Added:
projects/vfs/trunk/src/test/resources/vfs/context/jar/notanarchive.jar
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/zip/ZipEntryContext.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java
Log:
Fixed two unreported bugs that popped-up, and added unit tests to detect them in the future
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-03 17:18:26 UTC (rev 74008)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java 2008-06-03 18:51:49 UTC (rev 74009)
@@ -215,7 +215,14 @@
{
if (forceVfsJar)
{
- return new JarHandler(this, parent, file, file.toURL(), name);
+ try
+ {
+ return new JarHandler(this, parent, file, file.toURL(), name);
+ }
+ catch(IOException e)
+ {
+ log.debug("Exception while trying to handle file (" + name + ") as a jar: " + e.getMessage());
+ }
}
else
{
@@ -225,9 +232,7 @@
}
catch (Exception e)
{
- IOException ex = new IOException("Exception while trying to handle file (" + name + ") through ZipEntryContext: ");
- ex.initCause(e);
- throw ex;
+ log.debug("IGNORING: Exception while trying to handle file (" + name + ") as a jar through ZipEntryContext: ", e);
}
}
}
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2008-06-03 17:18:26 UTC (rev 74008)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2008-06-03 18:51:49 UTC (rev 74009)
@@ -30,6 +30,7 @@
import org.jboss.virtual.spi.VirtualFileHandler;
import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -607,8 +608,10 @@
throw new IllegalArgumentException("Null handler");
checkIfModified();
- EntryInfo ei = entries.get(handler.getLocalPathName());
+ String localPathName = handler.getLocalPathName();
+ EntryInfo ei = entries.get(localPathName);
+
if (ei == null)
{
String uriStr = "";
@@ -626,7 +629,10 @@
if(ei.entry == null)
{
- return zipSource.getRootAsStream();
+ if ("".equals(localPathName)) // root
+ return zipSource.getRootAsStream();
+ else // directory
+ return new ByteArrayInputStream(new byte[0]);
}
return zipSource.openStream(ei.entry);
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java 2008-06-03 17:18:26 UTC (rev 74008)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java 2008-06-03 18:51:49 UTC (rev 74009)
@@ -26,7 +26,9 @@
import org.jboss.virtual.VFS;
import org.jboss.virtual.plugins.context.jar.JarUtils;
import org.jboss.virtual.plugins.context.zip.ZipEntryContext;
+import org.jboss.virtual.plugins.context.file.FileSystemContext;
import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.VirtualFileHandler;
import java.io.File;
import java.io.FileOutputStream;
@@ -138,4 +140,41 @@
assertFalse("context.getRoot().exists()", context.getRoot().exists());
}
+
+ /**
+ * Test for proper handling when file appears to be an archive but
+ * trying to handle it produces an exception. Proper behaviour
+ * is to ignore exception and treat the file as non-archive.
+ *
+ * @throws Exception
+ */
+ public void testNotAnArchive() throws Exception
+ {
+ URL url = getResource("/vfs/context/jar/");
+ FileSystemContext ctx = new FileSystemContext(url);
+
+ // check that vfszip is active
+ VirtualFileHandler handler = ctx.getRoot().getChild("archive.jar");
+ assertTrue("is vfszip", "vfszip".equals(handler.toURL().getProtocol()));
+ assertFalse("is leaf", handler.isLeaf());
+
+ handler = ctx.getRoot().getChild("notanarchive.jar");
+ assertTrue("is leaf", handler.isLeaf());
+ }
+
+ /**
+ * Handler representing a directory must return a zero leangth stream
+ *
+ * @throws Exception
+ */
+ public void testDirectoryZipEntryOpenStream() throws Exception
+ {
+ URL url = getResource("/vfs/context/jar/complex.jar");
+ ZipEntryContext ctx = new ZipEntryContext(url);
+
+ VirtualFileHandler sub = ctx.getRoot().getChild("subfolder");
+ InputStream is = sub.openStream();
+ assertTrue("input stream closed", is.read() == -1);
+ }
+
}
\ No newline at end of file
Added: projects/vfs/trunk/src/test/resources/vfs/context/jar/notanarchive.jar
===================================================================
--- projects/vfs/trunk/src/test/resources/vfs/context/jar/notanarchive.jar (rev 0)
+++ projects/vfs/trunk/src/test/resources/vfs/context/jar/notanarchive.jar 2008-06-03 18:51:49 UTC (rev 74009)
@@ -0,0 +1 @@
+empty
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list