[jboss-cvs] JBossAS SVN: r76567 - in projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading: spi/vfs/dependency and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 1 07:42:05 EDT 2008


Author: alesj
Date: 2008-08-01 07:42:05 -0400 (Fri, 01 Aug 2008)
New Revision: 76567

Modified:
   projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java
   projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java
Log:
Optimize on matching.

Modified: projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java	2008-08-01 11:24:58 UTC (rev 76566)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java	2008-08-01 11:42:05 UTC (rev 76567)
@@ -21,6 +21,8 @@
  */
 package org.jboss.classloading.plugins.vfs;
 
+import java.net.URL;
+
 import org.jboss.classloader.spi.filter.ClassFilter;
 import org.jboss.classloading.spi.visitor.ResourceContext;
 import org.jboss.classloading.spi.visitor.ResourceFilter;
@@ -84,16 +86,20 @@
     * @param visitor the visitor
     * @param filter the filter
     * @param recurseFilter the recurse filter
+    * @param urls the urls
     */
-   public static void visit(VirtualFile[] roots, VirtualFile[] excludedRoots, ClassFilter included, ClassFilter excluded, ClassLoader classLoader, ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter)
+   public static void visit(VirtualFile[] roots, VirtualFile[] excludedRoots, ClassFilter included, ClassFilter excluded, ClassLoader classLoader, ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter, URL... urls)
    {
       VFSResourceVisitor vfsVisitor = new VFSResourceVisitor(roots, excludedRoots, included, excluded, classLoader, visitor, filter, recurseFilter);
       for (VirtualFile root : roots)
       {
          try
          {
-            vfsVisitor.setRoot(root);
-            root.visit(vfsVisitor);
+            if (urls == null || urls.length == 0 || matchRootWithUrls(root, urls))
+            {
+               vfsVisitor.setRoot(root);
+               root.visit(vfsVisitor);
+            }
          }
          catch (Exception e)
          {
@@ -103,6 +109,27 @@
    }
 
    /**
+    * Match root with urls.
+    *
+    * @param root one of the roots
+    * @param urls the urls
+    * @return true if root matches one of the urls
+    * @throws Exception for any error
+    */
+   protected static boolean matchRootWithUrls(VirtualFile root, URL[] urls) throws Exception
+   {
+      URL rootURL = root.toURL();
+      for (URL url : urls)
+      {
+         if (rootURL.equals(url))
+         {
+            return true;
+         }
+      }
+      return false;
+   }
+
+   /**
     * Create a new VFSResourceVisitor.
     *
     * @param roots the roots

Modified: projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java	2008-08-01 11:24:58 UTC (rev 76566)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java	2008-08-01 11:42:05 UTC (rev 76567)
@@ -23,7 +23,6 @@
 
 import java.net.URI;
 import java.net.URL;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -225,47 +224,9 @@
       VirtualFile[] roots = determineVFSRoots();
       if (roots != null && roots.length > 0)
       {
-         if (urls != null && urls.length > 0)
-            roots = matchUrlsWithRoots(urls, roots);
-
-         if (roots != null && roots.length > 0)
-         {
-            ClassFilter included = getIncluded();
-            ClassFilter excluded = getExcluded();
-            VFSResourceVisitor.visit(roots, null, included, excluded, classLoader, visitor, filter, recurseFilter);
-         }
+         ClassFilter included = getIncluded();
+         ClassFilter excluded = getExcluded();
+         VFSResourceVisitor.visit(roots, null, included, excluded, classLoader, visitor, filter, recurseFilter, urls);
       }
    }
-
-   /**
-    * Match urls with roots.
-    *
-    * @param urls the urls
-    * @param roots the old roots
-    * @return new roots
-    */
-   protected static VirtualFile[] matchUrlsWithRoots(URL[] urls, VirtualFile[] roots)
-   {
-      try
-      {
-         List<VirtualFile> newRoots = new ArrayList<VirtualFile>(roots.length);
-         for (VirtualFile root : roots)
-         {
-            URL rootURL = root.toURL();
-            for (URL url : urls)
-            {
-               if (rootURL.equals(url))
-               {
-                  newRoots.add(root);
-                  break;
-               }
-            }
-         }
-         return newRoots.toArray(new VirtualFile[newRoots.size()]);
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException("Cannot match urls to roots.", e);
-      }
-   }
 }




More information about the jboss-cvs-commits mailing list