[jboss-cvs] JBossAS SVN: r94992 - in projects/jboss-deployers/branches/vfs3: deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 15 20:15:31 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-10-15 20:15:30 -0400 (Thu, 15 Oct 2009)
New Revision: 94992

Modified:
   projects/jboss-deployers/branches/vfs3/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/AbstractStructureDeployer.java
   projects/jboss-deployers/branches/vfs3/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/war/WARStructure.java
Log:
Initial gesture towards a proper WAR structure deployer

Modified: projects/jboss-deployers/branches/vfs3/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/war/WARStructure.java
===================================================================
--- projects/jboss-deployers/branches/vfs3/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/war/WARStructure.java	2009-10-15 21:56:35 UTC (rev 94991)
+++ projects/jboss-deployers/branches/vfs3/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/war/WARStructure.java	2009-10-16 00:15:30 UTC (rev 94992)
@@ -22,8 +22,10 @@
 package org.jboss.deployers.vfs.plugins.structure.war;
 
 import java.io.IOException;
+import java.io.Closeable;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.ScheduledExecutorService;
 
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.structure.ContextInfo;
@@ -32,7 +34,11 @@
 import org.jboss.vfs.VirtualFile;
 import org.jboss.vfs.VirtualFileFilter;
 import org.jboss.vfs.VisitorAttributes;
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.TempFileProvider;
+import org.jboss.vfs.VFSUtils;
 import org.jboss.vfs.util.SuffixMatchFilter;
+import org.jboss.logging.Logger;
 
 /**
  * WARStructure.
@@ -54,6 +60,7 @@
 
    /** Whether to include web-inf in the classpath */
    private boolean includeWebInfInClasspath;
