[jboss-cvs] JBossAS SVN: r82978 - in projects/vfs/trunk/src: main/java/org/jboss/virtual/plugins/context and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jan 16 07:38:47 EST 2009
Author: alesj
Date: 2009-01-16 07:38:47 -0500 (Fri, 16 Jan 2009)
New Revision: 82978
Added:
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java
Removed:
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCloseUnitTestCase.java
Modified:
projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.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/jar/NestedJarHandler.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/plugins/copy/AbstractCopyMechanism.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
Log:
[JBVFS-86]; initial cleanup api.
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java 2009-01-16 08:57:00 UTC (rev 82977)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java 2009-01-16 12:38:47 UTC (rev 82978)
@@ -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/trunk/src/main/java/org/jboss/virtual/VirtualFile.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java 2009-01-16 08:57:00 UTC (rev 82977)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java 2009-01-16 12:38:47 UTC (rev 82978)
@@ -263,6 +263,15 @@
}
/**
+ * Do file cleanup.
+ * e.g. delete temp files
+ */
+ public void cleanup()
+ {
+ getHandler().cleanup();
+ }
+
+ /**
* Close the file resources (stream, etc.)
*/
public void close()
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 2009-01-16 08:57:00 UTC (rev 82977)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2009-01-16 12:38:47 UTC (rev 82978)
@@ -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;
@@ -453,13 +454,40 @@
if (references.get() < 0)
throw new IllegalStateException("Closed " + toStringLocal());
}
-
- public void close()
+
+ /**
+ * Get the references count.
+ *
+ * @return the ref count
+ */
+ protected int getReferences()
{
- if (decrement() == 0)
- doClose();
+ return references.get();
}
+ public void cleanup()
+ {
+ }
+
+ public boolean isTemporary()
+ {
+ 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/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java 2009-01-16 08:57:00 UTC (rev 82977)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java 2009-01-16 12:38:47 UTC (rev 82978)
@@ -151,22 +151,32 @@
}
@Override
+ public void cleanup()
+ {
+ getDelegate().cleanup();
+ }
+
+ @Override
public void close()
{
if (delegate == null)
return;
- if (delegate instanceof AbstractVirtualFileHandler)
+ try
{
- if (decrement() == 0)
+ if ((delegate instanceof AbstractVirtualFileHandler) && getReferences() == 1)
{
AbstractVirtualFileHandler avfh = AbstractVirtualFileHandler.class.cast(delegate);
avfh.doClose();
}
+ else
+ {
+ delegate.close();
+ }
}
- else
+ finally
{
- delegate.close();
+ decrement();
}
}
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 2009-01-16 08:57:00 UTC (rev 82977)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileHandler.java 2009-01-16 12:38:47 UTC (rev 82978)
@@ -161,6 +161,13 @@
return false;
}
+ @Override
+ public void cleanup()
+ {
+ if (isTemporary())
+ Files.delete(file);
+ }
+
public boolean delete(int gracePeriod) throws IOException
{
File f = getFile();
@@ -235,7 +242,6 @@
// if underlying file has been modified then create a new handler instead of using the cached one
if (handler != null && handler.hasBeenModified())
{
- handler.close(); // close old cached one
handler = null;
}
if (handler == null)
@@ -270,7 +276,6 @@
// if the child has been modified on disk then create a new handler
if (handler != null && handler.hasBeenModified())
{
- handler.close(); // close old cached one
handler = null;
}
if (handler == null)
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 2009-01-16 08:57:00 UTC (rev 82977)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java 2009-01-16 12:38:47 UTC (rev 82978)
@@ -32,6 +32,7 @@
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
+import org.jboss.util.file.Files;
import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VirtualFileHandler;
@@ -188,12 +189,26 @@
return false;
}
+ @Override
+ public void cleanup()
+ {
+ if (temp != null)
+ Files.delete(temp);
+ }
+
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/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 2009-01-16 08:57:00 UTC (rev 82977)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2009-01-16 12:38:47 UTC (rev 82978)
@@ -356,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);
}
}
@@ -802,17 +803,17 @@
*
* @param handler the handler to close
*/
- public void close(ZipEntryHandler handler)
+ public void cleanup(ZipEntryHandler handler)
{
VirtualFileHandler rootHandler = getRoot();
if (rootHandler.equals(handler))
{
- getZipSource().close();
- // only close nested - as they might be temp files we want to delete
+ // only cleanup nested - as they might be temp files we want to delete
for (VirtualFileHandler vfh : nestedHandlers)
{
- vfh.close();
+ vfh.cleanup();
}
+ getZipSource().close(); // close == cleanup in zip source impl
}
}
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 2009-01-16 08:57:00 UTC (rev 82977)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java 2009-01-16 12:38:47 UTC (rev 82978)
@@ -161,9 +161,9 @@
}
@Override
- protected void doClose()
+ public void cleanup()
{
- getZipEntryContext().close(this);
+ getZipEntryContext().cleanup(this);
}
public boolean delete(int gracePeriod) throws IOException
@@ -189,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/trunk/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java 2009-01-16 08:57:00 UTC (rev 82977)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java 2009-01-16 12:38:47 UTC (rev 82978)
@@ -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;
@@ -137,6 +138,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/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java 2009-01-16 08:57:00 UTC (rev 82977)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java 2009-01-16 12:38:47 UTC (rev 82978)
@@ -222,8 +222,13 @@
* @throws IllegalStateException if closed
*/
VirtualFile getVirtualFile();
-
+
/**
+ * Cleanup resources.
+ */
+ void cleanup();
+
+ /**
* Close the resources
*/
void close();
@@ -251,5 +256,12 @@
* @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;
+
+ /**
+ * Is the handler temporary.
+ *
+ * @return true if temporary, false otherwise
+ */
+ boolean isTemporary();
}
Copied: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java (from rev 82819, projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCloseUnitTestCase.java)
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java 2009-01-16 12:38:47 UTC (rev 82978)
@@ -0,0 +1,81 @@
+/*
+ * 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.net.URL;
+
+import junit.framework.Test;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VFSUtils;
+
+/**
+ * Test file closing
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+// TODO - some real test of deletion - count the temp files == 0?
+public class FileCleanupUnitTestCase extends AbstractVFSTest
+{
+ public FileCleanupUnitTestCase(String name)
+ {
+ super(name, true, false);
+ }
+
+ protected FileCleanupUnitTestCase(String name, boolean forceCopy)
+ {
+ super(name, forceCopy, false);
+ }
+
+ public static Test suite()
+ {
+ VFS.init();
+ return suite(FileCleanupUnitTestCase.class);
+ }
+
+ 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);
+
+ nestedChild.cleanup();
+ root.cleanup();
+ }
+
+ 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));
+
+ copy.cleanup();
+ }
+}
\ No newline at end of file
Property changes on: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Deleted: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCloseUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCloseUnitTestCase.java 2009-01-16 08:57:00 UTC (rev 82977)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCloseUnitTestCase.java 2009-01-16 12:38:47 UTC (rev 82978)
@@ -1,67 +0,0 @@
-/*
- * 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.net.URL;
-
-import junit.framework.Test;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * Test file closing
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class FileCloseUnitTestCase extends AbstractVFSTest
-{
- public FileCloseUnitTestCase(String name)
- {
- super(name, true, false);
- }
-
- protected FileCloseUnitTestCase(String name, boolean forceCopy)
- {
- super(name, forceCopy, false);
- }
-
- public static Test suite()
- {
- VFS.init();
- return suite(FileCloseUnitTestCase.class);
- }
-
- public void testNestedJarClosing() 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);
-
- // TODO - some real test of deletion
- nestedChild.close();
- root.close();
- }
-}
\ No newline at end of file
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java 2009-01-16 08:57:00 UTC (rev 82977)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java 2009-01-16 12:38:47 UTC (rev 82978)
@@ -96,7 +96,7 @@
// exception handler
suite.addTest(ExceptionHandlerTestCase.suite());
// operations
- suite.addTest(FileCloseUnitTestCase.suite());
+ suite.addTest(FileCleanupUnitTestCase.suite());
return suite;
}
More information about the jboss-cvs-commits
mailing list