[jboss-cvs] JBossAS SVN: r81338 - 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
Wed Nov 19 19:15:22 EST 2008


Author: mstruk
Date: 2008-11-19 19:15:21 -0500 (Wed, 19 Nov 2008)
New Revision: 81338

Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java
Log:
JBVFS-81 Lazy init of FileWrapper so that options can be set on super context and used when subcontexts are fully initialized

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	2008-11-19 22:55:52 UTC (rev 81337)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java	2008-11-20 00:15:21 UTC (rev 81338)
@@ -115,6 +115,9 @@
    /** Entry path representing a context root - archive root is not necessarily a context root */
    private String rootEntryPath = "";
 
+   /** path to zip file - used for lazy ZipWrapper initialization */
+   private String filePath = null;
+
    /** AutoClean signals if zip archive should be deleted after closing the context - true for nested archives */
    private boolean autoClean = false;
 
@@ -219,8 +222,7 @@
             throw new IllegalArgumentException("No ZipWrapper specified and localRootURL is null");
 
          // initialize rootEntryPath and get archive file path
-         String rootPath = initRootAndPath(localRootURL);
-         zipSource = createZipSource(rootPath);
+         filePath = initRootAndPath(localRootURL);
       }
       else
       {
@@ -251,8 +253,31 @@
       //initEntries();
    }
 
-   public Map<String, String> getOptions()
+   protected synchronized ZipWrapper getZipSource()
    {
+      if (zipSource == null)
+         try
+         {
+            zipSource = createZipSource(filePath);
+         }
+         catch (IOException e)
+         {
+            throw new RuntimeException("Failed to initialize ZipWrapper: " + filePath, e);
+         }
+
+      return zipSource;
+   }
+
+   /**
+    * Returns aggregated options.
+    *
+    * If peer exists, it uses peer context's options as a basis,
+    * and overrides them with this context's options.
+    *
+    * @return map containing aggregated options
+    */
+   public Map<String, String> getAggregatedOptions()
+   {
       Map<String, String> options = new HashMap<String, String>();
       VFSContext peerContext = getPeerContext();
       if (peerContext != null)
@@ -318,7 +343,7 @@
       }
       else
       {
-         boolean noReaper = Boolean.valueOf(getOptions().get(VFSUtils.NO_REAPER_QUERY));
+         boolean noReaper = Boolean.valueOf(getAggregatedOptions().get(VFSUtils.NO_REAPER_QUERY));
          realURL = urlInfo.toURL();
          return new ZipFileWrapper(file, autoClean, noReaper);
       }
@@ -409,7 +434,7 @@
       if (peer != null)
          return peer.getName();
       else
