[jboss-cvs] JBossAS SVN: r74245 - in projects/vfs/trunk/src: main/java/org/jboss/virtual/plugins and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jun 6 05:36:55 EDT 2008


Author: alesj
Date: 2008-06-06 05:36:54 -0400 (Fri, 06 Jun 2008)
New Revision: 74245

Added:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/CopyMechanism.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/ExplodedCopyMechanism.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnpackCopyMechanism.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CopyTest.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/DetachedCopyTest.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ExplodeTestCase.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/TempTestCase.java
Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.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/zip/ZipEntryContext.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnpackTestCase.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
Log:
Refactor modifications in more OO.

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java	2008-06-06 09:33:41 UTC (rev 74244)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java	2008-06-06 09:36:54 UTC (rev 74245)
@@ -21,17 +21,12 @@
 */
 package org.jboss.virtual;
 
-import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -45,10 +40,10 @@
 
 import org.jboss.logging.Logger;
 import org.jboss.util.StringPropertyReplacer;
-import org.jboss.util.id.GUID;
-import org.jboss.virtual.plugins.context.file.FileHandler;
-import org.jboss.virtual.plugins.context.file.FileSystemContext;
-import org.jboss.virtual.plugins.context.DelegatingHandler;
+import org.jboss.virtual.plugins.copy.CopyMechanism;
+import org.jboss.virtual.plugins.copy.ExplodedCopyMechanism;
+import org.jboss.virtual.plugins.copy.TempCopyMechanism;
+import org.jboss.virtual.plugins.copy.UnpackCopyMechanism;
 import org.jboss.virtual.spi.LinkInfo;
 import org.jboss.virtual.spi.VFSContext;
 import org.jboss.virtual.spi.VirtualFileHandler;
@@ -87,27 +82,6 @@
    public static final String FORCE_NO_REAPER_KEY = "jboss.vfs.forceNoReaper";
    public static final String NO_REAPER_QUERY = "noReaper";
 
-   private static File tempDir;
-
-   private static class GetTempDir implements PrivilegedAction<File>
-   {
-      public File run()
-      {
-         String tempDirKey = System.getProperty("vfs.temp.dir", "jboss.server.temp.dir");
-         return new File(System.getProperty(tempDirKey, System.getProperty("java.io.tmpdir")));
-      }
-   }
-
-   public synchronized static File getTempDirectory()
-   {
-      if (tempDir == null)
-      {
-         tempDir = AccessController.doPrivileged(new GetTempDir());
-         log.info("VFS temp dir: " + tempDir);
-      }
-      return tempDir;
-   }
-
    /**
     * Get the paths string for a collection of virtual files
     * 
@@ -498,7 +472,7 @@
     */
    public static VirtualFile unpack(VirtualFile file) throws IOException, URISyntaxException
    {
-      return createTemp(file, true);
+      return copy(file, UnpackCopyMechanism.INSTANCE);
    }
 
    /**
@@ -512,141 +486,42 @@
     */
    public static VirtualFile explode(VirtualFile file) throws IOException, URISyntaxException
    {
-      return createTemp(file, false);
+      return copy(file, ExplodedCopyMechanism.INSTANCE);
    }
 
    /**
     * Create temp.
     *
-    * @param file the file to unpack/explode
-    * @param force should we force the creation
+    * @param file the file to temp
     * @return temp file
     * @throws IOException for any io error
     * @throws URISyntaxException for any uri error
     */
-   private static VirtualFile createTemp(VirtualFile file, boolean force) throws IOException, URISyntaxException
+   public static VirtualFile temp(VirtualFile file) throws IOException, URISyntaxException
    {
-      if (file == null)
-         throw new IllegalArgumentException("Null file");
-      if (file.isLeaf())
-         return file;
-
-      VirtualFileHandler handler = file.getHandler();
-      VirtualFileHandler unwrapped = handler;
-      if (handler instanceof DelegatingHandler)
-         unwrapped = ((DelegatingHandler)handler).getDelegate();
-
-      boolean ignoreTempCreation = false;
-      if (force)
-         ignoreTempCreation = (unwrapped.isNested() == false);
-
-      if (ignoreTempCreation || unwrapped instanceof FileHandler)
-      {
-         if (log.isTraceEnabled())
-            log.trace("Should already be unpacked/exploded: " + file);
-         return file;
-      }
-
-      File guidDir = createTempDirectory(getTempDirectory(), GUID.asString());
-      File unpacked = createTempDirectory(guidDir, file.getName());
-
-      unpack(handler, unpacked, false);
-      FileSystemContext fileSystemContext = new FileSystemContext(unpacked);
-      VirtualFileHandler newHandler = fileSystemContext.getRoot();
-      VirtualFileHandler parent = handler.getParent();
-      if (parent != null && force)
-         parent.replaceChild(handler, newHandler);
-
-      return newHandler.getVirtualFile();
+      return copy(file, TempCopyMechanism.INSTANCE);
    }
 
    /**
-    * Create the temp directory.
+    * Create temp.
     *
-    * @param parent the parent
-    * @param name the dir name
-    * @return new directory
+    * @param file the file to unpack/explode
+    * @param mechanism the copy mechanism
+    * @return temp file
+    * @throws IOException for any io error
+    * @throws URISyntaxException for any uri error
     */