+   private ScheduledExecutorService scheduledExecutorService;
 
    /**
     * Sets the default relative order 1000.
@@ -65,6 +72,26 @@
    }
 
    /**
+    * Get the scheduled executor service.
+    *
+    * @return the scheduled executor service
+    */
+   public ScheduledExecutorService getScheduledExecutorService()
+   {
+      return scheduledExecutorService;
+   }
+
+   /**
+    * Set the scheduled executor service.
+    *
+    * @param scheduledExecutorService the scheduled executor service
+    */
+   public void setScheduledExecutorService(final ScheduledExecutorService scheduledExecutorService)
+   {
+      this.scheduledExecutorService = scheduledExecutorService;
+   }
+
+   /**
     * Get the webInfLibFilter.
     *
     * @return the webInfLibFilter.
@@ -119,82 +146,89 @@
 
    public boolean determineStructure(StructureContext structureContext) throws DeploymentException
    {
-      ContextInfo context = null;
+      boolean ok = false;
       VirtualFile file = structureContext.getFile();
-      try
-      {
-         boolean trace = log.isTraceEnabled();
+      final Logger log = WARStructure.log;
+      boolean trace = log.isTraceEnabled();
 
-         // the WEB-INF
-         VirtualFile webinf = null;
-
-         if (isLeaf(file) == false)
+      // the WEB-INF
+      final List<Closeable> handles = new ArrayList<Closeable>();
+      if (! file.isDirectory()) try {
+         handles.add(VFS.mountZipExpanded(file, file, TempFileProvider.create(file.getName(), scheduledExecutorService)));
+      } catch (IOException e) {
+         DeploymentException.rethrowAsDeploymentException("Failed to mount WAR archive", e);
+      }
+      try {
+         final VirtualFile webinf = file.getChild("WEB-INF");
+         if (file.getName().endsWith(".war") == false)
          {
-            // We require either a WEB-INF or the name ends in .war
-            if (file.getName().endsWith(".war") == false)
+            if (webinf.exists())
             {
-               webinf = file.getChild("WEB-INF");
-               if (webinf != null)
-               {
-                  if (trace)
-                     log.trace("... ok - directory has a WEB-INF subdirectory");
-               }
-               else
-               {
-                  if (trace)
-                     log.trace("... no - doesn't look like a war and no WEB-INF subdirectory.");
-                  return false;
-               }
+               if (trace)
+                  log.trace("... ok - directory has a WEB-INF subdirectory");
             }
-            else if (trace)
+            else
             {
-               log.trace("... ok - name ends in .war.");
+               if (trace)
+                  log.trace("... no - doesn't look like a war and no WEB-INF subdirectory.");
+               return false;
             }
-
-            List<String> metaDataLocations = new ArrayList<String>();
-            metaDataLocations.add("WEB-INF");
-
-            // Check for WEB-INF/classes
-            VirtualFile classes = null;
-            // The classpath contains WEB-INF/classes
-            classes = file.getChild("WEB-INF/classes");
-            // Check for a META-INF for metadata
-            if (classes != null)
-               metaDataLocations.add("WEB-INF/classes/META-INF");
-            // Check for jars in WEB-INF/lib
-            List<VirtualFile> archives = null;
+         }
+         else if (trace)
+         {
+            log.trace("... ok - name ends in .war.");
+         }
+         List<String> metaDataLocations = new ArrayList<String>();
+         metaDataLocations.add("WEB-INF");
+         // Check for WEB-INF/classes
+         final VirtualFile classes = file.getChild("WEB-INF/classes");
+         // Check for a META-INF for metadata
+         if (classes.isDirectory())
+         {
+            metaDataLocations.add("WEB-INF/classes/META-INF");
+         }
+         // Check for jars in WEB-INF/lib
+         List<VirtualFile> archives = null;
+         final VirtualFile webinfLib = file.getChild("WEB-INF/lib");
+         if (webinfLib.isDirectory())
+         {
             try
             {
-               VirtualFile webinfLib = file.getChild("WEB-INF/lib");
-               if (webinfLib != null)
+               archives = webinfLib.getChildren(webInfLibFilter);
+               // Add the jars' META-INF for metadata
+               for (VirtualFile jar : archives)
                {
-                  archives = webinfLib.getChildren(webInfLibFilter);
-                  // Add the jars' META-INF for metadata
-                  for (VirtualFile jar : archives)
-                  {
-                     // either same as plain lib filter, null or accepts the jar
-                     if (webInfLibMetaDataFilter == null || webInfLibMetaDataFilter == webInfLibFilter || webInfLibMetaDataFilter.accepts(jar))
-                        metaDataLocations.add("WEB-INF/lib/" + jar.getName() + "/META-INF");
+                  // mount up the JAR if it is an archive
+                  // todo - is it a fatal error if the mount fails, or should we just skip the entry?
+                  if (! jar.isDirectory()) {
+                     try {
+                        handles.add(VFS.mountZip(jar, jar, TempFileProvider.create(jar.getName(), scheduledExecutorService)));
+                     } catch (IOException e) {
+                        log.warn("Failed to mount file " + jar.getName() + ": " + e);
+                        // try the next one
+                        continue;
+                     }
                   }
+                  // either same as plain lib filter, null or accepts the jar
+                  if (webInfLibMetaDataFilter == null || webInfLibMetaDataFilter == webInfLibFilter || webInfLibMetaDataFilter.accepts(jar))
+                     metaDataLocations.add("WEB-INF/lib/" + jar.getName() + "/META-INF");
                }
             }
             catch (IOException e)
             {
                log.warn("Exception looking for WEB-INF/lib, " + file.getPathName() + ", " + e);
             }
-
-            // Create a context for this war file and all its metadata locations
-            context = createContext(structureContext, metaDataLocations.toArray(new String[metaDataLocations.size()]));
-
+         }
+         // Create a context for this war file and all its metadata locations
+         final ContextInfo context = createContext(structureContext, metaDataLocations.toArray(new String[metaDataLocations.size()]));
+         try {
             // Add the war manifest classpath entries
             addClassPath(structureContext, file, false, true, context);
-
             // Add WEB-INF/classes if present
             if (classes != null)
                addClassPath(structureContext, classes, true, false, context);
             else if (trace)
                log.trace("No WEB-INF/classes for: " + file.getPathName());
-
             // and the top level jars in WEB-INF/lib
             if (archives != null)
             {
@@ -205,30 +239,24 @@
             {
                log.trace("No WEB-INF/lib for: " + file.getPathName());
             }
-
             // do we include WEB-INF in classpath
             if (includeWebInfInClasspath && webinf != null)
             {
                addClassPath(structureContext, webinf, true, false, context);
             }
-
             // There are no subdeployments for wars
-            return true;
+            return ok = true;
+         } finally {
+            if (! ok) {
+               // Remove the invalid context
+               structureContext.removeChild(context);
+            }
          }
-         else
-         {
-            if (trace)
-               log.trace("... no - not a directory or an archive.");
-            return false;
+      } finally {
+         if (! ok) {
+            // Undo all mounts
+            VFSUtils.safeClose(handles);
          }
       }
-      catch (Exception e)
-      {
-         // Remove the invalid context
-         if (context != null)
-            structureContext.removeChild(context);
-
-         throw DeploymentException.rethrowAsDeploymentException("Error determining structure: " + file.getName(), e);
-      }
    }
 }

Modified: projects/jboss-deployers/branches/vfs3/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/AbstractStructureDeployer.java
===================================================================
--- projects/jboss-deployers/branches/vfs3/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/AbstractStructureDeployer.java	2009-10-15 21:56:35 UTC (rev 94991)
+++ projects/jboss-deployers/branches/vfs3/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/AbstractStructureDeployer.java	2009-10-16 00:15:30 UTC (rev 94992)
@@ -56,7 +56,7 @@
 public abstract class AbstractStructureDeployer implements StructureDeployer
 {
    /** The log */
-   protected Logger log = Logger.getLogger(getClass());
+   protected static final Logger log = Logger.getLogger("org.jboss.deployers.vfs.structure");
    
    /** The relative order */
    private int relativeOrder = Integer.MAX_VALUE;
@@ -221,7 +221,7 @@
     * @param context - the context to populate
     * @throws IOException on any IO error
     */
-   protected void addClassPath(StructureContext structureContext, VirtualFile entry, boolean includeEntry, boolean includeRootManifestCP, ContextInfo context) throws IOException
+   protected void addClassPath(StructureContext structureContext, VirtualFile entry, boolean includeEntry, boolean includeRootManifestCP, ContextInfo context)
    {
       boolean trace = log.isTraceEnabled();
       
@@ -232,7 +232,7 @@
          paths.add(entry);
 
       // Add the manifest locations
-      if (includeRootManifestCP && isLeaf(entry) == false)
+      if (includeRootManifestCP && entry.isDirectory())
       {
          try
          {




More information about the jboss-cvs-commits mailing list