[jboss-cvs] JBossAS SVN: r83457 - in projects/vfs/branches/Branch_2_0/src: main/java/org/jboss/virtual/plugins/cache and 8 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jan 27 05:42:03 EST 2009
Author: alesj
Date: 2009-01-27 05:42:02 -0500 (Tue, 27 Jan 2009)
New Revision: 83457
Added:
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/CombinedVFSCache.java
projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java
projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java
Modified:
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/VFS.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/VFSUtils.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/VirtualFile.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/file/FileHandler.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInputStream.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/ExplodedCopyMechanism.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/UnpackCopyMechanism.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java
projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java
projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/CopyTest.java
projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/DetachedCopyTest.java
projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java
projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/UnpackTestCase.java
projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java
Log:
Merge with trunk; cache fixes, temp cleanup, deprecate some VFS methods.
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/VFS.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/VFS.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/VFS.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -27,13 +27,13 @@
import java.util.List;
import org.jboss.virtual.plugins.vfs.helpers.WrappingVirtualFileHandlerVisitor;
+import org.jboss.virtual.spi.ExceptionHandler;
import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VFSContextFactory;
import org.jboss.virtual.spi.VFSContextFactoryLocator;
import org.jboss.virtual.spi.VirtualFileHandler;
-import org.jboss.virtual.spi.ExceptionHandler;
+import org.jboss.virtual.spi.cache.VFSCache;
import org.jboss.virtual.spi.cache.VFSCacheFactory;
-import org.jboss.virtual.spi.cache.VFSCache;
/**
* Virtual File System
@@ -115,6 +115,31 @@
}
/**
+ * Cleanup any resources tied to this file.
+ * e.g. vfs cache
+ *
+ * @param file the file
+ */
+ static void cleanup(VirtualFile file)
+ {
+ try
+ {
+ VirtualFileHandler fileHandler = file.getHandler();
+ VFSContext context = fileHandler.getVFSContext();
+ VirtualFileHandler contextHandler = context.getRoot();
+ // the file is the context root, hence possible cache candidate
+ if (fileHandler.equals(contextHandler))
+ {
+ VFSCache cache = VFSCacheFactory.getInstance();
+ cache.removeContext(context);
+ }
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+
+ /**
* Get the virtual file system for a root uri
*
* @param rootURI the root URI
@@ -133,6 +158,20 @@
}
/**
+ * Create new root
+ *
+ * @param rootURI the root url
+ * @return the virtual file
+ * @throws IOException if there is a problem accessing the VFS
+ * @throws IllegalArgumentException if the rootURL
+ */
+ public static VirtualFile createNewRoot(URI rootURI) throws IOException
+ {
+ VFS vfs = getVFS(rootURI);
+ return vfs.getRoot();
+ }
+
+ /**
* Get the root virtual file
*
* @param rootURI the root uri
@@ -142,8 +181,9 @@
*/
public static VirtualFile getRoot(URI rootURI) throws IOException
{
- VFS vfs = getVFS(rootURI);
- return vfs.getRoot();
+ VFSCache cache = VFSCacheFactory.getInstance();
+ VirtualFile file = cache.getFile(rootURI);
+ return (file != null) ? file : createNewRoot(rootURI);
}
/**
@@ -157,12 +197,12 @@
* @return the cached virtual file
* @throws IOException for any error
* @throws IllegalArgumentException if the rootURL is null
+ * @deprecated use getRoot
*/
+ @Deprecated
public static VirtualFile getCachedFile(URI rootURI) throws IOException
{
- VFSCache cache = VFSCacheFactory.getInstance();
- VirtualFile file = cache.getFile(rootURI);
- return (file != null) ? file : getRoot(rootURI);
+ return getRoot(rootURI);
}
/**
@@ -177,8 +217,8 @@
@SuppressWarnings("deprecation")
public static VirtualFile getVirtualFile(URI rootURI, String name) throws IOException
{
- VFS vfs = getVFS(rootURI);
- return vfs.findChild(name);
+ VirtualFile root = getRoot(rootURI);
+ return root.findChild(name);
}
/**
@@ -200,20 +240,35 @@
}
/**
- * Get the root virtual file
+ * Create new root
*
* @param rootURL the root url
* @return the virtual file
* @throws IOException if there is a problem accessing the VFS
* @throws IllegalArgumentException if the rootURL
*/
- public static VirtualFile getRoot(URL rootURL) throws IOException
+ public static VirtualFile createNewRoot(URL rootURL) throws IOException
{
VFS vfs = getVFS(rootURL);
return vfs.getRoot();
}
/**
+ * Get the root virtual file
+ *
+ * @param rootURL the root url
+ * @return the virtual file
+ * @throws IOException if there is a problem accessing the VFS
+ * @throws IllegalArgumentException if the rootURL
+ */
+ public static VirtualFile getRoot(URL rootURL) throws IOException
+ {
+ VFSCache cache = VFSCacheFactory.getInstance();
+ VirtualFile file = cache.getFile(rootURL);
+ return (file != null) ? file : createNewRoot(rootURL);
+ }
+
+ /**
* Get cached file.
*
* If VFSContext matching the rootURL parameter is cached
@@ -224,12 +279,12 @@
* @return the cached virtual file
* @throws IOException for any error
* @throws IllegalArgumentException if the rootURL is null
+ * @deprecated use getRoot
*/
+ @Deprecated
public static VirtualFile getCachedFile(URL rootURL) throws IOException
{
- VFSCache cache = VFSCacheFactory.getInstance();
- VirtualFile file = cache.getFile(rootURL);
- return (file != null) ? file : getRoot(rootURL);
+ return getRoot(rootURL);
}
/**
@@ -244,8 +299,8 @@
@SuppressWarnings("deprecation")
public static VirtualFile getVirtualFile(URL rootURL, String name) throws IOException
{
- VFS vfs = getVFS(rootURL);
- return vfs.findChild(name);
+ VirtualFile root = getRoot(rootURL);
+ return root.findChild(name);
}
/**
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/VFSUtils.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/VFSUtils.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -118,7 +118,10 @@
/** Standard separator for JAR URL */
public static final String JAR_URL_SEPARATOR = "!/";
-
+
+ /** The temp marker flag */
+ public static final String IS_TEMP_FILE = "IS_TEMP_FILE";
+
/**
* Stop cache.
*/
@@ -771,6 +774,17 @@
}
/**
+ * Is the virtual file temporary.
+ *
+ * @param file the file
+ * @return true if temporary, false otherwise
+ */
+ public static boolean isTemporaryFile(VirtualFile file)
+ {
+ return Boolean.valueOf(getOption(file, IS_TEMP_FILE));
+ }
+
+ /**
* Unpack the nested artifact under file param.
*
* @param file the file to unpack
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/VirtualFile.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/VirtualFile.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/VirtualFile.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -263,6 +263,22 @@
}
/**
+ * Do file cleanup.
+ * e.g. delete temp files
+ */
+ public void cleanup()
+ {
+ try
+ {
+ getHandler().cleanup();
+ }
+ finally
+ {
+ VFS.cleanup(this);
+ }
+ }
+
+ /**
* Close the file resources (stream, etc.)
*/
public void close()
Added: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/CombinedVFSCache.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/CombinedVFSCache.java (rev 0)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/cache/CombinedVFSCache.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -0,0 +1,241 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.virtual.plugins.cache;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.ExceptionHandler;
+import org.jboss.virtual.spi.cache.CacheStatistics;
+import org.jboss.virtual.spi.cache.VFSCache;
+import org.jboss.virtual.spi.cache.helpers.NoopVFSCache;
+
+/**
+ * Combined vfs cache - permanent entries + real cache.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class CombinedVFSCache implements VFSCache, CacheStatistics
+{
+ private PermanentVFSCache permanentCache = new PermanentVFSCache();
+ private VFSCache realCache;
+ private boolean initializing;
+
+ /**
+ * Set permanent roots and its exception handlers.
+ *
+ * @param initializationEntries the initialization entries
+ * @throws IOException for any error
+ */
+ public void setPermanentRoots(Map<URL, ExceptionHandler> initializationEntries) throws Exception
+ {
+ if (initializationEntries != null && initializationEntries.isEmpty() == false)
+ {
+ if (permanentCache.isStarted() == false)
+ permanentCache.start();
+
+ initializing = true;
+ try
+ {
+ for (Map.Entry<URL, ExceptionHandler> entry : initializationEntries.entrySet())
+ {
+ VFS vfs = VFS.getVFS(entry.getKey());
+ ExceptionHandler eh = entry.getValue();
+ if (eh != null)
+ vfs.setExceptionHandler(eh);
+ }
+ }
+ finally
+ {
+ initializing = false;
+ }
+ }
+ }
+
+ /**
+ * Set the real cache.
+ *
+ * @param realCache the real cache
+ */
+ public void setRealCache(VFSCache realCache)
+ {
+ this.realCache = realCache;
+ }
+
+ /**
+ * Check at create.
+ */
+ public void create()
+ {
+ check();
+ }
+
+ /**
+ * Check if real cache has been set.
+ */
+ private void check()
+ {
+ if (realCache == null)
+ realCache = new NoopVFSCache();
+ }
+
+ public VirtualFile getFile(URI uri) throws IOException
+ {
+ VirtualFile file = permanentCache.getFile(uri);
+ if (file != null)
+ return file;
+
+ check();
+ return realCache.getFile(uri);
+ }
+
+ public VirtualFile getFile(URL url) throws IOException
+ {
+ try
+ {
+ return getFile(url.toURI());
+ }
+ catch (URISyntaxException e)
+ {
+ IOException ioe = new IOException();
+ ioe.initCause(e);
+ throw ioe;
+ }
+ }
+
+ public void putContext(VFSContext context)
+ {
+ if (initializing)
+ {
+ permanentCache.putContext(context);
+ }
+ else
+ {
+ check();
+ realCache.putContext(context);
+ }
+ }
+
+ public void removeContext(VFSContext context)
+ {
+ check();
+ realCache.removeContext(context);
+ }
+
+ public void start() throws Exception
+ {
+ if (permanentCache.isStarted() == false)
+ permanentCache.start();
+ }
+
+ public void stop()
+ {
+ if (permanentCache.isStarted())
+ permanentCache.stop();
+ }
+
+ public void flush()
+ {
+ check();
+ realCache.flush();
+ }
+
+ public Iterable<VFSContext> getCachedContexts()
+ {
+ List<VFSContext> contexts = new ArrayList<VFSContext>();
+
+ for (VFSContext context : permanentCache.getCachedContexts())
+ contexts.add(context);
+
+ if (realCache instanceof CacheStatistics)
+ {
+ CacheStatistics cs = CacheStatistics.class.cast(realCache);
+ for (VFSContext context : cs.getCachedContexts())
+ contexts.add(context);
+ }
+
+ return contexts;
+ }
+
+ public int size()
+ {
+ int size = permanentCache.size();
+ if (realCache instanceof CacheStatistics)
+ {
+ size += CacheStatistics.class.cast(realCache).size();
+ }
+ return size;
+ }
+
+ public long lastInsert()
+ {
+ long permanentHit = permanentCache.lastInsert();
+ long realHit = -1;
+ if (realCache instanceof CacheStatistics)
+ {
+ realHit = CacheStatistics.class.cast(realCache).lastInsert();
+ }
+ return permanentHit > realHit ? permanentHit : realHit;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "CombinedVFSCache[real-cache: " + realCache + "]";
+ }
+
+ private class PermanentVFSCache extends MapVFSCache
+ {
+ private boolean started;
+
+ protected Map<String, VFSContext> createMap()
+ {
+ return new TreeMap<String, VFSContext>();
+ }
+
+ @Override
+ public void start() throws Exception
+ {
+ super.start();
+ started = true;
+ }
+
+ /**
+ * Is the cache started.
+ *
+ * @return the started flag
+ */
+ public boolean isStarted()
+ {
+ return started;
+ }
+ }
+}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -32,6 +32,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.jboss.logging.Logger;
@@ -179,8 +180,6 @@
{
boolean hasBeenModified = false;
long last = getLastModified();
- if(log.isTraceEnabled())
- log.trace("hasBeenModified, lastModified: "+last+", cachedLastModified: "+cachedLastModified);
if (cachedLastModified != last)
{
hasBeenModified = cachedLastModified != 0;
@@ -213,7 +212,7 @@
/**
* todo This is a hack until we can fix http://jira.jboss.com/jira/browse/JBMICROCONT-164
*
- * @param path
+ * @param path the path name
*/
public void setPathName(String path)
{
@@ -313,7 +312,12 @@
return false;
}
-
+ /**
+ * Initialise the peer path.
+ *
+ * @param pathName the path name
+ * @return whether it added anything
+ */
private boolean initPeerPath(StringBuilder pathName)
{
VirtualFileHandler grandParent = null;
@@ -332,11 +336,10 @@
}
}
- VirtualFileHandler peer = context.getRootPeer();
-
-
if (grandParent == null)
{
+ VirtualFileHandler peer = context.getRootPeer();
+
// bypass parent and delegate straight to peer
if (peer instanceof AbstractVirtualFileHandler)
@@ -384,8 +387,8 @@
{
if (context instanceof AbstractVFSContext)
{
- AbstractVFSContext avfs = (AbstractVFSContext) context;
- VirtualFileHandler peer = avfs.getRootPeer();
+ AbstractVFSContext avfc = (AbstractVFSContext) context;
+ VirtualFileHandler peer = avfc.getRootPeer();
if (peer != null)
return peer.getParent();
}
@@ -451,13 +454,45 @@
if (references.get() < 0)
throw new IllegalStateException("Closed " + toStringLocal());
}
+
+ /**
+ * Get the references count.
+ *
+ * @return the ref count
+ */
+ protected int getReferences()
+ {
+ return references.get();
+ }
+
+ public void cleanup()
+ {
+ }
- public void close()
+ /**
+ * Is the handler temporary.
+ *
+ * @return true if temporary, false otherwise
+ */
+ protected boolean isTemporary()
{
- if (decrement() == 0)
- doClose();
+ Map<String, String> options = getVFSContext().getOptions();
+ return (options != null && Boolean.valueOf(options.get(VFSUtils.IS_TEMP_FILE)));
}
+ public void close()
+ {
+ try
+ {
+ if (getReferences() == 1)
+ doClose();
+ }
+ finally
+ {
+ references.decrementAndGet();
+ }
+ }
+
/**
* The real close
*/
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -150,6 +150,36 @@
return getDelegate().isNested();
}
+ @Override
+ public void cleanup()
+ {
+ getDelegate().cleanup();
+ }
+
+ @Override
+ public void close()
+ {
+ if (delegate == null)
+ return;
+
+ try
+ {
+ if ((delegate instanceof AbstractVirtualFileHandler) && getReferences() == 1)
+ {
+ AbstractVirtualFileHandler avfh = AbstractVirtualFileHandler.class.cast(delegate);
+ avfh.doClose();
+ }
+ else
+ {
+ delegate.close();
+ }
+ }
+ finally
+ {
+ decrement();
+ }
+ }
+
public boolean delete(int gracePeriod) throws IOException
{
return getDelegate().delete(gracePeriod);
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/file/FileHandler.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/file/FileHandler.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/file/FileHandler.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -161,9 +161,25 @@
return false;
}
+ @Override
+ public void cleanup()
+ {
+ if (isTemporary())
+ {
+ try
+ {
+ delete(2000);
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+
public boolean delete(int gracePeriod) throws IOException
{
- File f = getFile();
+ // we can bypass the checkClosed
+ File f = file;
boolean exists = f.exists();
if (exists == false)
@@ -335,7 +351,7 @@
public boolean removeChild(String name) throws IOException
{
- return childCache.remove(name) != null;
+ return (childCache.remove(name) != null);
}
protected void internalReplaceChild(VirtualFileHandler original, VirtualFileHandler replacement)
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -32,16 +32,15 @@
import java.util.List;
import java.util.Properties;
+import org.jboss.logging.Logger;
import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.plugins.context.AbstractVFSContext;
import org.jboss.virtual.plugins.context.DelegatingHandler;
-import org.jboss.virtual.plugins.context.zip.ZipEntryContext;
import org.jboss.virtual.plugins.context.jar.JarHandler;
import org.jboss.virtual.plugins.context.jar.JarUtils;
+import org.jboss.virtual.plugins.context.zip.ZipEntryContext;
import org.jboss.virtual.spi.LinkInfo;
import org.jboss.virtual.spi.VirtualFileHandler;
-import org.jboss.logging.Logger;
/**
* FileSystemContext.
@@ -91,10 +90,7 @@
/** The root file */
private VirtualFileHandler root;
-
- /** A reference to the virtual file of the root to stop it getting closed */
- private VirtualFile rootFile;
-
+
/**
* Get the file for a url
*
@@ -213,7 +209,6 @@
throw new java.io.FileNotFoundException((file == null ? "<null>" : file.getName())
+ " doesn't exist. (rootURI: " + getRootURI() + ", file: " + file + ")");
- rootFile = root.getVirtualFile();
file = null; // nullify temp file
}
return root;
@@ -409,18 +404,11 @@
*
* @return true if case sensitivity is enabled
*/
- public boolean isForcedCaseSensitive() {
+ public boolean isForcedCaseSensitive()
+ {
return forceCaseSensitive;
}
- @Override
- protected void finalize() throws Throwable
- {
- if (rootFile != null)
- rootFile.close();
- super.finalize();
- }
-
private static class CheckForceVfsJar implements PrivilegedAction<Boolean>
{
public Boolean run()
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -188,12 +188,31 @@
return false;
}
+ @Override
+ public void cleanup()
+ {
+ try
+ {
+ delete(2000);
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+
public boolean delete(int gracePeriod) throws IOException
{
- boolean deleted = temp.delete();
- if (deleted)
- return super.delete(gracePeriod);
- return deleted;
+ if (temp != null)
+ {
+ boolean deleted = temp.delete();
+ if (deleted)
+ return super.delete(gracePeriod);
+ return deleted;
+ }
+ else
+ {
+ return false;
+ }
}
/**
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -46,6 +46,7 @@
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -130,6 +131,9 @@
/** RealURL of this context */
private URL realURL;
+ /** Nested handlers */
+ private List<VirtualFileHandler> nestedHandlers = new CopyOnWriteArrayList<VirtualFileHandler>();
+
/**
* Create a new ZipEntryContext
*
@@ -352,7 +356,8 @@
{
boolean noReaper = Boolean.valueOf(getAggregatedOptions().get(VFSUtils.NO_REAPER_QUERY));
realURL = urlInfo.toURL();
- return new ZipFileWrapper(file, autoClean, noReaper);
+ boolean isAutoClean = autoClean || Boolean.valueOf(getAggregatedOptions().get(VFSUtils.IS_TEMP_FILE));
+ return new ZipFileWrapper(file, isAutoClean, noReaper);
}
}
@@ -491,6 +496,7 @@
}
AbstractVirtualFileHandler parent = ei != null ? ei.handler : null;
+ // it's a nested jar
if(ent.isDirectory() == false && JarUtils.isArchive(ent.getName()))
{
boolean useCopyMode = forceCopy;
@@ -526,6 +532,7 @@
entries.put(delegator.getLocalPathName(), new EntryInfo(delegator, ent));
addChild(parent, delegator);
+ nestedHandlers.add(delegator); // add nested delegator
}
else
{
@@ -792,6 +799,25 @@
}
/**
+ * Close the handler, if it's root.
+ *
+ * @param handler the handler to close
+ */
+ public void cleanup(ZipEntryHandler handler)
+ {
+ VirtualFileHandler rootHandler = getRoot();
+ if (rootHandler.equals(handler))
+ {
+ // only cleanup nested - as they might be temp files we want to delete
+ for (VirtualFileHandler vfh : nestedHandlers)
+ {
+ vfh.cleanup();
+ }
+ getZipSource().close(); // close == cleanup in zip source impl
+ }
+ }
+
+ /**
* Returns lastModified timestamp for a given handler
*
* @param handler a handler
@@ -1001,11 +1027,10 @@
/**
* Properly release held resources
*/
- protected void finalize()
+ protected void finalize() throws Throwable
{
try
{
- super.finalize();
if (zipSource != null)
zipSource.close();
}
@@ -1013,6 +1038,7 @@
{
log.debug("IGNORING: Failed to close zip source: " + zipSource, ignored);
}
+ super.finalize();
}
/**
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -160,6 +160,12 @@
return false;
}
+ @Override
+ public void cleanup()
+ {
+ getZipEntryContext().cleanup(this);
+ }
+
public boolean delete(int gracePeriod) throws IOException
{
checkClosed();
@@ -183,6 +189,11 @@
getZipEntryContext().replaceChild(this, (AbstractVirtualFileHandler) original, replacement);
}
+ /**
+ * Get owner zip entry context.
+ *
+ * @return the owner zip entry context
+ */
private ZipEntryContext getZipEntryContext()
{
return ((ZipEntryContext) getLocalVFSContext());
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInputStream.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInputStream.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInputStream.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -226,7 +226,7 @@
/**
* Properly release held resources
*/
- protected void finalize()
+ protected void finalize() throws Throwable
{
try
{
@@ -235,6 +235,7 @@
catch(IOException ignored)
{
}
+ super.finalize();
}
/**
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -35,6 +35,7 @@
import org.jboss.logging.Logger;
import org.jboss.util.id.GUID;
import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.plugins.context.DelegatingHandler;
import org.jboss.virtual.plugins.context.file.FileSystemContext;
import org.jboss.virtual.spi.ExceptionHandler;
@@ -101,7 +102,10 @@
* @return true if needs replacement
* @throws IOException for any error
*/
- protected abstract boolean replaceOldHandler(VirtualFileHandler parent, VirtualFileHandler oldHandler, VirtualFileHandler newHandler) throws IOException;
+ protected boolean replaceOldHandler(VirtualFileHandler parent, VirtualFileHandler oldHandler, VirtualFileHandler newHandler) throws IOException
+ {
+ return true;
+ }
/**
* Unwrap the handler from possible delegate handler.
@@ -137,6 +141,8 @@
// merge old options
VFSContext oldVFSContext = handler.getVFSContext();
Map<String, String> newOptions = fileSystemContext.getOptions();
+ if (newOptions != null) // shouldn't be null, but we check anyway
+ newOptions.put(VFSUtils.IS_TEMP_FILE, Boolean.TRUE.toString());
Map<String, String> oldOptions = oldVFSContext.getOptions();
if (newOptions != null && oldOptions != null && oldOptions.isEmpty() == false)
newOptions.putAll(oldOptions);
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/ExplodedCopyMechanism.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/ExplodedCopyMechanism.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/ExplodedCopyMechanism.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -44,9 +44,4 @@
{
return handler instanceof FileHandler || handler.isLeaf();
}
-
- protected boolean replaceOldHandler(VirtualFileHandler parent, VirtualFileHandler oldHandler, VirtualFileHandler newHandler) throws IOException
- {
- return false;
- }
}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -68,9 +68,4 @@
return super.copy(guidDir, handler);
}
-
- protected boolean replaceOldHandler(VirtualFileHandler parent, VirtualFileHandler oldHandler, VirtualFileHandler newHandler) throws IOException
- {
- return false;
- }
}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/UnpackCopyMechanism.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/UnpackCopyMechanism.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/copy/UnpackCopyMechanism.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -43,9 +43,4 @@
{
return handler.isNested() == false;
}
-
- protected boolean replaceOldHandler(VirtualFileHandler parent, VirtualFileHandler oldHandler, VirtualFileHandler newHandler) throws IOException
- {
- return true;
- }
}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -102,7 +102,7 @@
@SuppressWarnings("deprecation")
protected static VirtualFile resolveVirtualFile(URL vfsurl, String relativePath) throws IOException
{
- VirtualFile file = VFS.getCachedFile(vfsurl);
+ VirtualFile file = VFS.getRoot(vfsurl);
return file.findChild(relativePath);
}
Modified: projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -222,8 +222,13 @@
* @throws IllegalStateException if closed
*/
VirtualFile getVirtualFile();
-
+
/**
+ * Cleanup resources.
+ */
+ void cleanup();
+
+ /**
* Close the resources
*/
void close();
@@ -251,5 +256,5 @@
* @return boolean true if file was deleted, false otherwise
* @throws IOException for any error
*/
- public boolean delete(int gracePeriod) throws IOException;
+ boolean delete(int gracePeriod) throws IOException;
}
Added: projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java (rev 0)
+++ projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/CombinedVFSCacheTestCase.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -0,0 +1,123 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.virtual.test;
+
+import java.net.URL;
+import java.util.Collections;
+import java.util.Map;
+
+import junit.framework.Test;
+import org.jboss.virtual.plugins.cache.CombinedVFSCache;
+import org.jboss.virtual.plugins.cache.IterableTimedVFSCache;
+import org.jboss.virtual.spi.ExceptionHandler;
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.cache.VFSCache;
+
+/**
+ * Combined VFSCache Test.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class CombinedVFSCacheTestCase extends VFSCacheTest
+{
+ public CombinedVFSCacheTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(CombinedVFSCacheTestCase.class);
+ }
+
+ @Override
+ protected void configureCache(VFSCache cache) throws Exception
+ {
+ if (cache instanceof CombinedVFSCache)
+ {
+ CombinedVFSCache cvc = CombinedVFSCache.class.cast(cache);
+
+ URL url = getResource("/vfs/test/nested");
+ Map<URL, ExceptionHandler> map = Collections.singletonMap(url, null);
+ cvc.setPermanentRoots(map);
+
+ IterableTimedVFSCache realCache = new IterableTimedVFSCache(5);
+ realCache.start();
+ cvc.setRealCache(realCache);
+
+ cvc.create();
+ }
+ }
+
+ @Override
+ protected void stopCache(VFSCache cache)
+ {
+ if (cache != null)
+ {
+ if (cache instanceof CombinedWrapperVFSCache)
+ {
+ CombinedWrapperVFSCache cwvc = (CombinedWrapperVFSCache)cache;
+ cwvc.getTemp().stop();
+ }
+ cache.stop();
+ }
+ }
+
+ @Override
+ protected Class<? extends VFSCache> getCacheClass()
+ {
+ return CombinedVFSCache.class;
+ }
+
+ protected CombinedVFSCache createCache()
+ {
+ return new CombinedWrapperVFSCache();
+ }
+
+ protected Map<Object, Object> getMap()
+ {
+ return null;
+ }
+
+ protected void testCachedContexts(Iterable<VFSContext> iter)
+ {
+ VFSContext context = iter.iterator().next();
+ assertNotNull(context);
+ }
+
+ private class CombinedWrapperVFSCache extends CombinedVFSCache
+ {
+ private VFSCache temp;
+
+ @Override
+ public void setRealCache(VFSCache realCache)
+ {
+ super.setRealCache(realCache);
+ temp = realCache;
+ }
+
+ public VFSCache getTemp()
+ {
+ return temp;
+ }
+ }
+}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/CopyTest.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/CopyTest.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/CopyTest.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -81,7 +81,10 @@
assertNotNull(replacement.findChild("jar2.jar"));
}
- protected abstract void assertTopLevelParent(VirtualFile originalParent, VirtualFile replacementParent) throws Exception;
+ protected void assertTopLevelParent(VirtualFile originalParent, VirtualFile replacementParent) throws Exception
+ {
+ assertEquals(originalParent, replacementParent);
+ }
public void testUnpackTopLevel() throws Throwable
{
@@ -165,7 +168,7 @@
protected void assertExplodedReplacement(VirtualFile original, VirtualFile replacement) throws Exception
{
assertReplacement(original, replacement);
- assertNull(replacement.getParent());
+ assertNotNull(replacement.getParent());
}
protected void assertReplacement(VirtualFile original, VirtualFile replacement) throws Exception
Modified: projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/DetachedCopyTest.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/DetachedCopyTest.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/DetachedCopyTest.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -50,7 +50,7 @@
protected void assertTopLevel(VirtualFile original, VirtualFile replacement) throws Exception
{
assertReplacement(original, replacement, isExploded());
- assertNull(replacement.getParent());
+ assertNotNull(replacement.getParent());
}
protected void assertNestedLevel(VirtualFile original, VirtualFile replacement) throws Exception
@@ -58,11 +58,6 @@
assertExplodedReplacement(original, replacement);
}
- protected void assertTopLevelParent(VirtualFile originalParent, VirtualFile replacementParent) throws Exception
- {
- assertNull(replacementParent);
- }
-
protected void assertOnURI(VirtualFile original, VirtualFile replacement) throws Exception
{
assertReplacement(original, replacement);
Added: projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java (rev 0)
+++ projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -0,0 +1,201 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.virtual.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.net.URI;
+import java.net.URL;
+
+import junit.framework.Test;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.copy.AbstractCopyMechanism;
+import org.jboss.virtual.plugins.cache.LRUVFSCache;
+import org.jboss.virtual.spi.cache.VFSCache;
+import org.jboss.virtual.spi.cache.VFSCacheFactory;
+
+/**
+ * Test file closing
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class FileCleanupUnitTestCase extends AbstractVFSTest
+{
+ private File tempDir;
+
+ public FileCleanupUnitTestCase(String name)
+ {
+ super(name, true, true);
+ }
+
+ protected FileCleanupUnitTestCase(String name, boolean forceCopy, boolean forceNoReaper)
+ {
+ super(name, forceCopy, forceNoReaper);
+ }
+
+ public static Test suite()
+ {
+ VFS.init();
+ return suite(FileCleanupUnitTestCase.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ // nullify the temp dir
+ Class<?> clazz = AbstractCopyMechanism.class;
+ Field field = clazz.getDeclaredField("tempDir");
+ field.setAccessible(true);
+ field.set(null, null);
+
+ String tempDirKey = System.getProperty("vfs.temp.dir", "jboss.server.temp.dir");
+ String tempDirString = System.getProperty(tempDirKey, System.getProperty("java.io.tmpdir")) + "filecleanup";
+
+ tempDir = new File(tempDirString);
+ if (tempDir.exists())
+ {
+ deleteTempDir();
+ }
+ assertTrue(tempDir.mkdir());
+
+ System.setProperty("jboss.server.temp.dir", tempDirString);
+
+ VFSCache cache = new LRUVFSCache(2, 5);
+ cache.start();
+ VFSCacheFactory.setInstance(cache);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ VFSCacheFactory.getInstance().stop();
+ }
+ catch (Throwable ignored)
+ {
+ }
+ finally
+ {
+ VFSCacheFactory.setInstance(null);
+ }
+
+ System.clearProperty("jboss.server.temp.dir");
+
+ try
+ {
+ deleteTempDir();
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+
+ protected void deleteTempDir() throws IOException
+ {
+ // use vfs to disable possible reaper
+ VirtualFile td = VFS.getRoot(tempDir.toURI());
+ td.cleanup();
+ td.delete();
+ }
+
+ protected void assertTempFiles(int size) throws Exception
+ {
+ File dir = new File(tempDir, "vfs-nested.tmp");
+ File[] files = dir.listFiles();
+ assertNotNull(files);
+ assertEquals(size, files.length);
+ }
+
+ protected void assertCopyMechanismFiles(int size) throws Exception
+ {
+ File[] files = tempDir.listFiles();
+ assertNotNull(files);
+ int counter = 0;
+ for (File dir : files)
+ {
+ counter += dir.listFiles().length;
+ }
+ assertEquals(size, counter);
+ }
+
+ protected void assertCacheExists(URI uri) throws Exception
+ {
+ VFSCache cache = VFSCacheFactory.getInstance();
+ VirtualFile file = cache.getFile(uri);
+ assertNotNull(file);
+ }
+
+ protected void assertNoCache(URI uri) throws Exception
+ {
+ VFSCache cache = VFSCacheFactory.getInstance();
+ VirtualFile file = cache.getFile(uri);
+ assertNull(file);
+ }
+
+ public void testNestedJarCleanup() throws Exception
+ {
+ URL url = getResource("/vfs/test/nested/nested.jar");
+ VirtualFile root = VFS.getRoot(url);
+ assertNotNull(root);
+ VirtualFile child = root.getChild("complex.jar");
+ assertNotNull(child);
+ VirtualFile nestedChild = child.getChild("child");
+ assertNotNull(nestedChild);
+
+ assertTempFiles(1);
+
+ nestedChild.cleanup();
+ assertCacheExists(nestedChild.toURI());
+
+ root.cleanup();
+
+ assertTempFiles(0);
+ assertNoCache(root.toURI());
+ }
+
+ public void testExplicitCopyCleanup() throws Exception
+ {
+ URL url = getResource("/vfs/test/nested/nested.jar");
+ VirtualFile root = VFS.getRoot(url);
+ assertNotNull(root);
+
+ VirtualFile copy = VFSUtils.temp(root);
+ assertNotNull(copy);
+ assertTrue(VFSUtils.isTemporaryFile(copy));
+
+ assertCopyMechanismFiles(1);
+
+ copy.cleanup();
+
+ assertCopyMechanismFiles(0);
+
+ root.cleanup();
+ assertNoCache(root.toURI());
+ }
+}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -117,21 +117,27 @@
public void testSuspiciousTokens() throws Throwable
{
- testSuspiciousTokens(false);
- testSuspiciousTokens(true);
+ testSuspiciousTokens("/.hudson/..hudson/...hudson/./../.../.*foo/foo.bar", ".hudson", "..hudson", "...hudson", ".", "..", "...", ".*foo", "foo.bar");
+ testSuspiciousTokens("jpa/.svn", "jpa", ".svn");
}
- public void testSuspiciousTokens(boolean flag) throws Throwable
+ protected void testSuspiciousTokens(String path, String... expected) throws Throwable
{
+ testSuspiciousTokens(true, path, expected);
+ testSuspiciousTokens(false, path, expected);
+ }
+
+ protected void testSuspiciousTokens(boolean flag, String path, String... expected) throws Throwable
+ {
PathTokenizer.setErrorOnSuspiciousTokens(flag);
try
{
- String path = "/.hudson/..hudson/...hudson/./../.../.*foo/foo.bar";
List<String> tokens = PathTokenizer.getTokens(path);
- List<String> expected = Arrays.asList(".hudson", "..hudson", "...hudson", ".", "..", "...", ".*foo", "foo.bar");
- assertEquals(expected, tokens);
if (flag)
fail("Should not be here.");
+
+ List<String> expectedTokens = Arrays.asList(expected);
+ assertEquals(expectedTokens, tokens);
}
catch (Throwable t)
{
Modified: projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/UnpackTestCase.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/UnpackTestCase.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/UnpackTestCase.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -61,9 +61,4 @@
{
assertUnpackedReplacement(original, replacement);
}
-
- protected void assertTopLevelParent(VirtualFile originalParent, VirtualFile replacementParent) throws Exception
- {
- assertEquals(originalParent, replacementParent);
- }
}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -92,8 +92,11 @@
suite.addTest(IterableTimedCacheTestCase.suite());
suite.addTest(SoftRefCacheTestCase.suite());
suite.addTest(WeakRefCacheTestCase.suite());
+ suite.addTest(CombinedVFSCacheTestCase.suite());
// exception handler
suite.addTest(ExceptionHandlerTestCase.suite());
+ // operations
+ suite.addTest(FileCleanupUnitTestCase.suite());
return suite;
}
Modified: projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java
===================================================================
--- projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java 2009-01-27 10:30:40 UTC (rev 83456)
+++ projects/vfs/branches/Branch_2_0/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java 2009-01-27 10:42:02 UTC (rev 83457)
@@ -49,6 +49,16 @@
protected abstract VFSCache createCache();
+ protected void configureCache(VFSCache cache) throws Exception
+ {
+ }
+
+ protected void stopCache(VFSCache cache)
+ {
+ if (cache != null)
+ cache.stop();
+ }
+
@SuppressWarnings("deprecation")
public void testCache() throws Exception
{
@@ -61,6 +71,8 @@
VFSCacheFactory.setInstance(cache);
try
{
+ configureCache(cache);
+
VirtualFile root = VFS.getRoot(url);
VirtualFile file = root.findChild("/nested.jar/META-INF/empty.txt");
@@ -85,7 +97,7 @@
}
finally
{
- cache.stop();
+ stopCache(cache);
}
}
@@ -105,6 +117,8 @@
VFSCacheFactory.setInstance(cache);
try
{
+ configureCache(cache);
+
VirtualFile root = VFS.getRoot(url);
assertNotNull(root);
@@ -122,7 +136,7 @@
}
finally
{
- cache.stop();
+ stopCache(cache);
}
}
@@ -141,7 +155,7 @@
public void testCacheFactory() throws Exception
{
- VFSCache cache;
+ VFSCache cache = null;
String cacheClassName = getCacheClass().getName();
VFSCacheFactory.setInstance(null);
@@ -173,6 +187,7 @@
}
finally
{
+ stopCache(cache);
VFSCacheFactory.setInstance(null);
}
}
More information about the jboss-cvs-commits
mailing list