-   private static File createTempDirectory(File parent, String name)
+   protected static VirtualFile copy(VirtualFile file, CopyMechanism mechanism) throws IOException, URISyntaxException
    {
-      File file = new File(parent, name);
-      if (file.mkdir() == false)
-         throw new IllegalArgumentException("Cannot create directory: " + file);
-      file.deleteOnExit();
-      return file;
-   }
+      if (file == null)
+         throw new IllegalArgumentException("Null file");
+      if (mechanism == null)
+         throw new IllegalArgumentException("Null copy mechanism");
 
-   /**
-    * Unpack the root into file.
-    * Repeat this on the root's children.
-    *
-    * @param root the root
-    * @param file the file
-    * @param writeRoot do we write root
-    * @throws IOException for any error
-    */
-   private static void unpack(VirtualFileHandler root, File file, boolean writeRoot) throws IOException
-   {
-      // should we write trhe root
-      if (writeRoot)
-         rewrite(root, file);
-
-      List<VirtualFileHandler> children = root.getChildren(true);
-      if (children != null && children.isEmpty() == false)
-      {
-         for (VirtualFileHandler handler : children)
-         {
-            File next = new File(file, handler.getName());
-            if (handler.isLeaf() == false && next.mkdir() == false)
-               throw new IllegalArgumentException("Problems creating new directory: " + next);
-            next.deleteOnExit();
-
-            unpack(handler, next, handler.isLeaf());
-         }
-      }
+      return mechanism.copy(file, file.getHandler());
    }
 
    /**
-    * Rewrite contents of handler into file.
-    *
-    * @param handler the handler
-    * @param file the file
-    * @throws IOException for any error
-    */
-   private static void rewrite(VirtualFileHandler handler, File file) throws IOException
-   {
-      OutputStream out = new FileOutputStream(file);
-      InputStream in = handler.openStream();
-      try
-      {
-         byte[] bytes = new byte[1024];
-         while (in.available() > 0)
-         {
-            int length = in.read(bytes);
-            if (length > 0)
-               out.write(bytes, 0, length);
-         }
-      }
-      finally
-      {
-         try
-         {
-            in.close();
-         }
-         catch (IOException ignored)
-         {
-         }
-         try
-         {
-            out.close();
-         }
-         catch (IOException ignored)
-         {
-         }
-      }
-   }
-
-   /**
     * Is file handle nested.
     *
     * @param file the file handle to check

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	2008-06-06 09:33:41 UTC (rev 74244)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java	2008-06-06 09:36:54 UTC (rev 74245)
@@ -72,8 +72,6 @@
    public DelegatingHandler(VFSContext context, VirtualFileHandler parent, String name, VirtualFileHandler delegate)
    {
       super(context, parent, name);
-      //if (delegate == null)
-      //   throw new IllegalArgumentException("Null delegate");
       this.delegate = delegate;
    }
 
@@ -84,72 +82,83 @@
 
    public VirtualFileHandler getDelegate()
    {
+      if (delegate == null)
+         throw new IllegalArgumentException("Null delegate");
       return delegate;
    }
 
+   public VirtualFileHandler getParent() throws IOException
+   {
+      VirtualFileHandler parent = getDelegate().getParent();
+      if (parent != null)
+         return parent;
+
+      return super.getParent();
+   }
+
    public VirtualFileHandler getChild(String path) throws IOException
    {
-      return delegate.getChild(path);
+      return getDelegate().getChild(path);
    }
 
    public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
    {
-      return delegate.getChildren(ignoreErrors);
+      return getDelegate().getChildren(ignoreErrors);
    }
 
    public long getLastModified() throws IOException
    {
-      return delegate.getLastModified();
+      return getDelegate().getLastModified();
    }
 
    public long getSize() throws IOException
    {
-      return delegate.getSize();
+      return getDelegate().getSize();
    }
 
    public boolean isLeaf() throws IOException
    {
-      return delegate.isLeaf();
+      return getDelegate().isLeaf();
    }
 
    public boolean exists() throws IOException
    {
-      return delegate.exists();
+      return getDelegate().exists();
    }
 
    public boolean isHidden() throws IOException
    {
-      return delegate.isHidden();
+      return getDelegate().isHidden();
    }
 
    public boolean isNested() throws IOException
    {
-      return delegate.isNested();
+      return getDelegate().isNested();
    }
 
    public InputStream openStream() throws IOException
    {
-      return delegate.openStream();
+      return getDelegate().openStream();
    }
 
    public URI toURI() throws URISyntaxException
    {
-      return delegate.toURI();
+      return getDelegate().toURI();
    }
 
    public URL toURL() throws URISyntaxException, MalformedURLException
    {
-      return delegate.toURL();
+      return getDelegate().toURL();
    }
 
    protected void internalReplaceChild(VirtualFileHandler original, VirtualFileHandler replacement)
    {
-      delegate.replaceChild(original, replacement);
+      getDelegate().replaceChild(original, replacement);
    }
 
    public URL toVfsUrl() throws MalformedURLException, URISyntaxException
    {
-      return delegate.toVfsUrl();
+      return getDelegate().toVfsUrl();
    }
 
    public int hashCode()

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-06-06 09:33:41 UTC (rev 74244)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java	2008-06-06 09:36:54 UTC (rev 74245)
@@ -52,6 +52,7 @@
 import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
 import org.jboss.virtual.plugins.context.DelegatingHandler;
 import org.jboss.virtual.plugins.context.jar.JarUtils;
+import org.jboss.virtual.plugins.copy.AbstractCopyMechanism;
 import org.jboss.virtual.spi.VirtualFileHandler;
 
 /**
@@ -942,7 +943,7 @@
     */
    private static String getTempDir()
    {
-      File dir = new File(VFSUtils.getTempDirectory(), "vfs-nested.tmp");
+      File dir = new File(AbstractCopyMechanism.getTempDirectory(), "vfs-nested.tmp");
       return dir.toString();
    }
 

