[jboss-cvs] JBossAS SVN: r74087 - in projects/vfs/trunk/src: main/java/org/jboss/virtual/plugins/context and 8 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 4 07:24:48 EDT 2008
Author: alesj
Date: 2008-06-04 07:24:48 -0400 (Wed, 04 Jun 2008)
New Revision: 74087
Modified:
projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/LinkHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryContents.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NoCopyNestedJarHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectoryHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/ByteArrayHandler.java
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/ZipEntryHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVirtualFileHandlerTest.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVirtualFileHandlerUnitTestCase.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVirtualFileHandlerUnitTestCase.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnpackTestCase.java
Log:
Add isNested to handler.
Add new util methods - explode, isNested.
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-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -46,11 +46,9 @@
import org.jboss.logging.Logger;
import org.jboss.util.StringPropertyReplacer;
import org.jboss.util.id.GUID;
+import org.jboss.virtual.plugins.context.file.FileHandler;
+import org.jboss.virtual.plugins.context.file.FileSystemContext;
import org.jboss.virtual.plugins.context.DelegatingHandler;
-import org.jboss.virtual.plugins.context.file.FileSystemContext;
-import org.jboss.virtual.plugins.context.jar.AbstractJarHandler;
-import org.jboss.virtual.plugins.context.jar.NestedJarHandler;
-import org.jboss.virtual.plugins.context.zip.ZipEntryHandler;
import org.jboss.virtual.spi.LinkInfo;
import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VirtualFileHandler;
@@ -491,7 +489,7 @@
}
/**
- * Unpack the artifact under file param.
+ * Unpack the nested artifact under file param.
*
* @param file the file to unpack
* @return unpacked file
@@ -500,22 +498,52 @@
*/
public static VirtualFile unpack(VirtualFile file) throws IOException, URISyntaxException
{
+ return createTemp(file, true);
+ }
+
+ /**
+ * Force explode.
+ * Explode archives or nested entries.
+ *
+ * @param file the file to explode
+ * @return exploded file
+ * @throws IOException for any io error
+ * @throws URISyntaxException for any uri error
+ */
+ public static VirtualFile explode(VirtualFile file) throws IOException, URISyntaxException
+ {
+ return createTemp(file, false);
+ }
+
+ /**
+ * Create temp.
+ *
+ * @param file the file to unpack/explode
+ * @param force should we force the creation
+ * @return temp file
+ * @throws IOException for any io error
+ * @throws URISyntaxException for any uri error
+ */
+ private static VirtualFile createTemp(VirtualFile file, boolean force) throws IOException, URISyntaxException
+ {
if (file == null)
throw new IllegalArgumentException("Null file");
if (file.isLeaf())
return file;
VirtualFileHandler handler = file.getHandler();
- // already unpacked
VirtualFileHandler unwrapped = handler;
- if (unwrapped instanceof DelegatingHandler)
- unwrapped = ((DelegatingHandler) unwrapped).getDelegate();
+ if (handler instanceof DelegatingHandler)
+ unwrapped = ((DelegatingHandler)handler).getDelegate();
- if (unwrapped instanceof ZipEntryHandler == false
- && (unwrapped instanceof NestedJarHandler || unwrapped instanceof AbstractJarHandler == false))
+ boolean ignoreTempCreation = false;
+ if (force)
+ ignoreTempCreation = (unwrapped.isNested() == false);
+
+ if (ignoreTempCreation || unwrapped instanceof FileHandler)
{
if (log.isTraceEnabled())
- log.trace("Should already be unpacked: " + file);
+ log.trace("Should already be unpacked/exploded: " + file);
return file;
}
@@ -617,4 +645,17 @@
}
}
}
+
+ /**
+ * Is file handle nested.
+ *
+ * @param file the file handle to check
+ * @return true if file/dir is nested otherwise false
+ * @throws IOException for any error
+ */
+ public static boolean isNestedFile(VirtualFile file) throws IOException
+ {
+ VirtualFileHandler handler = file.getHandler();
+ return handler.isNested();
+ }
}
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -212,7 +212,7 @@
if (len == 0)
return pathName;
else if (rootPathName.length() < pathName.length())
- return pathName.substring(rootPathName.length() + 1);
+ return pathName.substring(len + 1);
else
return "";
}
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -122,6 +122,11 @@
return delegate.isHidden();
}
+ public boolean isNested() throws IOException
+ {
+ return delegate.isNested();
+ }
+
public InputStream openStream() throws IOException
{
return delegate.openStream();
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileHandler.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileHandler.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -136,6 +136,11 @@
return getFile().isHidden();
}
+ public boolean isNested() throws IOException
+ {
+ return false;
+ }
+
public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
{
File parent = getFile();
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/LinkHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/LinkHandler.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/LinkHandler.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -98,6 +98,11 @@
{
return false;
}
+
+ public boolean isNested() throws IOException
+ {
+ return false;
+ }
}
/**
@@ -188,6 +193,11 @@
return false;
}
+ public boolean isNested() throws IOException
+ {
+ return false;
+ }
+
public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
{
return new ArrayList<VirtualFileHandler>(linkTargets.values());
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryContents.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryContents.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryContents.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -112,6 +112,11 @@
return false;
}
+ public boolean isNested() throws IOException
+ {
+ return true;
+ }
+
byte[] getContents()
{
return contents;
@@ -240,9 +245,16 @@
protected void internalReplaceChild(VirtualFileHandler original, VirtualFileHandler replacement)
{
- entryChildren.remove(original);
- entryChildren.add(replacement);
- entryMap.put(original.getName(), replacement);
+ if (isJar)
+ {
+ njar.internalReplaceChild(original, replacement);
+ }
+ else
+ {
+ entryChildren.remove(original);
+ entryChildren.add(replacement);
+ entryMap.put(original.getName(), replacement);
+ }
}
public String toString()
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -132,6 +132,11 @@
return false;
}
+ public boolean isNested() throws IOException
+ {
+ return true;
+ }
+
public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
{
checkClosed();
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarHandler.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarHandler.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -86,4 +86,9 @@
throw e;
}
}
+
+ public boolean isNested() throws IOException
+ {
+ return false;
+ }
}
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -200,6 +200,11 @@
return lastModified;
}
+ public boolean isNested() throws IOException
+ {
+ return true;
+ }
+
// Stream accessor
public InputStream openStream() throws IOException
{
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -169,6 +169,11 @@
return getEntry().getSize();
}
+ public boolean isNested() throws IOException
+ {
+ return false;
+ }
+
/**
* Overriden to return the raw tmp jar file stream
*/
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NoCopyNestedJarHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NoCopyNestedJarHandler.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NoCopyNestedJarHandler.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -113,6 +113,11 @@
return getEntry().getSize();
}
+ public boolean isNested() throws IOException
+ {
+ return true;
+ }
+
@Override
public InputStream openStream() throws IOException
{
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -137,6 +137,11 @@
return false;
}
+ public boolean isNested() throws IOException
+ {
+ return true;
+ }
+
@Override
public InputStream openStream() throws IOException
{
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextHandler.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextHandler.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -148,6 +148,11 @@
return cachedLastModified;
}
+ public boolean isNested() throws IOException
+ {
+ return false;
+ }
+
@Override
public InputStream openStream() throws IOException
{
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectoryHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectoryHandler.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectoryHandler.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -120,6 +120,11 @@
return false;
}
+ public boolean isNested() throws IOException
+ {
+ return false;
+ }
+
public InputStream openStream() throws IOException
{
throw new RuntimeException("Cannot open stream");
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/ByteArrayHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/ByteArrayHandler.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/ByteArrayHandler.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -35,7 +35,7 @@
import org.jboss.virtual.spi.VirtualFileHandler;
/**
- * comment
+ * ByteArrayHandler.
*
* @author <a href="bill at jboss.com">Bill Burke</a>
* @author <a href="ales.justin at jboss.com">Ales Justin</a>
@@ -91,6 +91,11 @@
return false;
}
+ public boolean isNested() throws IOException
+ {
+ return false;
+ }
+
public InputStream openStream() throws IOException
{
return new ByteArrayInputStream(bytes);
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-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -98,7 +98,6 @@
log.info("VFS force nested jars copy-mode is enabled.");
}
-
/** Abstracted access to zip archive - either ZipFileWrapper or ZipStreamWrapper */
private ZipWrapper zipSource;
@@ -111,13 +110,12 @@
/** Registry of everything that zipSource contains */
private ConcurrentHashMap<String, EntryInfo> entries = new ConcurrentHashMap<String, EntryInfo>();
-
/**
* Create a new ZipEntryContext
*
* @param rootURL - file or jar:file url
- * @throws URISyntaxException
- * @throws IOException
+ * @throws URISyntaxException for any URI error
+ * @throws java.io.IOException for any error
*/
public ZipEntryContext(URL rootURL) throws URISyntaxException, IOException
{
@@ -129,8 +127,8 @@
*
* @param rootURL - file or jar:file url
* @param autoClean - true if file represented by rootURL should be deleted after this context is closed
- * @throws URISyntaxException
- * @throws java.io.IOException
+ * @throws URISyntaxException for any URI error
+ * @throws java.io.IOException for any error
*/
public ZipEntryContext(URL rootURL, boolean autoClean) throws URISyntaxException, IOException
{
@@ -145,8 +143,8 @@
* @param rootURL - url representing this context within another context
* @param peer - file handler in another context through which this context is being mounted
* @param localRootUrl - file or jar:file url
- * @throws URISyntaxException
- * @throws java.io.IOException
+ * @throws URISyntaxException for any URI error
+ * @throws java.io.IOException for any error
*/
public ZipEntryContext(URL rootURL, VirtualFileHandler peer, URL localRootUrl) throws URISyntaxException, IOException
{
@@ -160,8 +158,8 @@
* @param peer - file handler in another context through which this context is being mounted
* @param localRootUrl - file or jar:file url
* @param autoClean - true if file represented by localRootURL should be deleted after this context is closed
- * @throws URISyntaxException
- * @throws IOException
+ * @throws URISyntaxException for any URI error
+ * @throws java.io.IOException for any error
*/
public ZipEntryContext(URL rootURL, VirtualFileHandler peer, URL localRootUrl, boolean autoClean) throws URISyntaxException, IOException
{
@@ -177,8 +175,8 @@
* @param peer - file handler in another context through which this context is being mounted
* @param zipWrapper - abstracted zip archive source
* @param autoClean - true if file represented by localRootURL should be deleted after this context is closed
- * @throws URISyntaxException
- * @throws IOException
+ * @throws URISyntaxException for any URI error
+ * @throws java.io.IOException for any error
*/
public ZipEntryContext(URL rootURL, VirtualFileHandler peer, ZipWrapper zipWrapper, boolean autoClean) throws URISyntaxException, IOException
{
@@ -190,11 +188,11 @@
/**
* Extra initialization that couldn't fit inside constructors
*
- * @param localRootURL
- * @param peer
- * @param zipWrapper
- * @throws IOException
- * @throws URISyntaxException
+ * @param localRootURL the local url
+ * @param peer the peer
+ * @param zipWrapper zip wrapper
+ * @throws URISyntaxException for any URI error
+ * @throws java.io.IOException for any error
*/
private void init(URL localRootURL, VirtualFileHandler peer, ZipWrapper zipWrapper) throws IOException, URISyntaxException
{
@@ -258,12 +256,11 @@
/**
* Iterate through zip archive entries, compose a tree structure of archive's content
*
- * @throws IOException
- * @throws URISyntaxException
+ * @throws URISyntaxException for any URI error
+ * @throws java.io.IOException for any error
*/
private synchronized void initEntries() throws IOException, URISyntaxException
{
-
// we're using a two phase approach - we first select the relevant ones
// then we order these by name and only then we process them
// this way we ensure that parent entries are processed before child entries
@@ -349,18 +346,17 @@
{
zipSource.release();
}
-
}
/**
* Mount ZipEntryContext created around extracted nested archive
*
- * @param parent
- * @param name
- * @param file
- * @return
- * @throws IOException
- * @throws URISyntaxException
+ * @param parent the parent
+ * @param name the name
+ * @param file the file
+ * @return mounted delegate
+ * @throws IOException for any error
+ * @throws URISyntaxException for any URI syntax error
*/
protected DelegatingHandler mountZipFile(VirtualFileHandler parent, String name, File file) throws IOException, URISyntaxException
{
@@ -381,12 +377,12 @@
/**
* Mount ZipEntryContext created around ZipStreamWrapper
*
- * @param parent
- * @param name
- * @param zipStream
- * @return
- * @throws IOException
- * @throws URISyntaxException
+ * @param parent the parent
+ * @param name the name
+ * @param zipStream the zip stream
+ * @return mounted delegate
+ * @throws IOException for any error
+ * @throws URISyntaxException for any URI syntax error
*/
protected DelegatingHandler mountZipStream(VirtualFileHandler parent, String name, InputStream zipStream) throws IOException, URISyntaxException
{
@@ -408,9 +404,9 @@
/**
* Zip archives sometimes don't contain directory entries - only leaf entries
*
- * @param parentPath
- * @return
- * @throws IOException
+ * @param parentPath the parent path
+ * @return entry info
+ * @throws IOException for any error
*/
private EntryInfo makeDummyParent(String parentPath) throws IOException
{
@@ -431,8 +427,8 @@
/**
* Initialize rootEntryPath and return archive file path
*
- * @param localRootUrl
- * @return
+ * @param localRootUrl local root url
+ * @return file path
*/
private String initRootAndPath(URL localRootUrl)
{
@@ -601,6 +597,66 @@
return !ei.entry.isDirectory();
}
+ /**
+ * Is archive.
+ *
+ * @param handler the handler
+ * @return true if archive
+ */
+ static boolean isArchive(VirtualFileHandler handler)
+ {
+ if (handler instanceof ZipEntryHandler && "".equals(handler.getLocalPathName()))
+ {
+ return true;
+ }
+
+ if (handler instanceof DelegatingHandler && ((DelegatingHandler) handler).getDelegate() instanceof ZipEntryHandler)
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Get parent.
+ *
+ * @param handler the handler to check
+ * @return parent handler
+ * @throws IOException for any error
+ */
+ static VirtualFileHandler getParent(VirtualFileHandler handler) throws IOException
+ {
+ VirtualFileHandler parent = handler.getParent();
+ if (parent == null)
+ {
+ VirtualFileHandler peer = handler.getVFSContext().getRootPeer();
+ if (peer != null)
+ parent = peer.getParent();
+ }
+ return parent;
+ }
+
+ /**
+ * Is nested.
+ *
+ * @param handler the handler
+ * @return true if nested
+ * @throws IOException for any error
+ */
+ static boolean isNested(VirtualFileHandler handler) throws IOException
+ {
+ VirtualFileHandler parent = getParent(handler);
+ while (parent != null)
+ {
+ if(isArchive(parent))
+ return true;
+
+ parent = getParent(parent);
+ }
+ return false;
+ }
+
public InputStream openStream(ZipEntryHandler handler) throws IOException
{
if (handler == null)
@@ -613,7 +669,7 @@
if (ei == null)
{
- String uriStr = "";
+ String uriStr;
try
{
uriStr = handler.toURI().toString();
@@ -623,7 +679,6 @@
throw new RuntimeException("ASSERTION ERROR - uri generation failed for ZipEntryHandler: " + handler, ex);
}
throw new FileNotFoundException(uriStr);
-
}
if(ei.entry == null)
@@ -652,8 +707,6 @@
throw new RuntimeException("Parent does not exist: " + parent);
}
-
-
protected void finalize()
{
try
@@ -667,7 +720,6 @@
}
}
-
public void replaceChild(ZipEntryHandler parent, AbstractVirtualFileHandler original, VirtualFileHandler replacement)
{
EntryInfo parentEntry = entries.get(parent.getLocalPathName());
@@ -681,8 +733,7 @@
}
else
{
- DelegatingHandler delegator = new DelegatingHandler(this, parent, original.getName(), replacement);
- newOne = delegator;
+ newOne = new DelegatingHandler(this, parent, original.getName(), replacement);
}
synchronized(this)
@@ -701,7 +752,6 @@
}
}
-
/**
* Internal data structure holding meta information of a virtual file in this context
*/
@@ -775,20 +825,16 @@
}
}
-
-
//
// Helper methods
//
-
-
/**
* Copy input stream to output stream and close them both
*
- * @param is
- * @param os
- * @throws IOException
+ * @param is input stream
+ * @param os output stream
+ * @throws IOException for any error
*/
static void copyStreamAndClose(InputStream is, OutputStream os) throws IOException
{
@@ -820,9 +866,9 @@
/**
* Make sure url protocol is <em>vfszip</em>
*
- * @param rootURL
- * @return
- * @throws MalformedURLException
+ * @param rootURL the root url
+ * @return fixed url
+ * @throws MalformedURLException for any error
*/
private static URL fixUrl(URL rootURL) throws MalformedURLException
{
@@ -841,8 +887,8 @@
/**
* Break to path + name
*
- * @param pathName
- * @return
+ * @param pathName the path name
+ * @return path tokens
*/
public static String [] splitParentChild(String pathName)
{
@@ -875,12 +921,11 @@
return ret;
}
-
/**
* Temporary files naming scheme
*
- * @param name
- * @return
+ * @param name the name
+ * @return random name
*/
private static String getTempFileName(String name)
{
@@ -893,7 +938,7 @@
/**
* Use VFS's temp directory and make 'vfs-nested' sub-directory inside it for our purposes
*
- * @return
+ * @return temp dir
*/
private static String getTempDir()
{
@@ -919,10 +964,8 @@
catch(Exception ignored)
{
}
-
}
-
private static class CheckForceCopy implements PrivilegedAction<Boolean>
{
public Boolean run()
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -21,36 +21,30 @@
*/
package org.jboss.virtual.plugins.context.zip;
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
-import org.jboss.virtual.plugins.context.StructuredVirtualFileHandler;
-import org.jboss.virtual.spi.VirtualFileHandler;
-
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
+import org.jboss.virtual.plugins.context.StructuredVirtualFileHandler;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
/**
* Handler representing an individual file (ZipEntry) within ZipEntryContext
*
* @author <a href="strukelj at parsek.net">Marko Strukelj</a>
* @version $Revision: 1.0 $
*/
-
public class ZipEntryHandler extends AbstractVirtualFileHandler implements StructuredVirtualFileHandler
{
-
/** The url */
private final URL url;
-
/**
* Create a new ZipEntryHandler.
*
@@ -58,6 +52,7 @@
* @param parent parent within the same context
* @param name name of this file within context
* @param isLeaf true if this file should have a URL not ending with '/', false otherwise
+ * @throws IOException for any error
*/
public ZipEntryHandler(ZipEntryContext context, AbstractVirtualFileHandler parent, String name, boolean isLeaf) throws IOException
{
@@ -118,6 +113,11 @@
return false;
}
+ public boolean isNested() throws IOException
+ {
+ return ZipEntryContext.isNested(this);
+ }
+
public InputStream openStream() throws IOException
{
checkClosed();
@@ -127,7 +127,6 @@
public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
{
return getZipEntryContext().getChildren(this, ignoreErrors);
-
}
public VirtualFileHandler getChild(String path) throws IOException
@@ -135,7 +134,6 @@
return structuredFindChild(path);
}
-
public VirtualFileHandler createChildHandler(String name) throws IOException
{
return getZipEntryContext().getChild(this, name);
@@ -153,6 +151,4 @@
{
return ((ZipEntryContext) getVFSContext());
}
-
-
}
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -56,6 +56,14 @@
String getPathName();
/**
+ * Get the VFS local path name.
+ * Relative to root.
+ *
+ * @return the VFS local path name
+ */
+ String getLocalPathName();
+
+ /**
* Get a VFS-based URL
*
* @return the url
@@ -201,4 +209,12 @@
* @param replacement the replacement
*/
void replaceChild(VirtualFileHandler original, VirtualFileHandler replacement);
+
+ /**
+ * Are we nested in some archive.
+ *
+ * @return true if this is archive entry
+ * @throws IOException for any error
+ */
+ boolean isNested() throws IOException;
}
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -68,7 +68,10 @@
/** Is a hidden */
private boolean hidden;
-
+
+ /** Is nested */
+ private boolean nested;
+
/** The stream */
private byte[] stream;
@@ -235,6 +238,16 @@
this.hidden = hidden;
}
+ public boolean isNested() throws IOException
+ {
+ return nested;
+ }
+
+ public void setNested(boolean nested)
+ {
+ this.nested = nested;
+ }
+
/**
* Set the stream.
*
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVirtualFileHandlerTest.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVirtualFileHandlerTest.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVirtualFileHandlerTest.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -576,6 +576,23 @@
}
}
+ public void testIsNested() throws Exception
+ {
+ VFSContext context = getVFSContext("complex");
+ VirtualFileHandler root = context.getRoot();
+ assertFalse(root.isNested());
+ VirtualFileHandler subfolder = context.getChild(root, "subfolder");
+ assertIsNested(subfolder);
+ VirtualFileHandler subchild = subfolder.getChild("subchild");
+ assertIsNested(subchild);
+ VirtualFileHandler subsubfolder = subfolder.getChild("subsubfolder");
+ assertIsNested(subsubfolder);
+ VirtualFileHandler subsubchild = subsubfolder.getChild("subsubchild");
+ assertIsNested(subsubchild);
+ }
+
+ protected abstract void assertIsNested(VirtualFileHandler handler) throws Exception;
+
protected void checkVirtualFile(VirtualFileHandler handler) throws Exception
{
VirtualFile file = handler.getVirtualFile();
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVirtualFileHandlerUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVirtualFileHandlerUnitTestCase.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVirtualFileHandlerUnitTestCase.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -29,6 +29,7 @@
import org.jboss.virtual.plugins.context.file.FileSystemContext;
import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.VirtualFileHandler;
/**
* FileVirtualFileHandlerUnitTestCase.
@@ -78,4 +79,10 @@
File file = getRealFile(name, path);
return file.length();
}
+
+ protected void assertIsNested(VirtualFileHandler handler) throws Exception
+ {
+ assertNotNull(handler);
+ assertFalse(handler.isNested());
+ }
}
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVirtualFileHandlerUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVirtualFileHandlerUnitTestCase.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVirtualFileHandlerUnitTestCase.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -32,6 +32,7 @@
import org.jboss.virtual.plugins.context.jar.JarContext;
import org.jboss.virtual.plugins.context.jar.JarUtils;
import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.VirtualFileHandler;
/**
* JARVirtualFileHandlerUnitTestCase.
@@ -113,4 +114,10 @@
return file.length();
}
}
+
+ protected void assertIsNested(VirtualFileHandler handler) throws Exception
+ {
+ assertNotNull(handler);
+ assertTrue(handler.toString(), handler.isNested());
+ }
}
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnpackTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnpackTestCase.java 2008-06-04 10:36:55 UTC (rev 74086)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnpackTestCase.java 2008-06-04 11:24:48 UTC (rev 74087)
@@ -21,11 +21,10 @@
*/
package org.jboss.test.virtual.test;
-import java.net.URL;
-import java.io.InputStream;
import java.io.BufferedReader;
+import java.io.InputStream;
import java.io.InputStreamReader;
-import java.io.IOException;
+import java.net.URL;
import junit.framework.Test;
import org.jboss.virtual.VFS;
@@ -91,7 +90,7 @@
VirtualFile replacement;
original = vfs.findChild("level1.zip");
- replacement = VFSUtils.unpack(original);
+ replacement = VFSUtils.explode(original);
assertReplacement(original, replacement);
VirtualFile parent = original.getParent();
VirtualFile child = parent.findChild("level1.zip");
More information about the jboss-cvs-commits
mailing list