[jboss-cvs] JBossAS SVN: r78929 - in projects/jboss-cl/branches/Branch_2_0/classloading/src: test/java/org/jboss/test/classloading/dependency/support and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Sep 29 10:37:49 EDT 2008


Author: alesj
Date: 2008-09-29 10:37:48 -0400 (Mon, 29 Sep 2008)
New Revision: 78929

Modified:
   projects/jboss-cl/branches/Branch_2_0/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoaderPolicyModule.java
   projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/MockFilteredResourceVisitor.java
   projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/MockResourceVisitor.java
   projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/test/MockResourceVisitorUnitTestCase.java
Log:
Port JBCL-32 to 2_0 branch.

Modified: projects/jboss-cl/branches/Branch_2_0/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoaderPolicyModule.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoaderPolicyModule.java	2008-09-29 13:23:25 UTC (rev 78928)
+++ projects/jboss-cl/branches/Branch_2_0/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoaderPolicyModule.java	2008-09-29 14:37:48 UTC (rev 78929)
@@ -21,7 +21,9 @@
 */
 package org.jboss.classloading.spi.dependency.policy.mock;
 
+import java.io.File;
 import java.net.URL;
+import java.net.URISyntaxException;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -92,6 +94,24 @@
       return classLoader.getResource(path);
    }
 
+   /**
+    * Get file from path's url.
+    *
+    * @param url the path's url
+    * @return path's file
+    */
+   protected File getFile(URL url)
+   {
+      try
+      {
+         return new File(url.toURI());
+      }
+      catch (URISyntaxException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
    public void visit(ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter, URL... urls)
    {
       MockClassLoadingMetaData mclmd = getClassLoadingMetaData();
@@ -109,22 +129,81 @@
 
          for (String path : paths)
          {
-            if (included.isEmpty() == false && included.contains(path) == false)
-               continue;
-            if (includedFilter != null && includedFilter.matchesResourcePath(path) == false)
-               continue;
-            if (excluded.isEmpty() == false && excluded.contains(path))
-               continue;
-            if (excludedFilter != null && excludedFilter.matchesResourcePath(path))
-               continue;
+            visitPath(null, path, visitor, filter, classLoader, included, includedFilter, excluded, excludedFilter);
+         }
+      }
+   }
 
-            ResourceContext context = new DefaultResourceContext(getURL(path), path, classLoader);
-            if (filter == null || filter.accepts(context))
-               visitor.visit(context);
+   /**
+    * Visit path.
+    *
+    * @param file the current path file
+    * @param path the path
+    * @param visitor the visitor
+    * @param filter the filter
+    * @param classLoader the classloader
+    * @param included the included
+    * @param includedFilter the included filter
+    * @param excluded the excluded
+    * @param excludedFilter the excluded filter
+    */
+   protected void visitPath(File file, String path, ResourceVisitor visitor, ResourceFilter filter, ClassLoader classLoader, Collection<String> included, ClassFilter includedFilter, Collection<String> excluded, ClassFilter excludedFilter)
+   {
+      boolean visit = includePath(path, included, includedFilter, excluded, excludedFilter);
+
+      URL url = getURL(path);
+      
+      if (visit)
+      {
+         ResourceContext context = new DefaultResourceContext(url, path, classLoader);
+         if (filter == null || filter.accepts(context))
+            visitor.visit(context);
+      }
+
+      if (file == null)
+         file = getFile(url);
+      
+      if (file.isFile())
+         return;
+
+      File[] files = file.listFiles();
+      if (files != null && files.length > 0)
+      {
+         if (path.endsWith("/") == false)
+            path += "/";
+
+         for (File child : files)
+         {
+            String childPath = path + child.getName();
+            visitPath(child, childPath, visitor, filter, classLoader, included, includedFilter, excluded, excludedFilter);
          }
       }
    }
 
+   /**
+    * Should we include path in visit.
+    *
+    * @param path the path
+    * @param included the included
+    * @param includedFilter the included filter
+    * @param excluded the excluded
+    * @param excludedFilter the excluded filter
+    * @return true if path should be included in visit
+    */
+   protected boolean includePath(String path, Collection<String> included, ClassFilter includedFilter, Collection<String> excluded, ClassFilter excludedFilter)
+   {
+      if (included.isEmpty() == false && included.contains(path) == false)
+         return false;
+      if (includedFilter != null && includedFilter.matchesResourcePath(path) == false)
+         return false;
+      if (excluded.isEmpty() == false && excluded.contains(path))
+         return false;
+      if (excludedFilter != null && excludedFilter.matchesResourcePath(path))
+         return false;
+
+      return true;
+   }
+
    @Override
    protected List<Capability> determineCapabilities()
    {

Modified: projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/MockFilteredResourceVisitor.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/MockFilteredResourceVisitor.java	2008-09-29 13:23:25 UTC (rev 78928)
+++ projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/MockFilteredResourceVisitor.java	2008-09-29 14:37:48 UTC (rev 78929)
@@ -36,7 +36,7 @@
       {
          public boolean accepts(ResourceContext resource)
          {
-            return resource.getResourceName().contains("C.class") == false;
+            return resource.isClass() && resource.getResourceName().contains("C.class") == false;
          }
       };
    }

Modified: projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/MockResourceVisitor.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/MockResourceVisitor.java	2008-09-29 13:23:25 UTC (rev 78928)
+++ projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/MockResourceVisitor.java	2008-09-29 14:37:48 UTC (rev 78929)
@@ -21,9 +21,10 @@
 */
 package org.jboss.test.classloading.dependency.support;
 
+import java.util.HashSet;
 import java.util.Set;
-import java.util.HashSet;
 
+import org.jboss.classloading.spi.visitor.ClassFilter;
 import org.jboss.classloading.spi.visitor.ResourceContext;
 import org.jboss.classloading.spi.visitor.ResourceFilter;
 import org.jboss.classloading.spi.visitor.ResourceVisitor;
@@ -37,7 +38,7 @@
 
    public ResourceFilter getFilter()
    {
-      return null;
+      return ClassFilter.INSTANCE;
    }
 
    public void visit(ResourceContext resource)

Modified: projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/test/MockResourceVisitorUnitTestCase.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/test/MockResourceVisitorUnitTestCase.java	2008-09-29 13:23:25 UTC (rev 78928)
+++ projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/test/MockResourceVisitorUnitTestCase.java	2008-09-29 14:37:48 UTC (rev 78929)
@@ -46,6 +46,13 @@
 {
    private static String[] paths = new String[]
    {
+      ClassLoaderUtils.packageNameToPath(A.class.getName()),
+      ClassLoaderUtils.packageNameToPath(B.class.getName()),
+      ClassLoaderUtils.packageNameToPath(C.class.getName()),
+   };
+
+   private static String[] classes = new String[]
+   {
       ClassLoaderUtils.classNameToPath(A.class),
       ClassLoaderUtils.classNameToPath(B.class),
       ClassLoaderUtils.classNameToPath(C.class),
@@ -103,7 +110,7 @@
 
          module.visit(visitor);
 
-         Set<String> resources = new HashSet<String>(Arrays.asList(paths));
+         Set<String> resources = new HashSet<String>(Arrays.asList(classes));
          resources.remove(ClassLoaderUtils.classNameToPath(C.class));
          assertEquals(resources, visitor.getResources());
       }




More information about the jboss-cvs-commits mailing list