Added: 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	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java	2008-06-06 09:36:54 UTC (rev 74245)
@@ -0,0 +1,234 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.virtual.plugins.copy;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URISyntaxException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.List;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.id.GUID;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.context.file.FileSystemContext;
+import org.jboss.virtual.plugins.context.DelegatingHandler;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * Copy mechanism to be used in VFSUtils.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractCopyMechanism implements CopyMechanism
+{
+   private static Logger log = Logger.getLogger(CopyMechanism.class);
+
+   private static File tempDir;
+
+   private static class GetTempDir implements PrivilegedAction<File>
+   {
+      public File run()
+      {
+         String tempDirKey = System.getProperty("vfs.temp.dir", "jboss.server.temp.dir");
+         return new File(System.getProperty(tempDirKey, System.getProperty("java.io.tmpdir")));
+      }
+   }
+
+   /**
+    * Get temp directory.
+    *
+    * @return the temp directory
+    */
+   public synchronized static File getTempDirectory()
+   {
+      if (tempDir == null)
+      {
+         tempDir = AccessController.doPrivileged(new GetTempDir());
+         log.info("VFS temp dir: " + tempDir);
+      }
+      return tempDir;
+   }
+
+   /**
+    * Get mechanism type.
+    *
+    * @return the type
+    */
+   protected abstract String getType();
+
+   /**
+    * Is handler already modified.
+    *
+    * @param handler the handler
+    * @return true if already modified
+    * @throws IOException for any error
+    */
+   protected abstract boolean isAlreadyModified(VirtualFileHandler handler) throws IOException;
+
+   /**
+    * Should we replace old handler with new.
+    *
+    * @param parent the parent handler
+    * @param oldHandler the old handler
+    * @param newHandler the new handler
+    * @return true if needs replacement
+    * @throws IOException for any error
+    */
+   protected abstract boolean replaceOldHandler(VirtualFileHandler parent, VirtualFileHandler oldHandler, VirtualFileHandler newHandler) throws IOException;
+
+   public VirtualFile copy(VirtualFile file, VirtualFileHandler handler) throws IOException, URISyntaxException
+   {
+      VirtualFileHandler unwrapped = handler;
+      if (handler instanceof DelegatingHandler)
+         unwrapped = ((DelegatingHandler)handler).getDelegate();
+
+      // check modification on unwrapped
+      if (isAlreadyModified(unwrapped))
+      {
+         if (log.isTraceEnabled())
+            log.trace("Should already be " + getType() + ": " + unwrapped);
+         return file;
+      }
+
+      //create guid dir
+      File guidDir = createTempDirectory(getTempDirectory(), GUID.asString());
+      // unpack handler
+      File copy = copy(guidDir, handler);
+      // create new handler
+      FileSystemContext fileSystemContext = new FileSystemContext(copy);
+      VirtualFileHandler newHandler = fileSystemContext.getRoot();
+      VirtualFileHandler parent = handler.getParent();
+      if (parent != null && replaceOldHandler(parent, handler, newHandler))
+         parent.replaceChild(handler, newHandler);
+
+      return newHandler.getVirtualFile();
+   }
+
+   /**
+    * Copy handler.
+    *
+    * @param guidDir the guid directory
+    * @param handler the handler to copy
+    * @return handler's copy as file
+    * @throws IOException for any error
+    */
+   protected File copy(File guidDir, VirtualFileHandler handler) throws IOException
+   {
+      File copy = createTempDirectory(guidDir, handler.getName());
+      unpack(handler, copy, false);
+      return copy;
+   }
+
+   /**
+    * Create the temp directory.
+    *
+    * @param parent the parent
+    * @param name the dir name
+    * @return new directory
+    */
+   protected static File createTempDirectory(File parent, String name)
+   {
+      File file = new File(parent, name);
+      if (file.mkdir() == false)
+         throw new IllegalArgumentException("Cannot create directory: " + file);
+      file.deleteOnExit();
+      return file;
+   }
+
+   /**
+    * Unpack the root into file.
+    * Repeat this on the root's children.
+    *
+    * @param root the root
+    * @param file the file
+    * @param writeRoot do we write root
+    * @throws IOException for any error
+    */
+   protected static void unpack(VirtualFileHandler root, File file, boolean writeRoot) throws IOException
+   {
+      // should we write the root
+      if (writeRoot)
+         rewrite(root, file);
+
+      if (root.isLeaf() == false)
+      {
+         List<VirtualFileHandler> children = root.getChildren(true);
+         if (children != null && children.isEmpty() == false)
+         {
+            for (VirtualFileHandler handler : children)
+            {
+               File next = new File(file, handler.getName());
+               if (handler.isLeaf() == false && next.mkdir() == false)
+                  throw new IllegalArgumentException("Problems creating new directory: " + next);
+               next.deleteOnExit();
+
+               unpack(handler, next, handler.isLeaf());
+            }
+         }
+      }
+   }
+
+   /**
+    * Rewrite contents of handler into file.
+    *
+    * @param handler the handler
+    * @param file the file
+    * @throws IOException for any error
+    */
+   protected static void rewrite(VirtualFileHandler handler, File file) throws IOException
+   {
+      OutputStream out = new FileOutputStream(file);
+      InputStream in = handler.openStream();
+      try
+      {
+         byte[] bytes = new byte[1024];
+         while (in.available() > 0)
+         {
+            int length = in.read(bytes);
+            if (length > 0)
+               out.write(bytes, 0, length);
+         }
+      }
+      finally
+      {
+         try
+         {
+            in.close();
+         }
+         catch (IOException ignored)
+         {
+         }
+         try
+         {
+            out.close();
+         }
+         catch (IOException ignored)
+         {
+         }
+      }
+   }
+}
\ No newline at end of file

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/CopyMechanism.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/CopyMechanism.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/CopyMechanism.java	2008-06-06 09:36:54 UTC (rev 74245)
@@ -0,0 +1,48 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.virtual.plugins.copy;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * Copy mechanism to be used in VFSUtils.
+ * 
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface CopyMechanism
+{
+   /**
+    * Copy handler.
+    * If already modified, return handler's file.
+    *
+    * @param file the original file
+    * @param handler the handler to copy
+    * @return handler's copy
+    * @throws IOException for any error
+    * @throws URISyntaxException for any URI syntax error
+    */
+   VirtualFile copy(VirtualFile file, VirtualFileHandler handler) throws IOException, URISyntaxException;
+}

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/ExplodedCopyMechanism.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/ExplodedCopyMechanism.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/ExplodedCopyMechanism.java	2008-06-06 09:36:54 UTC (rev 74245)
@@ -0,0 +1,52 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.virtual.plugins.copy;
+
+import java.io.IOException;
+
+import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.virtual.plugins.context.file.FileHandler;
+
+/**
+ * Explode any archive into temp dir.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ExplodedCopyMechanism extends AbstractCopyMechanism
+{
+   public static final ExplodedCopyMechanism INSTANCE = new ExplodedCopyMechanism();
+
+   protected String getType()
+   {
+      return "exploded";
+   }
+
+   protected boolean isAlreadyModified(VirtualFileHandler handler) throws IOException
+   {
+      return handler instanceof FileHandler || handler.isLeaf();
+   }
+
+   protected boolean replaceOldHandler(VirtualFileHandler parent, VirtualFileHandler oldHandler, VirtualFileHandler newHandler) throws IOException
+   {
+      return false;
+   }
+}
\ No newline at end of file

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java	2008-06-06 09:36:54 UTC (rev 74245)
@@ -0,0 +1,67 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.virtual.plugins.copy;
+
+import java.io.IOException;
+import java.io.File;
+
+import org.jboss.virtual.plugins.context.jar.NestedJarHandler;
+import org.jboss.virtual.plugins.context.jar.JarHandler;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * Copy any non-temp file into temp dir.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TempCopyMechanism extends AbstractCopyMechanism
+{
+   public static final TempCopyMechanism INSTANCE = new TempCopyMechanism();
+   
+   protected String getType()
+   {
+      return "temp";
+   }
+
+   protected boolean isAlreadyModified(VirtualFileHandler handler) throws IOException
+   {
+      return handler instanceof NestedJarHandler;
+   }
+
+   protected File copy(File guidDir, VirtualFileHandler handler) throws IOException
+   {
+      // leave top level archives or leaves in one piece
+      if (handler instanceof JarHandler || handler.isLeaf())
+      {
+         File temp = new File(guidDir, handler.getName());
+         temp.deleteOnExit();
+         rewrite(handler, temp);
+         return temp;
+      }
+      return super.copy(guidDir, handler);
+   }
+
+   protected boolean replaceOldHandler(VirtualFileHandler parent, VirtualFileHandler oldHandler, VirtualFileHandler newHandler) throws IOException
+   {
+      return false;
+   }
+}
\ No newline at end of file

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnpackCopyMechanism.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnpackCopyMechanism.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnpackCopyMechanism.java	2008-06-06 09:36:54 UTC (rev 74245)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.virtual.plugins.copy;
+
+import java.io.IOException;
+
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * Unpack nested file into temp dir.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class UnpackCopyMechanism extends AbstractCopyMechanism
+{
+   public static final UnpackCopyMechanism INSTANCE = new UnpackCopyMechanism();
+   
+   protected String getType()
+   {
+      return "unpacked";
+   }
+
+   protected boolean isAlreadyModified(VirtualFileHandler handler) throws IOException
+   {
+      return handler.isNested() == false;
+   }
+
+   protected boolean replaceOldHandler(VirtualFileHandler parent, VirtualFileHandler oldHandler, VirtualFileHandler newHandler) throws IOException
+   {
+      return true;
+   }
+}
\ No newline at end of file

Copied: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CopyTest.java (from rev 74144, projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnpackTestCase.java)
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CopyTest.java	                        (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CopyTest.java	2008-06-06 09:36:54 UTC (rev 74245)
@@ -0,0 +1,204 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.net.URL;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Copy tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class CopyTest extends AbstractVFSTest
+{
+   protected CopyTest(String s)
+   {
+      super(s);
+   }
+
+   protected abstract VirtualFile modify(VirtualFile file) throws Exception;
+
+   protected void assertNoReplacement(VFS vfs, String name) throws Throwable
+   {
+      VirtualFile original = vfs.findChild(name);
+      VirtualFile replacement = modify(original);
+      assertNoReplacement(original, replacement);
+   }
+
+   protected abstract void assertNoReplacement(VirtualFile original, VirtualFile replacement) throws Exception;
+
+   public void testNoReplacement() throws Throwable
+   {
+      URL rootURL = getResource("/vfs/test");
+      VFS vfs = VFS.getVFS(rootURL);
+
+      assertNoReplacement(vfs, "unpacked-outer.jar");
+      assertNoReplacement(vfs, "jar1-filesonly.jar");
+      assertNoReplacement(vfs, "jar1-filesonly.mf");
+      assertNoReplacement(vfs, "unpacked-with-metadata.jar/META-INF");
+   }
+
+   public void testCopyOuter() throws Throwable
+   {
+      URL rootURL = getResource("/vfs/test");
+      VFS vfs = VFS.getVFS(rootURL);
+      VirtualFile original;
+      VirtualFile replacement;
+
+      original = vfs.findChild("outer.jar");
+      replacement = modify(original);
+      assertTopLevelParent(original.getParent(), replacement.getParent());
+
+      VirtualFile child = replacement.findChild("jar1.jar");
+      assertNotNull(child);
+      assertNotNull(child.findChild("META-INF/MANIFEST.MF"));
+      assertNotNull(replacement.findChild("jar2.jar"));
+   }
+
+   protected abstract void assertTopLevelParent(VirtualFile originalParent, VirtualFile replacementParent) throws Exception;
+
+   public void testUnpackTopLevel() throws Throwable
+   {
+      URL rootURL = getResource("/vfs/test");
+      VFS vfs = VFS.getVFS(rootURL);
+      VirtualFile original;
+      VirtualFile replacement;
+
+      original = vfs.findChild("level1.zip");
+      replacement = modify(original);
+      assertTopLevel(original, replacement);
+
+      VirtualFile textOne = replacement.findChild("test1.txt");
+      testText(textOne);
+      VirtualFile two = replacement.findChild("level2.zip");
+      VirtualFile textTwo = two.findChild("test2.txt");
+      testText(textTwo);
+      VirtualFile three = two.findChild("level3.zip");
+      VirtualFile textThree = three.findChild("test3.txt");
+      testText(textThree);
+   }
+
+   protected abstract void assertTopLevel(VirtualFile original, VirtualFile replacement) throws Exception;
+
+   protected abstract void assertNestedLevel(VirtualFile original, VirtualFile replacement) throws Exception;
+
+   public void testUnpack2ndLevel() throws Throwable
+   {
+      URL rootURL = getResource("/vfs/test");
+      VFS vfs = VFS.getVFS(rootURL);
+      VirtualFile original;
+      VirtualFile replacement;
+
+      original = vfs.findChild("level1.zip/level2.zip");
+      replacement = modify(original);
+      assertNestedLevel(original, replacement);
+      VirtualFile parent = original.getParent();
+      VirtualFile child = parent.findChild("level2.zip");
+      //assertEquals(replacement, child);
+      assertOnURI(child, replacement);
+
+      VirtualFile textTwo = replacement.findChild("test2.txt");
+      testText(textTwo);
+      VirtualFile three = replacement.findChild("level3.zip");
+      VirtualFile textThree = three.findChild("test3.txt");
+      testText(textThree);
+   }
+
+   public void testUnpackDeepLevel() throws Throwable
+   {
+      URL rootURL = getResource("/vfs/test");
+      VFS vfs = VFS.getVFS(rootURL);
+      VirtualFile original;
+      VirtualFile replacement;
+
+      original = vfs.findChild("level1.zip/level2.zip/level3.zip");
+      replacement = modify(original);
+      assertNestedLevel(original, replacement);
+      VirtualFile parent = original.getParent();
+      VirtualFile child = parent.findChild("level3.zip");
+      //assertEquals(replacement, child);
+      assertOnURI(child, replacement);
+
+      VirtualFile textThree = replacement.findChild("test3.txt");
+      testText(textThree);
+   }
+
+   protected void assertOnURI(VirtualFile original, VirtualFile replacement) throws Exception
+   {
+      URI originalUri = original.toURI();
+      URI replacementUri = replacement.toURI();
+      assertEquals(originalUri, replacementUri);
+   }
+
+   protected void assertUnpackedReplacement(VirtualFile original, VirtualFile replacement) throws Exception
+   {
+      assertReplacement(original, replacement);
+      assertEquals(original.getParent(), replacement.getParent());
+   }
+
+   protected void assertExplodedReplacement(VirtualFile original, VirtualFile replacement) throws Exception
+   {
+      assertReplacement(original, replacement);
+      assertNull(replacement.getParent());
+   }
+
+   protected void assertReplacement(VirtualFile original, VirtualFile replacement) throws Exception
+   {
+      assertEquals(original.getName(), replacement.getName());
+      // when mounting via DelegatingHandler, getPathName changes because VFSContext changes
+      //assertEquals(original.getPathName(), replacement.getPathName());
+
+      // it's a directory
+      if (replacement.isLeaf())
+         assertEquals(original.getSize(), replacement.getSize());
+      else
+         assertEquals(0, replacement.getSize());
+      assertEquals(original.exists(), replacement.exists());
+      assertEquals(original.isLeaf(), replacement.isLeaf());
+      assertEquals(original.isHidden(), replacement.isHidden());
+   }
+
+   protected void testText(VirtualFile file) throws Exception
+   {
+      InputStream in = file.openStream();
+      try
+      {
+         BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+         String line;
+         while ((line = reader.readLine()) != null)
+         {
+            assertEquals("Some test.", line);
+         }
+      }
+      finally
+      {
+         in.close();
+      }
+   }
+}
\ No newline at end of file

Added: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/DetachedCopyTest.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/DetachedCopyTest.java	                        (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/DetachedCopyTest.java	2008-06-06 09:36:54 UTC (rev 74245)
@@ -0,0 +1,67 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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 org.jboss.virtual.VirtualFile;
+
+/**
+ * Detached tests - no parent re-wiring.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class DetachedCopyTest extends CopyTest
+{
+   public DetachedCopyTest(String s)
+   {
+      super(s);
+   }
+
+   protected abstract boolean isSame(VirtualFile original) throws Exception;
+
+   protected void assertNoReplacement(VirtualFile original, VirtualFile replacement) throws Exception
+   {
+      if (isSame(original))
+         assertSame(original, replacement);
+      else
+         assertReplacement(original, replacement);
+   }
+
+   protected void assertTopLevel(VirtualFile original, VirtualFile replacement) throws Exception
+   {
+      assertExplodedReplacement(original, replacement);
+   }
+
+   protected void assertNestedLevel(VirtualFile original, VirtualFile replacement) throws Exception
+   {
+      assertExplodedReplacement(original, replacement);
+   }
+
+   protected void assertTopLevelParent(VirtualFile originalParent, VirtualFile replacementParent) throws Exception
+   {
+      assertNull(replacementParent);
+   }
+
+   protected void assertOnURI(VirtualFile original, VirtualFile replacement) throws Exception
+   {
+      assertReplacement(original, replacement);
+   }
+}
\ No newline at end of file

Copied: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ExplodeTestCase.java (from rev 74144, projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnpackTestCase.java)
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ExplodeTestCase.java	                        (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/ExplodeTestCase.java	2008-06-06 09:36:54 UTC (rev 74245)
@@ -0,0 +1,54 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.VirtualFile;
+import org.jboss.virtual.VFSUtils;
+
+/**
+ * Unpack tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ExplodeTestCase extends DetachedCopyTest
+{
+   public ExplodeTestCase(String s)
+   {
+      super(s);
+   }
+
+   public static Test suite()
+   {
+      return suite(ExplodeTestCase.class);
+   }
+
+   protected VirtualFile modify(VirtualFile file) throws Exception
+   {
+      return VFSUtils.explode(file);
+   }
+
+   protected boolean isSame(VirtualFile original) throws Exception
+   {
+      return original.isLeaf();
+   }
+}
\ No newline at end of file

Added: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/TempTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/TempTestCase.java	                        (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/TempTestCase.java	2008-06-06 09:36:54 UTC (rev 74245)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.VirtualFile;
+import org.jboss.virtual.VFSUtils;
+
+/**
+ * Unpack tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TempTestCase extends DetachedCopyTest
+{
+   public TempTestCase(String s)
+   {
+      super(s);
+   }
+
+   public static Test suite()
+   {
+      return suite(TempTestCase.class);
+   }
+
+   protected VirtualFile modify(VirtualFile file) throws Exception
+   {
+      return VFSUtils.temp(file);
+   }
+
+   protected boolean isSame(VirtualFile original) throws Exception
+   {
+      // should almost never be same
+      // except if file was already nested jar copy
+      return false;
+   }
+}
\ No newline at end of file

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnpackTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnpackTestCase.java	2008-06-06 09:33:41 UTC (rev 74244)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnpackTestCase.java	2008-06-06 09:36:54 UTC (rev 74245)
@@ -21,22 +21,16 @@
 */
 package org.jboss.test.virtual.test;
 
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-
 import junit.framework.Test;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VFSUtils;
 import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VFSUtils;
 
 /**
  * Unpack tests.
  *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public class UnpackTestCase extends AbstractVFSTest
+public class UnpackTestCase extends CopyTest
 {
    public UnpackTestCase(String s)
    {
@@ -48,142 +42,28 @@
       return suite(UnpackTestCase.class);
    }
 
-   protected void assertNoReplacement(VFS vfs, String name) throws Throwable
+   protected VirtualFile modify(VirtualFile file) throws Exception
    {
-      VirtualFile original = vfs.findChild(name);
-      VirtualFile replacement = VFSUtils.unpack(original);
-      assertSame(original, replacement);
+      return VFSUtils.unpack(file);
    }
 
-   public void testNoReplacement() throws Throwable
+   protected void assertNoReplacement(VirtualFile original, VirtualFile replacement) throws Exception
    {
-      URL rootURL = getResource("/vfs/test");
-      VFS vfs = VFS.getVFS(rootURL);
-
-      assertNoReplacement(vfs, "unpacked-outer.jar");
-      assertNoReplacement(vfs, "jar1-filesonly.mf");
-      assertNoReplacement(vfs, "unpacked-with-metadata.jar/META-INF");
+      assertSame(original, replacement);
    }
 
-   public void testUnpackOuter() throws Throwable
+   protected void assertTopLevel(VirtualFile original, VirtualFile replacement) throws Exception
    {
-      URL rootURL = getResource("/vfs/test");
-      VFS vfs = VFS.getVFS(rootURL);
-      VirtualFile original;
-      VirtualFile replacement;
-
-      original = vfs.findChild("outer.jar");
-      replacement = VFSUtils.unpack(original);
-      assertEquals(original.getParent(), replacement.getParent());
-
-      VirtualFile child = replacement.findChild("jar1.jar");
-      assertNotNull(child);
-      assertNotNull(child.findChild("META-INF/MANIFEST.MF"));
-      assertNotNull(replacement.findChild("jar2.jar"));
+      assertSame(original, replacement);
    }
 
-   public void testUnpackTopLevel() throws Throwable
+   protected void assertNestedLevel(VirtualFile original, VirtualFile replacement) throws Exception
    {
-      URL rootURL = getResource("/vfs/test");
-      VFS vfs = VFS.getVFS(rootURL);
-      VirtualFile original;
-      VirtualFile replacement;
-
-      original = vfs.findChild("level1.zip");
-      replacement = VFSUtils.explode(original);
-      assertExplodedReplacement(original, replacement);
-
-      VirtualFile textOne = replacement.findChild("test1.txt");
-      testText(textOne);
-      VirtualFile two = replacement.findChild("level2.zip");
-      VirtualFile textTwo = two.findChild("test2.txt");
-      testText(textTwo);
-      VirtualFile three = two.findChild("level3.zip");
-      VirtualFile textThree = three.findChild("test3.txt");
-      testText(textThree);
-   }
-
-   public void testUnpack2ndLevel() throws Throwable
-   {
-      URL rootURL = getResource("/vfs/test");
-      VFS vfs = VFS.getVFS(rootURL);
-      VirtualFile original;
-      VirtualFile replacement;
-
-      original = vfs.findChild("level1.zip/level2.zip");
-      replacement = VFSUtils.unpack(original);
       assertUnpackedReplacement(original, replacement);
-      VirtualFile parent = original.getParent();
-      VirtualFile child = parent.findChild("level2.zip");
-      //assertEquals(replacement, child);
-      assertEquals(replacement.toURI(), child.toURI());
-
-      VirtualFile textTwo = replacement.findChild("test2.txt");
-      testText(textTwo);
-      VirtualFile three = replacement.findChild("level3.zip");
-      VirtualFile textThree = three.findChild("test3.txt");
-      testText(textThree);
    }
 
-   public void testUnpackDeepLevel() throws Throwable
+   protected void assertTopLevelParent(VirtualFile originalParent, VirtualFile replacementParent) throws Exception
    {
-      URL rootURL = getResource("/vfs/test");
-      VFS vfs = VFS.getVFS(rootURL);
-      VirtualFile original;
-      VirtualFile replacement;
-
-      original = vfs.findChild("level1.zip/level2.zip/level3.zip");
-      replacement = VFSUtils.unpack(original);
-      assertUnpackedReplacement(original, replacement);
-      VirtualFile parent = original.getParent();
-      VirtualFile child = parent.findChild("level3.zip");
-      //assertEquals(replacement, child);
-      assertEquals(replacement.toURI(), child.toURI());
-
-      VirtualFile textThree = replacement.findChild("test3.txt");
-      testText(textThree);
+      assertEquals(originalParent, replacementParent);
    }
-
-   protected void assertUnpackedReplacement(VirtualFile original, VirtualFile replacement) throws Exception
-   {
-      assertReplacement(original, replacement);
-      assertEquals(original.getParent(), replacement.getParent());
-   }
-
-   protected void assertExplodedReplacement(VirtualFile original, VirtualFile replacement) throws Exception
-   {
-      assertReplacement(original, replacement);
-      assertNull(replacement.getParent());
-   }
-
-   protected void assertReplacement(VirtualFile original, VirtualFile replacement) throws Exception
-   {
-      assertEquals(original.getName(), replacement.getName());
-      // when mounting via DelegatingHandler, getPathName changes because VFSContext changes
-      //assertEquals(original.getPathName(), replacement.getPathName());
-      
-      // it's a directory
-      assertEquals(0, replacement.getSize());
-      assertEquals(original.exists(), replacement.exists());
-      assertEquals(original.isLeaf(), replacement.isLeaf());
-      assertEquals(original.isHidden(), replacement.isHidden());
-   }
-
-   protected void testText(VirtualFile file) throws Exception
-   {
-      InputStream in = file.openStream();
-      try
-      {
-         BufferedReader reader = new BufferedReader(new InputStreamReader(in));
-         String line;
-         while ((line = reader.readLine()) != null)
-         {
-            assertEquals("Some test.", line);
-         }
-      }
-      finally
-      {
-         in.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	2008-06-06 09:33:41 UTC (rev 74244)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java	2008-06-06 09:36:54 UTC (rev 74245)
@@ -77,6 +77,8 @@
       suite.addTest(PathTokensTestCase.suite());
       // unpack
       suite.addTest(UnpackTestCase.suite());
+      suite.addTest(ExplodeTestCase.suite());
+      suite.addTest(TempTestCase.suite());
       // visitor
       suite.addTest(VisitorUnitTestCase.suite());
 




More information about the jboss-cvs-commits mailing list