[jboss-cvs] JBossAS SVN: r83902 - projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 5 09:53:00 EST 2009


Author: alesj
Date: 2009-02-05 09:53:00 -0500 (Thu, 05 Feb 2009)
New Revision: 83902

Added:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/ExactCopyMechanism.java
Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.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/UnjarCopyMechanism.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnpackCopyMechanism.java
Log:
Fix temping.

Modified: 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	2009-02-05 13:57:01 UTC (rev 83901)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java	2009-02-05 14:53:00 UTC (rev 83902)
@@ -34,6 +34,7 @@
 
 import org.jboss.logging.Logger;
 import org.jboss.util.id.GUID;
+import org.jboss.util.file.JarUtils;
 import org.jboss.virtual.VFSUtils;
 import org.jboss.virtual.VirtualFile;
 import org.jboss.virtual.plugins.context.DelegatingHandler;
@@ -175,12 +176,34 @@
     */
    protected File copy(File guidDir, VirtualFileHandler handler) throws IOException
    {
-      File copy = createTempDirectory(guidDir, handler.getName());
-      unpack(handler, copy, false);
+      File copy = createCopy(guidDir, handler);
+      doCopy(copy, handler);
       return copy;
    }
 
    /**
+    * Create copy destination.
+    *
+    * @param guidDir the guid dir
+    * @param handler the handler to copy
+    * @return copy's destination
+    * @throws IOException for any error
+    */
+   protected File createCopy(File guidDir, VirtualFileHandler handler) throws IOException
+   {
+      return createTempDirectory(guidDir, handler.getName());
+   }
+
+   /**
+    * Do copy.
+    *
+    * @param copy the copy destination
+    * @param handler the handler
+    * @throws IOException for any error
+    */
+   protected abstract void doCopy(File copy, VirtualFileHandler handler) throws IOException;
+
+   /**
     * Create the temp directory.
     *
     * @param parent the parent
@@ -197,39 +220,116 @@
    }
 
    /**
+    * Exact copy.
+    *
+    * @param copy the copy dest
+    * @param root the handler to copy
+    * @throws IOException for any error
+    */
+   protected static void exactCopy(File copy, VirtualFileHandler root) throws IOException
+   {
+      unpack(copy, root, COPY);   
+   }
+
+   /**
+    * Explode the root into file.
+    *
+    * @param copy the copy dest
+    * @param root the root
+    * @throws IOException for any error
+    */
+   protected static void explode(File copy, VirtualFileHandler root) throws IOException
+   {
+      unpack(copy, root, EXPLODE);
+   }
+
+   /**
     * Unpack the root into file.
     * Repeat this on the root's children.
     *
+    * @param copy the copy dest
     * @param root the root
-    * @param file the file
-    * @param writeRoot do we write root
+    * @param checker do we write the root checker
     * @throws IOException for any error
     */
