[jboss-cvs] JBossAS SVN: r81222 - in projects/vfs/trunk/src: test/java/org/jboss/test/virtual/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Nov 18 08:22:28 EST 2008


Author: alesj
Date: 2008-11-18 08:22:28 -0500 (Tue, 18 Nov 2008)
New Revision: 81222

Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
Log:
Make root creation lazy.

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java	2008-11-18 13:03:52 UTC (rev 81221)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java	2008-11-18 13:22:28 UTC (rev 81222)
@@ -86,11 +86,14 @@
          log.debug("VFS forced case sensitivity is enabled.");
    }
 
+   /** The temp file */
+   private transient File file;
+
    /** The root file */
-   private final VirtualFileHandler root;
+   private VirtualFileHandler root;
    
    /** A reference to the virtual file of the root to stop it getting closed */
-   private final VirtualFile rootFile;
+   private VirtualFile rootFile;
    
    /**
     * Get the file for a url
@@ -193,12 +196,7 @@
    private FileSystemContext(URI rootURI, File file) throws IOException
    {
       super(rootURI);
-      root = createVirtualFileHandler(null, file);
-      if (root == null)
-         throw new java.io.FileNotFoundException((file == null ? "null" : file.getName())
-                 + " doesn't exist. (rootURI: " + rootURI + ", file: " + file + ")");
-
-      rootFile = root.getVirtualFile();
+      this.file = file;
    }
 
    public String getName()
@@ -208,6 +206,16 @@
 
    public VirtualFileHandler getRoot() throws IOException
    {
+      if (root == null)
+      {
+         root = createVirtualFileHandler(null, file);
+         if (root == null)
+            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;
    }
 

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java	2008-11-18 13:03:52 UTC (rev 81221)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java	2008-11-18 13:22:28 UTC (rev 81222)
@@ -1608,15 +1608,16 @@
    {
       File tmpRoot = File.createTempFile("vfs", ".root");
       VFS vfs = VFS.getVFS(tmpRoot.toURL());
+      VirtualFile root = vfs.getRoot();
 
       // non-existent directory - exists() not
       tmpRoot.delete();
-      assertFalse(tmpRoot + ".exits() == false", vfs.getRoot().exists());
+      assertFalse(tmpRoot + ".exits() == false", root.exists());
 
       // existing directory - exists(), delete()
       tmpRoot.mkdir();
-      assertTrue(tmpRoot + ".exits()", vfs.getRoot().exists());
-      assertTrue(tmpRoot + ".delete()", vfs.getRoot().delete());
+      assertTrue(tmpRoot + ".exits()", root.exists());
+      assertTrue(tmpRoot + ".delete()", root.delete());
       tmpRoot.mkdir();
 
       // non-empty directory - delete()
@@ -1648,7 +1649,7 @@
       assertNull(tmpRoot + ".getChild('" + tmp.getName() + "') == null", tmpVF);
 
       // directory delete()
-      assertTrue(tmpRoot + ".delete()", vfs.getRoot().delete());
+      assertTrue(tmpRoot + ".delete()", root.delete());
    }
 
    /**




More information about the jboss-cvs-commits mailing list