-         return zipSource.getName();
+         return getZipSource().getName();
    }
 
    /**
@@ -425,6 +450,7 @@
       // this way we ensure that parent entries are processed before child entries
 
       Map<String, ZipEntry> relevant = new HashMap<String, ZipEntry>();
+      ZipWrapper zipSource = getZipSource();
       zipSource.acquire();
       try
       {
@@ -463,7 +489,7 @@
                boolean useCopyMode = forceCopy;
                if (useCopyMode == false)
                {
-                  String flag = getOptions().get(VFSUtils.USE_COPY_QUERY);
+                  String flag = getAggregatedOptions().get(VFSUtils.USE_COPY_QUERY);
                   useCopyMode = Boolean.valueOf(flag);
                }
 
@@ -525,9 +551,9 @@
       {
          ExceptionHandler eh = getExceptionHandler();
          if (eh != null)
-            eh.handleZipEntriesInitException(ex, zipSource.getName());
+            eh.handleZipEntriesInitException(ex, getZipSource().getName());
          else
-            throw new RuntimeException("Failed to read zip file: " + zipSource, ex);
+            throw new RuntimeException("Failed to read zip file: " + getZipSource(), ex);
       }
       finally
       {
@@ -659,13 +685,13 @@
       {
          ensureEntries();
       }
-      else if (initStatus == InitializationStatus.INITIALIZED && zipSource.hasBeenModified())
+      else if (initStatus == InitializationStatus.INITIALIZED && getZipSource().hasBeenModified())
       {
          EntryInfo rootInfo = entries.get("");
          entries = new ConcurrentHashMap<String, EntryInfo>();
          entries.put("", rootInfo);
 
-         if (zipSource.exists())
+         if (getZipSource().exists())
          {
             try
             {
@@ -755,7 +781,7 @@
     */
    public boolean delete(ZipEntryHandler handler, int gracePeriod) throws IOException
    {
-      return getRoot().equals(handler) && zipSource.delete(gracePeriod);
+      return getRoot().equals(handler) && getZipSource().delete(gracePeriod);
    }
 
    /**
@@ -776,7 +802,7 @@
          return 0;
 
       if(ei.entry == null) {
-         return zipSource.getLastModified();
+         return getZipSource().getLastModified();
       }
 
       return ei.entry.getTime();
@@ -794,7 +820,7 @@
          throw new IllegalArgumentException("Null handler");
 
       if(getRoot().equals(handler))
-         return zipSource.getSize();
+         return getZipSource().getSize();
 
       checkIfModified();
 
@@ -817,7 +843,7 @@
          throw new IllegalArgumentException("Null handler");
 
       if (getRoot().equals(handler))
-         return zipSource.exists();
+         return getZipSource().exists();
 
       checkIfModified();
       EntryInfo ei = entries.get(handler.getLocalPathName());
@@ -918,7 +944,7 @@
          throw new IllegalArgumentException("Null handler");
 
       if (getRoot().equals(handler))
-         return zipSource.getRootAsStream();
+         return getZipSource().getRootAsStream();
 
       checkIfModified();
 
@@ -941,7 +967,7 @@
       if(ei.entry == null)
          return new ByteArrayInputStream(new byte[0]);
 
-      return zipSource.openStream(ei.entry);
+      return getZipSource().openStream(ei.entry);
    }
 
    /**
@@ -1029,6 +1055,9 @@
     */
    public URL getRealURL()
    {
+      // make sure realURL has been initialized
+      // realURL is initialized when ZipSource is initialized
+      getZipSource();
       return realURL;
    }
 

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	2008-11-19 22:55:52 UTC (rev 81337)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java	2008-11-20 00:15:21 UTC (rev 81338)
@@ -26,12 +26,14 @@
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.IOException;
 import java.net.URL;
 import java.util.List;
 
 import junit.framework.Test;
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
 import org.jboss.virtual.plugins.context.file.FileSystemContext;
 import org.jboss.virtual.plugins.context.jar.JarUtils;
 import org.jboss.virtual.plugins.context.zip.ZipEntryContext;
@@ -199,6 +201,29 @@
    }
 
    /**
+    * Test that options are properly propagated to mounted subcontexts
+    *
+    * @throws IOException
+    */
+   public void testOptionPropagation() throws IOException
+   {
+      // jar:file: url test
+      URL url = getResource("/vfs/test/level1.zip");
+      VFS vfs = VFS.getVFS(new URL("jar:file:" + url.getPath() + "!/"));
+      VFSUtils.enableNoReaper(vfs);
+
+      VirtualFile vf = vfs.getChild("level2.zip/level3.zip");
+      assertEquals("jar:file: option propagation", VFSUtils.getOption(vf, VFSUtils.NO_REAPER_QUERY), "true");
+
+      // vfszip: url test
+      vfs = VFS.getVFS(new URL("vfszip:" + url.getPath()));
+      VFSUtils.enableNoReaper(vfs);
+
+      vf = vfs.getChild("level2.zip/level3.zip");
+      assertEquals("vfszip: option propagation", VFSUtils.getOption(vf, VFSUtils.NO_REAPER_QUERY), "true");
+   }
+
+   /**
     * Handler representing a directory must return a recomposed zip archive
     * that has requested entry as its root.
     *




More information about the jboss-cvs-commits mailing list