[jboss-cvs] JBossAS SVN: r83795 - in projects/vfs/trunk/src: main/java/org/jboss/virtual/plugins/context and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Feb 3 01:19:00 EST 2009
Author: alesj
Date: 2009-02-03 01:18:59 -0500 (Tue, 03 Feb 2009)
New Revision: 83795
Added:
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ExplodeCleanupUnitTestCase.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTest.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/TempCleanupUnitTestCase.java
Removed:
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java
Modified:
projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.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/jar/AbstractStructuredJarHandler.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/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/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/test/AbstractVFSContextTest.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSContextUnitTestCase.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java
Log:
VirtualFileHandler::isArchive,
remove deprecated VFS methods,
add exploded file cleanup test.
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java 2009-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -188,25 +188,6 @@
}
/**
- * Get cached file.
- *
- * If VFSContext matching the rootURI parameter is cached
- * this method will return cached virtual file
- * else it will use VFS::getRoot(rootURI).
- *
- * @param rootURI the root uri
- * @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
- {
- return getRoot(rootURI);
- }
-
- /**
* Get a virtual file
*
* @param rootURI the root uri
@@ -270,25 +251,6 @@
}
/**
- * Get cached file.
- *
- * If VFSContext matching the rootURL parameter is cached
- * this method will return cached virtual file
- * else it will use VFS::getRoot(rootURL).
- *
- * @param rootURL the root url
- * @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
- {
- return getRoot(rootURL);
- }
-
- /**
* Get a virtual file
*
* @param rootURL the root url
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java 2009-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -193,6 +193,17 @@
}
/**
+ * Is the file archive.
+ *
+ * @return true if archive, false otherwise
+ * @throws IOException for any error
+ */
+ public boolean isArchive() throws IOException
+ {
+ return getHandler().isArchive();
+ }
+
+ /**
* Whether it is hidden
*
* @return true when hidden
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-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -182,6 +182,11 @@
return childPathName;
}
+ public boolean isArchive() throws IOException
+ {
+ return false;
+ }
+
public boolean hasBeenModified() throws IOException
{
boolean hasBeenModified = false;
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-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -145,6 +145,12 @@
return getDelegate().isLeaf();
}
+ @Override
+ public boolean isArchive() throws IOException
+ {
+ return getDelegate().isArchive();
+ }
+
public boolean exists() throws IOException
{
return getDelegate().exists();
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java 2009-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -253,6 +253,12 @@
return next;
}
+ @Override
+ public boolean isArchive() 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 2009-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarHandler.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -34,6 +34,7 @@
* JarHandler.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @version $Revision: 1.1 $
*/
public class JarHandler extends AbstractStructuredJarHandler<Object>
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-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -38,9 +38,9 @@
/**
* Nested Jar Handler.
*
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @author Scott.Stark at jboss.org
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @version $Revision: 1.1 $
*/
public class NestedJarHandler extends AbstractStructuredJarHandler<Object>
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 2009-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NoCopyNestedJarHandler.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -36,8 +36,8 @@
/**
* Nested Jar Handler.
*
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
* @author <a href="ales.justin at jboss.org">Ales Justin</a>
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
public class NoCopyNestedJarHandler extends AbstractJarHandler
@@ -113,6 +113,12 @@
return getEntry().getSize();
}
+ @Override
+ public boolean isArchive() throws IOException
+ {
+ return njar.isArchive();
+ }
+
public boolean isNested() throws IOException
{
return true;
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-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -780,7 +780,7 @@
* @param name name of the child
* @return child handler or null if not found
*/
- public VirtualFileHandler getChild(ZipEntryHandler parent, String name)
+ VirtualFileHandler getChild(ZipEntryHandler parent, String name)
{
if (parent == null)
throw new IllegalArgumentException("Null parent");
@@ -837,7 +837,7 @@
* @return true if delete succeeded
* @throws IOException for any error
*/
- public boolean delete(ZipEntryHandler handler, int gracePeriod) throws IOException
+ boolean delete(ZipEntryHandler handler, int gracePeriod) throws IOException
{
return getRoot().equals(handler) && getZipSource().delete(gracePeriod);
}
@@ -847,7 +847,7 @@
*
* @param handler the handler to close
*/
- public void cleanup(ZipEntryHandler handler)
+ void cleanup(ZipEntryHandler handler)
{
VirtualFileHandler rootHandler = getRoot();
if (rootHandler.equals(handler))
@@ -862,7 +862,7 @@
* @param handler a handler
* @return lastModified timestamp
*/
- public long getLastModified(ZipEntryHandler handler)
+ long getLastModified(ZipEntryHandler handler)
{
if (handler == null)
throw new IllegalArgumentException("Null handler");
@@ -886,7 +886,7 @@
* @param handler a handler
* @return size in bytes
*/
- public long getSize(ZipEntryHandler handler)
+ long getSize(ZipEntryHandler handler)
{
if (handler == null)
throw new IllegalArgumentException("Null handler");
@@ -909,7 +909,7 @@
* @param handler a handler
* @return true if entry exists
*/
- public boolean exists(ZipEntryHandler handler)
+ boolean exists(ZipEntryHandler handler)
{
if (handler == null)
throw new IllegalArgumentException("Null handler");
@@ -925,10 +925,10 @@
/**
* Returns true if handler represents a non-directory entry
*
- * @param handler a handler
+ * @param handler the handler
* @return true if not a directory
*/
- public boolean isLeaf(ZipEntryHandler handler)
+ boolean isLeaf(ZipEntryHandler handler)
{
if (handler == null)
throw new IllegalArgumentException("Null handler");
@@ -944,6 +944,17 @@
}
/**
+ * Is the handler archive.
+ *
+ * @param handler the handler
+ * @return true if archive, false otherwise
+ */
+ boolean isArchive(ZipEntryHandler handler)
+ {
+ return getRoot().equals(handler);
+ }
+
+ /**
* Is archive.
*
* @param handler the handler
@@ -1010,7 +1021,7 @@
* @return InputStream with entry's content
* @throws IOException for any error
*/
- public InputStream openStream(ZipEntryHandler handler) throws IOException
+ InputStream openStream(ZipEntryHandler handler) throws IOException
{
if (handler == null)
throw new IllegalArgumentException("Null handler");
@@ -1087,7 +1098,7 @@
* @param original current child
* @param replacement new child
*/
- public void replaceChild(ZipEntryHandler parent, AbstractVirtualFileHandler original, VirtualFileHandler replacement)
+ void replaceChild(ZipEntryHandler parent, AbstractVirtualFileHandler original, VirtualFileHandler replacement)
{
ensureEntries();
EntryInfo parentEntry = entries.get(parent.getLocalPathName());
@@ -1125,7 +1136,7 @@
*
* @return the real url
*/
- public URL getRealURL()
+ URL getRealURL()
{
// make sure realURL has been initialized
// realURL is initialized when ZipSource is initialized
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-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -131,6 +131,13 @@
return getZipEntryContext().isLeaf(this);
}
+ @Override
+ public boolean isArchive() throws IOException
+ {
+ checkClosed();
+ return getZipEntryContext().isArchive(this);
+ }
+
public boolean isHidden() throws IOException
{
checkClosed();
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-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -151,6 +151,15 @@
boolean isLeaf() throws IOException;
/**
+ * Does this represent an archive.
+ * e.g. zip, tar, ...
+ *
+ * @return true if archive, false otherwise
+ * @throws IOException for any problem accessing the virtual file system
+ */
+ boolean isArchive() throws IOException;
+
+ /**
* Whether it is hidden
*
* @return true if hidden.
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSContextTest.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSContextTest.java 2009-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSContextTest.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -39,6 +39,7 @@
* AbstractVFSContextTest.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @version $Revision: 1.1 $
*/
public abstract class AbstractVFSContextTest extends AbstractVFSTest
@@ -62,6 +63,8 @@
protected abstract boolean isRealURLSupported();
+ protected abstract boolean isArchive();
+
/* TODO URI testing
public void testRootURI() throws Exception
{
@@ -273,6 +276,34 @@
}
}
+ public void testIsArchive() throws Exception
+ {
+ VFSContext context = getVFSContext("nested");
+
+ VirtualFileHandler root = context.getRoot();
+ assertEquals(isArchive(), root.isArchive());
+
+ VirtualFileHandler complex = root.getChild("complex.jar");
+ assertNotNull(complex);
+ assertEquals(isArchive(), complex.isArchive());
+
+ VirtualFileHandler subfolder = complex.getChild("subfolder");
+ assertNotNull(subfolder);
+ assertFalse(subfolder.isArchive());
+
+ VirtualFileHandler subchild = subfolder.getChild("subchild");
+ assertNotNull(subchild);
+ assertFalse(subchild.isArchive());
+
+ VirtualFileHandler subsubfolder = subfolder.getChild("subsubfolder");
+ assertNotNull(subsubfolder);
+ assertFalse(subsubfolder.isArchive());
+
+ VirtualFileHandler subsubchild = subsubfolder.getChild("subsubchild");
+ assertNotNull(subsubchild);
+ assertFalse(subsubchild.isArchive());
+ }
+
public void testSpecialTokensOnLeaf() throws Exception
{
VFSContext context = getVFSContext("complex");
Added: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ExplodeCleanupUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ExplodeCleanupUnitTestCase.java (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ExplodeCleanupUnitTestCase.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -0,0 +1,56 @@
+/*
+ * 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 junit.framework.Test;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Test file closing - explode
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ExplodeCleanupUnitTestCase extends FileCleanupUnitTest
+{
+ public ExplodeCleanupUnitTestCase(String name)
+ {
+ super(name, true, true);
+ }
+
+ public static Test suite()
+ {
+ VFS.init();
+ return suite(ExplodeCleanupUnitTestCase.class);
+ }
+
+ protected VirtualFile modify(VirtualFile original) throws Exception
+ {
+ return VFSUtils.explode(original);
+ }
+
+ protected String getProtocol()
+ {
+ return "vfsfile:";
+ }
+}
\ No newline at end of file
Copied: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTest.java (from rev 83788, projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java)
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTest.java (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTest.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -0,0 +1,299 @@
+/*
+ * 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.io.FilenameFilter;
+import java.lang.reflect.Field;
+import java.net.URI;
+import java.net.URL;
+
+import junit.framework.Test;
+import org.jboss.util.id.GUID;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.cache.LRUVFSCache;
+import org.jboss.virtual.plugins.copy.AbstractCopyMechanism;
+import org.jboss.virtual.spi.cache.VFSCache;
+import org.jboss.virtual.spi.cache.VFSCacheFactory;
+import org.jboss.virtual.spi.registry.VFSRegistry;
+
+/**
+ * Test file closing
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class FileCleanupUnitTest extends AbstractVFSRegistryTest
+{
+ private File tempDir;
+
+ protected FileCleanupUnitTest(String name)
+ {
+ super(name, true, true);
+ }
+
+ protected FileCleanupUnitTest(String name, boolean forceCopy, boolean forceNoReaper)
+ {
+ super(name, forceCopy, forceNoReaper);
+ }
+
+ public static Test suite()
+ {
+ VFS.init();
+ return suite(FileCleanupUnitTest.class);
+ }
+
+ protected abstract VirtualFile modify(VirtualFile original) throws Exception;
+
+ protected abstract String getProtocol();
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ try
+ {
+ // 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")) + GUID.asString();
+
+ tempDir = new File(tempDirString);
+ tempDir.deleteOnExit();
+ 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);
+ }
+ catch (Exception e)
+ {
+ super.tearDown();
+ throw e;
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ deleteTempDir();
+
+ VFSCacheFactory.getInstance().stop();
+ VFSCacheFactory.setInstance(null);
+
+ System.clearProperty("jboss.server.temp.dir");
+ }
+ catch (Throwable ignored)
+ {
+ }
+ 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();
+ if (dir.exists())
+ {
+ assertEquals(size, files.length);
+ }
+ else if (size == 0)
+ {
+ assertNull(files);
+ }
+ else
+ {
+ fail("Illegal dir: " + dir);
+ }
+ }
+
+ protected void assertCopyMechanismFiles(int size) throws Exception
+ {
+ File[] files = tempDir.listFiles(new FilenameFilter()
+ {
+ public boolean accept(File dir, String name)
+ {
+ return name.contains("vfs-nested.tmp") == false;
+ }
+ });
+ assertNotNull(files);
+ int counter = 0;
+ for (File dir : files)
+ {
+ File[] realFiles = dir.listFiles();
+ counter += realFiles.length;
+ }
+ assertEquals(size, counter);
+ }
+
+ protected void assertRegistryEntryExists(URI uri) throws Exception
+ {
+ VFSRegistry registry = VFSRegistry.getInstance();
+ VirtualFile file = registry.getFile(uri);
+ assertNotNull(file);
+ }
+
+ protected void assertNoRegistryEntry(URI uri) throws Exception
+ {
+ VFSRegistry registry = VFSRegistry.getInstance();
+ VirtualFile file = registry.getFile(uri);
+ assertNull("" + uri, 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();
+ assertRegistryEntryExists(nestedChild.toURI());
+
+ root.cleanup();
+
+ assertTempFiles(0);
+ assertNoRegistryEntry(root.toURI());
+ }
+
+ public void testExplicitCopyCleanup() throws Exception
+ {
+ URL url = getResource("/vfs/test/nested/nested.jar");
+ VirtualFile root = VFS.getRoot(url);
+ assertNotNull(root);
+
+ VirtualFile copy = modify(root);
+ assertNotNull(copy);
+ assertTrue(VFSUtils.isTemporaryFile(copy));
+
+ assertCopyMechanismFiles(1);
+
+ copy.cleanup();
+
+ assertCopyMechanismFiles(0);
+
+ root.cleanup();
+ assertNoRegistryEntry(root.toURI());
+ }
+
+ public void test3Levels() throws Exception
+ {
+ URL url = getResource("/vfs/test");
+ VFS root = VFS.getVFS(url);
+
+ VirtualFile ear = root.getChild("level1.zip");
+ VirtualFile earCopy = modify(ear);
+
+ VirtualFile l3 = ear.getChild("level2.zip/level3.zip/test3.txt");
+ assertNotNull(l3);
+ assertTempFiles(2);
+
+ VirtualFile l3copy = earCopy.getChild("level2.zip/level3.zip/test3.txt");
+ assertNotNull(l3copy);
+ assertCopyMechanismFiles(1);
+
+ earCopy.cleanup();
+
+ assertTempFiles(0);
+ assertCopyMechanismFiles(0);
+ }
+
+ public void testDirectURLUsage() throws Exception
+ {
+ URL url = getResource("/vfs/test");
+ VFS root = VFS.getVFS(url);
+
+ VirtualFile ear = root.getChild("level1.zip");
+ assertTempFiles(0);
+ VirtualFile earCopy = modify(ear);
+
+ VirtualFile l3 = earCopy.getChild("level2.zip/level3.zip/test3.txt");
+ assertNotNull(l3);
+ assertCopyMechanismFiles(1);
+
+ url = new URL(root.getRoot().toURL().toExternalForm() + "level1.zip/level2.zip/level3.zip/test3.txt");
+ VirtualFile l3url = VFS.getRoot(url);
+
+ assertEquals(l3, l3url);
+ assertTempFiles(2);
+ assertCopyMechanismFiles(1);
+
+ earCopy.cleanup();
+
+ assertCopyMechanismFiles(0);
+ }
+
+ // TODO - move this test
+ public void testTempUrls() throws Exception
+ {
+ URL url = getResource("/vfs/test");
+ String urlString = VFSUtils.stripProtocol(VFSUtils.toURI(url));
+ VFS root = VFS.getVFS(url);
+
+ VirtualFile ear = root.getChild("level1.zip");
+ VirtualFile earCopy = modify(ear);
+ assertEquals(getProtocol() + urlString + "level1.zip", earCopy.toURL().toExternalForm());
+
+ VirtualFile l2 = earCopy.getChild("level2.zip");
+ assertEquals(getProtocol() + urlString + "level1.zip/level2.zip", l2.toURL().toExternalForm());
+ VirtualFile l2sub = l2.getChild("test2.txt");
+ assertEquals(getProtocol() + urlString + "level1.zip/level2.zip/test2.txt", l2sub.toURL().toExternalForm());
+
+ VirtualFile l3 = l2.getChild("level3.zip");
+ assertEquals(getProtocol() + urlString + "level1.zip/level2.zip/level3.zip", l3.toURL().toExternalForm());
+ VirtualFile l3sub = l3.getChild("test3.txt");
+ assertEquals(getProtocol() + urlString + "level1.zip/level2.zip/level3.zip/test3.txt", l3sub.toURL().toExternalForm());
+
+ ear.cleanup();
+ }
+}
\ No newline at end of file
Property changes on: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTest.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/FileCleanupUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java 2009-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -1,295 +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.io.File;
-import java.io.IOException;
-import java.io.FilenameFilter;
-import java.lang.reflect.Field;
-import java.net.URI;
-import java.net.URL;
-
-import junit.framework.Test;
-import org.jboss.util.id.GUID;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.plugins.cache.LRUVFSCache;
-import org.jboss.virtual.plugins.copy.AbstractCopyMechanism;
-import org.jboss.virtual.spi.cache.VFSCache;
-import org.jboss.virtual.spi.cache.VFSCacheFactory;
-import org.jboss.virtual.spi.registry.VFSRegistry;
-
-/**
- * Test file closing
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class FileCleanupUnitTestCase extends AbstractVFSRegistryTest
-{
- 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();
-
- try
- {
- // 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")) + GUID.asString();
-
- tempDir = new File(tempDirString);
- tempDir.deleteOnExit();
- 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);
- }
- catch (Exception e)
- {
- super.tearDown();
- throw e;
- }
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- try
- {
- deleteTempDir();
-
- VFSCacheFactory.getInstance().stop();
- VFSCacheFactory.setInstance(null);
-
- System.clearProperty("jboss.server.temp.dir");
- }
- catch (Throwable ignored)
- {
- }
- 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();
- if (dir.exists())
- {
- assertEquals(size, files.length);
- }
- else if (size == 0)
- {
- assertNull(files);
- }
- else
- {
- fail("Illegal dir: " + dir);
- }
- }
-
- protected void assertCopyMechanismFiles(int size) throws Exception
- {
- File[] files = tempDir.listFiles(new FilenameFilter()
- {
- public boolean accept(File dir, String name)
- {
- return name.contains("vfs-nested.tmp") == false;
- }
- });
- assertNotNull(files);
- int counter = 0;
- for (File dir : files)
- {
- File[] realFiles = dir.listFiles();
- counter += realFiles.length;
- }
- assertEquals(size, counter);
- }
-
- protected void assertRegistryEntryExists(URI uri) throws Exception
- {
- VFSRegistry registry = VFSRegistry.getInstance();
- VirtualFile file = registry.getFile(uri);
- assertNotNull(file);
- }
-
- protected void assertNoRegistryEntry(URI uri) throws Exception
- {
- VFSRegistry registry = VFSRegistry.getInstance();
- VirtualFile file = registry.getFile(uri);
- assertNull("" + uri, 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();
- assertRegistryEntryExists(nestedChild.toURI());
-
- root.cleanup();
-
- assertTempFiles(0);
- assertNoRegistryEntry(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();
- assertNoRegistryEntry(root.toURI());
- }
-
- public void test3Levels() throws Exception
- {
- URL url = getResource("/vfs/test");
- VFS root = VFS.getVFS(url);
-
- VirtualFile ear = root.getChild("level1.zip");
- VirtualFile earCopy = VFSUtils.temp(ear);
-
- VirtualFile l3 = ear.getChild("level2.zip/level3.zip/test3.txt");
- assertNotNull(l3);
- assertTempFiles(2);
-
- VirtualFile l3copy = earCopy.getChild("level2.zip/level3.zip/test3.txt");
- assertNotNull(l3copy);
- assertCopyMechanismFiles(1);
-
- earCopy.cleanup();
-
- assertTempFiles(0);
- assertCopyMechanismFiles(0);
- }
-
- public void testDirectURLUsage() throws Exception
- {
- URL url = getResource("/vfs/test");
- VFS root = VFS.getVFS(url);
-
- VirtualFile ear = root.getChild("level1.zip");
- assertTempFiles(0);
- VirtualFile earCopy = VFSUtils.temp(ear);
-
- VirtualFile l3 = earCopy.getChild("level2.zip/level3.zip/test3.txt");
- assertNotNull(l3);
- assertCopyMechanismFiles(1);
-
- url = new URL(root.getRoot().toURL().toExternalForm() + "level1.zip/level2.zip/level3.zip/test3.txt");
- VirtualFile l3url = VFS.getRoot(url);
-
- assertEquals(l3, l3url);
- assertTempFiles(2);
- assertCopyMechanismFiles(1);
-
- earCopy.cleanup();
-
- assertCopyMechanismFiles(0);
- }
-
- // TODO - move this test
- public void testTempUrls() throws Exception
- {
- URL url = getResource("/vfs/test");
- String urlString = VFSUtils.stripProtocol(VFSUtils.toURI(url));
- VFS root = VFS.getVFS(url);
-
- VirtualFile ear = root.getChild("level1.zip");
- VirtualFile earCopy = VFSUtils.temp(ear);
- assertEquals("vfszip:" + urlString + "level1.zip", earCopy.toURL().toExternalForm());
-
- VirtualFile l2 = earCopy.getChild("level2.zip");
- assertEquals("vfszip:" + urlString + "level1.zip/level2.zip", l2.toURL().toExternalForm());
- VirtualFile l2sub = l2.getChild("test2.txt");
- assertEquals("vfszip:" + urlString + "level1.zip/level2.zip/test2.txt", l2sub.toURL().toExternalForm());
-
- VirtualFile l3 = l2.getChild("level3.zip");
- assertEquals("vfszip:" + urlString + "level1.zip/level2.zip/level3.zip", l3.toURL().toExternalForm());
- VirtualFile l3sub = l3.getChild("test3.txt");
- assertEquals("vfszip:" + urlString + "level1.zip/level2.zip/level3.zip/test3.txt", l3sub.toURL().toExternalForm());
-
- ear.cleanup();
- }
-}
\ No newline at end of file
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSContextUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSContextUnitTestCase.java 2009-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSContextUnitTestCase.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -33,6 +33,7 @@
* FileVFSContextUnitTestCase.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @version $Revision: 1.1 $
*/
public class FileVFSContextUnitTestCase extends AbstractVFSContextTest
@@ -83,4 +84,9 @@
{
return true;
}
+
+ protected boolean isArchive()
+ {
+ return false;
+ }
}
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java 2009-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -114,6 +114,11 @@
return false;
}
+ protected boolean isArchive()
+ {
+ return true;
+ }
+
/**
* Was having problems with a jar entry as root of VFS.
*
Added: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/TempCleanupUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/TempCleanupUnitTestCase.java (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/TempCleanupUnitTestCase.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -0,0 +1,56 @@
+/*
+ * 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 junit.framework.Test;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Test file closing - temp
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TempCleanupUnitTestCase extends FileCleanupUnitTest
+{
+ public TempCleanupUnitTestCase(String name)
+ {
+ super(name, true, true);
+ }
+
+ public static Test suite()
+ {
+ VFS.init();
+ return suite(TempCleanupUnitTestCase.class);
+ }
+
+ protected VirtualFile modify(VirtualFile original) throws Exception
+ {
+ return VFSUtils.temp(original);
+ }
+
+ protected String getProtocol()
+ {
+ return "vfszip:";
+ }
+}
\ 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-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -96,7 +96,8 @@
// exception handler
suite.addTest(ExceptionHandlerTestCase.suite());
// operations
- suite.addTest(FileCleanupUnitTestCase.suite());
+ suite.addTest(TempCleanupUnitTestCase.suite());
+ suite.addTest(ExplodeCleanupUnitTestCase.suite());
return suite;
}
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java 2009-02-03 06:14:49 UTC (rev 83794)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java 2009-02-03 06:18:59 UTC (rev 83795)
@@ -44,6 +44,7 @@
* ZipEntryVFSContextUnitTestCase.
*
* @author <a href="strukelj at parsek.net">Marko Strukelj</a>
+ * @author <a href="ales.justin at parsek.net">Ales Justin</a>
* @version $Revision: 1.0 $
*/
public class ZipEntryVFSContextUnitTestCase extends JARVFSContextUnitTestCase
@@ -203,7 +204,7 @@
/**
* Test that options are properly propagated to mounted subcontexts
*
- * @throws IOException
+ * @throws IOException for any error
*/
public void testOptionPropagation() throws IOException
{
More information about the jboss-cvs-commits
mailing list