-   protected static void unpack(VirtualFileHandler root, File file, boolean writeRoot) throws IOException
+   protected static void unpack(File copy, VirtualFileHandler root, WriteRootChecker checker) throws IOException
    {
       // should we write the root
+      boolean writeRoot = checker.writeRoot(root);
+
       if (writeRoot)
-         rewrite(root, file);
+         rewrite(root, copy);
 
-      if (root.isLeaf() == false)
+      if (writeRoot == 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)
+               File next = new File(copy, handler.getName());
+               if (checker.writeRoot(handler) == false && next.mkdir() == false)
                   throw new IllegalArgumentException("Problems creating new directory: " + next);
                next.deleteOnExit();
 
-               unpack(handler, next, handler.isLeaf());
+               unpack(next, handler, checker);
             }
          }
       }
    }
 
    /**
+    * Check if we need to write the root.
+    */
+   private static interface WriteRootChecker
+   {
+      /**
+       * Do we write the root.
+       *
+       * @param handler the handler
+       * @return true if we write the root
+       * @throws IOException for any error
+       */
+      boolean writeRoot(VirtualFileHandler handler) throws IOException;
+   }
+
+   private static WriteRootChecker COPY = new WriteRootChecker()
+   {
+      public boolean writeRoot(VirtualFileHandler handler) throws IOException
+      {
+         return handler.isArchive() || handler.isLeaf();
+      }
+   };
+
+   private static WriteRootChecker EXPLODE = new WriteRootChecker()
+   {
+      public boolean writeRoot(VirtualFileHandler handler) throws IOException
+      {
+         return handler.isLeaf();
+      }
+   };
+
+   /**
+    * Unjar to copy parameter.
+    *
+    * @param copy the dest to unjar
+    * @param handler the handler to unjar
+    * @throws IOException for any error
+    */
+   protected static void unjar(File copy, VirtualFileHandler handler) throws IOException
+   {
+      InputStream in = handler.openStream();
+      try
+      {
+         JarUtils.unjar(in, copy);
+      }
+      finally
+      {
+         in.close();
+      }
+   }
+
+   /**
     * Rewrite contents of handler into file.
     *
     * @param handler the handler

Copied: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/ExactCopyMechanism.java (from rev 83550, projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnpackCopyMechanism.java)
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/ExactCopyMechanism.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/ExactCopyMechanism.java	2009-02-05 14:53:00 UTC (rev 83902)
@@ -0,0 +1,55 @@
+/*
+* 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.spi.VirtualFileHandler;
+
+/**
+ * Excat copy mechanism.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class ExactCopyMechanism extends AbstractCopyMechanism
+{
+   @Override
+   protected File createCopy(File guidDir, VirtualFileHandler handler) throws IOException
+   {
+      if (handler.isArchive() || handler.isLeaf())
+      {
+         File copy = new File(guidDir, handler.getName());
+         copy.deleteOnExit();
+         return copy;
+      }
+      else
+      {
+         return super.createCopy(guidDir, handler);
+      }
+   }
+
+   protected void doCopy(File copy, VirtualFileHandler handler) throws IOException
+   {
+      exactCopy(copy, handler);
+   }
+}
\ No newline at end of file


Property changes on: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/ExactCopyMechanism.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: 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	2009-02-05 13:57:01 UTC (rev 83901)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/ExplodedCopyMechanism.java	2009-02-05 14:53:00 UTC (rev 83902)
@@ -22,6 +22,7 @@
 package org.jboss.virtual.plugins.copy;
 
 import java.io.IOException;
+import java.io.File;
 
 import org.jboss.virtual.spi.VirtualFileHandler;
 import org.jboss.virtual.plugins.context.file.FileHandler;
@@ -45,6 +46,11 @@
       return handler instanceof FileHandler || handler.isLeaf();
    }
 
+   protected void doCopy(File copy, VirtualFileHandler handler) throws IOException
+   {
+      explode(copy, handler);
+   }
+
    protected boolean replaceOldHandler(VirtualFileHandler parent, VirtualFileHandler oldHandler, VirtualFileHandler newHandler) throws IOException
    {
       return false;

Modified: 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	2009-02-05 13:57:01 UTC (rev 83901)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java	2009-02-05 14:53:00 UTC (rev 83902)
@@ -21,7 +21,6 @@
 */
 package org.jboss.virtual.plugins.copy;
 
-import java.io.File;
 import java.io.IOException;
 
 import org.jboss.virtual.plugins.context.jar.NestedJarHandler;
@@ -32,7 +31,7 @@
  *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public class TempCopyMechanism extends AbstractCopyMechanism
+public class TempCopyMechanism extends ExactCopyMechanism
 {
    public static final TempCopyMechanism INSTANCE = new TempCopyMechanism();
    
@@ -47,20 +46,6 @@
       return handler instanceof NestedJarHandler;
    }
 
-   protected File copy(File guidDir, VirtualFileHandler handler) throws IOException
-   {
-      // leave top level archives or leaves in one piece
-      if (handler.isArchive() || 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;

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnjarCopyMechanism.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnjarCopyMechanism.java	2009-02-05 13:57:01 UTC (rev 83901)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnjarCopyMechanism.java	2009-02-05 14:53:00 UTC (rev 83902)
@@ -23,9 +23,7 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
 
-import org.jboss.util.file.JarUtils;
 import org.jboss.virtual.plugins.context.file.FileHandler;
 import org.jboss.virtual.spi.VirtualFileHandler;
 
@@ -49,20 +47,9 @@
       return handler instanceof FileHandler || handler.isLeaf();
    }
 
-   @Override
-   protected File copy(File guidDir, VirtualFileHandler handler) throws IOException
+   protected void doCopy(File copy, VirtualFileHandler handler) throws IOException
    {
-      File copy = createTempDirectory(guidDir, handler.getName());
-      InputStream in = handler.openStream();
-      try
-      {
-         JarUtils.unjar(in, copy);
-      }
-      finally
-      {
-         in.close();
-      }
-      return copy;
+      unjar(copy, handler);
    }
 
    protected boolean replaceOldHandler(VirtualFileHandler parent, VirtualFileHandler oldHandler, VirtualFileHandler newHandler) throws IOException

Modified: 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	2009-02-05 13:57:01 UTC (rev 83901)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnpackCopyMechanism.java	2009-02-05 14:53:00 UTC (rev 83902)
@@ -30,7 +30,7 @@
  *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public class UnpackCopyMechanism extends AbstractCopyMechanism
+public class UnpackCopyMechanism extends ExactCopyMechanism
 {
    public static final UnpackCopyMechanism INSTANCE = new UnpackCopyMechanism();
    




More information about the jboss-cvs-commits mailing list