Skip to content

Commit

Permalink
Expose vfszip bug - unable to re-create virtual file from nested jar …
Browse files Browse the repository at this point in the history
…url.
  • Loading branch information
alesj committed Jun 13, 2008
1 parent 0c85597 commit f84bfd7
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 24 deletions.
Expand Up @@ -145,9 +145,9 @@ public URL getChildURL(VirtualFileHandler parent, String name) throws IOExceptio
.append(":").append(rootUri.getPath());
if(parent != null)
{
String pPathName = null;
String pPathName;
if(parent instanceof AbstractVirtualFileHandler)
pPathName = ((AbstractVirtualFileHandler)parent).getLocalPathName();
pPathName = parent.getLocalPathName();
else
pPathName = parent.getPathName();

Expand Down
Expand Up @@ -65,7 +65,6 @@
*/
public class FileSystemContext extends AbstractVFSContext
{

private static final Logger log = Logger.getLogger(ZipEntryContext.class);

/** true if forcing fallback to vfsjar from default vfszip */
Expand Down
Expand Up @@ -196,7 +196,6 @@ public ZipEntryContext(URL rootURL, VirtualFileHandler peer, ZipWrapper zipWrapp
*/
private void init(URL localRootURL, VirtualFileHandler peer, ZipWrapper zipWrapper) throws IOException, URISyntaxException
{

if (zipWrapper == null)
{
if (localRootURL == null)
Expand Down Expand Up @@ -709,7 +708,8 @@ protected void finalize()
try
{
super.finalize();
zipSource.close();
if (zipSource != null)
zipSource.close();
}
catch (Throwable ignored)
{
Expand Down
Expand Up @@ -21,9 +21,6 @@
*/
package org.jboss.virtual.plugins.context.zip;

import org.jboss.virtual.plugins.context.AbstractContextFactory;
import org.jboss.virtual.spi.VFSContext;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
Expand All @@ -32,13 +29,15 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.jboss.virtual.plugins.context.AbstractContextFactory;
import org.jboss.virtual.spi.VFSContext;

/**
* ContextFactory that keeps track of ZipEntryContexts
*
* @author <a href="strukelj@parsek.net">Marko Strukelj</a>
* @version $Revision: 1.0 $
*/

public class ZipEntryContextFactory extends AbstractContextFactory
{
/** registry of all ZipEntryContext instances */
Expand Down Expand Up @@ -75,7 +74,6 @@ public VFSContext getVFS(URL rootURL) throws IOException

String longestMatchingKey = null;
ZipEntryContext longestMatchingCtx = null;

for(Map.Entry<String, ZipEntryContext> ent : ctxCache.entrySet())
{
if(key.startsWith(ent.getKey()))
Expand All @@ -87,29 +85,19 @@ public VFSContext getVFS(URL rootURL) throws IOException
}
}
}

ZipEntryContext ctx = null;
if(longestMatchingCtx != null)
ctx = longestMatchingCtx;

if(ctx != null)
return ctx;
return longestMatchingCtx;

try
{
ctx = new ZipEntryContext(rootURL);
return new ZipEntryContext(rootURL);
}
catch(URISyntaxException ex)
{
MalformedURLException e = new MalformedURLException("Failed to convert URL to URI: " + rootURL);
e.initCause(ex);
throw e;
}

// ZipEntryContext registers newly created context with this factory
// by calling registerContext() which puts a newly created context into ctxCache

return ctx;
}

public static ZipEntryContextFactory getInstance()
Expand Down
Expand Up @@ -121,6 +121,7 @@ public void testInnerJarFileSerialization() throws Exception
assertEquals("jar1", title1);
jar1DSMF.close();
}

/**
* JBVFS-17 test
* @throws Exception
Expand Down Expand Up @@ -156,7 +157,6 @@ public void testInnerJarFilesOnlyFileSerialization() throws Exception
jar1DSMF.close();
}

/*
public void testLevelZips() throws Exception
{
URL rootURL = getResource("/vfs/test");
Expand Down Expand Up @@ -203,7 +203,6 @@ public void testLevelZips() throws Exception
textThree = two.findChild("level3.zip/test3.txt");
testText(textThree);
}
*/

protected void testText(VirtualFile file) throws Exception
{
Expand Down
Expand Up @@ -161,4 +161,24 @@ public void testInnerJarFileEntryOpenStream() throws Exception
InputStream is = target.openStream();
assertFalse("input stream closed", is.read() == -1);
}

public void testInnerJarOverURL() throws Exception
{
URL url = getResource("/vfs/test/nested/" + getNestedName() + ".jar");
String urlString = url.toExternalForm();
URL vfsURL = new URL(getProtocol() + urlString.substring(4) + "/complex.jar");
InputStream is = vfsURL.openStream();
assertNotNull(is);
}

// we need to make sure this doesn't get touched before
protected String getNestedName()
{
return "nested";
}

protected String getProtocol()
{
return "vfsfile";
}
}
Expand Up @@ -26,6 +26,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.Map;

import junit.framework.Test;
import org.jboss.virtual.VFS;
Expand All @@ -43,6 +44,8 @@
*/
public class ZipEntryVFSContextUnitTestCase extends JARVFSContextUnitTestCase
{
private Map ctxCacheMap;

public ZipEntryVFSContextUnitTestCase(String name)
{
super(name);
Expand All @@ -55,6 +58,25 @@ public static Test suite()
return suite(ZipEntryVFSContextUnitTestCase.class);
}

/*
protected void setUp() throws Exception
{
super.setUp();
SecurityManager sm = System.getSecurityManager();
System.setSecurityManager(null);
try
{
Field field = ZipEntryContextFactory.class.getDeclaredField("ctxCache");
ctxCacheMap = (Map)field.get(ZipEntryContextFactory.getInstance());
}
finally
{
System.setSecurityManager(sm);
}
}
*/

protected VFSContext getVFSContext(String name) throws Exception
{
URL url = getResource("/vfs/context/jar/" + name + ".jar");
Expand Down Expand Up @@ -121,4 +143,15 @@ public void testNotAnArchive() throws Exception
handler = ctx.getRoot().getChild("notanarchive.jar");
assertTrue("is leaf", handler.isLeaf());
}

// we need to make sure this doesn't get touched before
protected String getNestedName()
{
return super.getNestedName() + "_copy";
}

protected String getProtocol()
{
return "vfszip";
}
}
Binary file added src/test/resources/vfs/test/nested/nested.jar
Binary file not shown.
Binary file not shown.

0 comments on commit f84bfd7

Please sign in to comment.