[jboss-cvs] JBossAS SVN: r82811 - in projects/vfs/trunk/src: main/java/org/jboss/virtual/plugins/context/file and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jan 13 08:53:08 EST 2009


Author: alesj
Date: 2009-01-13 08:53:08 -0500 (Tue, 13 Jan 2009)
New Revision: 82811

Added:
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCloseUnitTestCase.java
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/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/zip/ZipEntryContext.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARCacheUnitTestCase.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
Log:
More initial work on JBVFS-85.
Removing FileHandler closings, as they are too specific.


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-13 13:06:39 UTC (rev 82810)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java	2009-01-13 13:53:08 UTC (rev 82811)
@@ -179,8 +179,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 +211,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)
    {

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-13 13:06:39 UTC (rev 82810)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java	2009-01-13 13:53:08 UTC (rev 82811)
@@ -153,7 +153,21 @@
    @Override
    public void close()
    {
-      getDelegate().close();
+      if (delegate == null)
+         return;
+
+      if (delegate instanceof AbstractVirtualFileHandler)
+      {
+         if (decrement() == 0)
+         {
+            AbstractVirtualFileHandler avfh = AbstractVirtualFileHandler.class.cast(delegate);
+            avfh.doClose();
+         }
+      }
+      else
+      {
+         delegate.close();
+      }
    }
 
    public boolean delete(int gracePeriod) throws IOException

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-13 13:06:39 UTC (rev 82810)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileHandler.java	2009-01-13 13:53:08 UTC (rev 82811)
@@ -337,25 +337,12 @@
 
    public boolean removeChild(String name) throws IOException
    {
-      VirtualFileHandler fileHandler = childCache.remove(name);
-      if (fileHandler != null)
-      {
-         fileHandler.close();
-         return true;
-      }
-      else
-      {
-         return false;
-      }
+      return (childCache.remove(name) != null);
    }
 
    protected void internalReplaceChild(VirtualFileHandler original, VirtualFileHandler replacement)
    {
-      VirtualFileHandler previousHandler = childCache.put(original.getName(), replacement);
-      if (previousHandler != null)
-      {
-         previousHandler.close();
-      }
+      childCache.put(original.getName(), replacement);
    }
 
    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException

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-13 13:06:39 UTC (rev 82810)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java	2009-01-13 13:53:08 UTC (rev 82811)
@@ -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
     *
@@ -491,6 +495,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 +531,7 @@
 
                entries.put(delegator.getLocalPathName(), new EntryInfo(delegator, ent));
                addChild(parent, delegator);
+               nestedHandlers.add(delegator); // add nested delegator
             }
             else
             {
@@ -802,6 +808,11 @@
       if (rootHandler.equals(handler))
       {
          getZipSource().close();
+         // only close nested - as they might be temp files we want to delete
+         for (VirtualFileHandler vfh : nestedHandlers)
+         {
+            vfh.close();
+         }
       }
    }
 

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-13 13:06:39 UTC (rev 82810)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java	2009-01-13 13:53:08 UTC (rev 82811)
@@ -116,7 +116,7 @@
 
    public boolean exists() throws IOException
    {
-//      checkClosed(); // TODO - this fails with JBVFS-85 check
+      checkClosed();
       return getZipEntryContext().exists(this);
    }
 

Copied: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCloseUnitTestCase.java (from rev 82798, projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARCacheUnitTestCase.java)
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCloseUnitTestCase.java	                        (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCloseUnitTestCase.java	2009-01-13 13:53:08 UTC (rev 82811)
@@ -0,0 +1,68 @@
+/*
+ * 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();
+      child.close();
+      root.close();
+   }
+}
\ No newline at end of file


Property changes on: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCloseUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARCacheUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARCacheUnitTestCase.java	2009-01-13 13:06:39 UTC (rev 82810)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARCacheUnitTestCase.java	2009-01-13 13:53:08 UTC (rev 82811)
@@ -102,15 +102,12 @@
       }
       
       // Verify the manifest the VFS way
-      // TODO - JBVFS-85 check
-/*
       {
          VirtualFile manifestFile = vf.findChild("META-INF/MANIFEST.MF");
          Manifest manifest = new Manifest(manifestFile.openStream());
          String actual = manifest.getMainAttributes().getValue("test");
          assertEquals("VFS found the wrong manifest", "v2", actual);
       }
-*/
 
       // Verify again - through new context
       {

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-13 13:06:39 UTC (rev 82810)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java	2009-01-13 13:53:08 UTC (rev 82811)
@@ -95,6 +95,8 @@
       suite.addTest(CombinedVFSCacheTestCase.suite());
       // exception handler
       suite.addTest(ExceptionHandlerTestCase.suite());
+      // operations
+      suite.addTest(FileCloseUnitTestCase.suite());
 
       return suite;
    }




More information about the jboss-cvs-commits mailing list