[jboss-cvs] JBossAS SVN: r79077 - in projects/jboss-cl/branches/Branch_2_0: classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/mock and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Oct 3 08:15:57 EDT 2008
Author: alesj
Date: 2008-10-03 08:15:56 -0400 (Fri, 03 Oct 2008)
New Revision: 79077
Added:
projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/policy/test/PackageInfoUnitTestCase.java
projects/jboss-cl/branches/Branch_2_0/classloading/src/main/java/org/jboss/classloading/plugins/visitor/FederatedResourceVisitor.java
projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/MockFederatedResourceVisitor.java
projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/ResourcesAdapter.java
Removed:
projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/policy/test/PackageInfoUnitTestCase.java
Modified:
projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java
projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/metadata/test/VFSResourceVisitorUnitTestCase.java
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 changes from trunk.
e.g. federated resource visitor + matching tests.
Copied: projects/jboss-cl/branches/Branch_2_0/classloading/src/main/java/org/jboss/classloading/plugins/visitor/FederatedResourceVisitor.java (from rev 79076, projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/visitor/FederatedResourceVisitor.java)
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading/src/main/java/org/jboss/classloading/plugins/visitor/FederatedResourceVisitor.java (rev 0)
+++ projects/jboss-cl/branches/Branch_2_0/classloading/src/main/java/org/jboss/classloading/plugins/visitor/FederatedResourceVisitor.java 2008-10-03 12:15:56 UTC (rev 79077)
@@ -0,0 +1,138 @@
+/*
+* 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.classloading.plugins.visitor;
+
+import java.util.Arrays;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+
+/**
+ * Federated resource visitor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class FederatedResourceVisitor implements ResourceVisitor
+{
+ private ResourceVisitor[] visitors;
+ private ResourceFilter[] filters;
+ private ResourceFilter[] recurseFilters;
+
+ private ResourceFilter filter;
+ private ResourceFilter recurseFilter;
+ private boolean[] recurseFlags;
+ private boolean[] filterFlags;
+
+ public FederatedResourceVisitor(ResourceVisitor[] visitors)
+ {
+ if (visitors == null || visitors.length == 0)
+ throw new IllegalArgumentException("Null or empty visitors: " + Arrays.toString(visitors));
+ this.visitors = visitors;
+ }
+
+ public FederatedResourceVisitor(ResourceVisitor[] visitors, ResourceFilter[] filters, ResourceFilter[] recurseFilters)
+ {
+ this(visitors);
+ this.filters = filters;
+ this.recurseFilters = recurseFilters;
+ }
+
+ public ResourceFilter getRecurseFilter()
+ {
+ if (recurseFilters == null || recurseFilters.length == 0)
+ return null;
+
+ if (recurseFilter == null)
+ {
+ recurseFlags = new boolean[recurseFilters.length];
+ recurseFilter = new FederatedRecurseFilter();
+ }
+ return recurseFilter;
+ }
+
+ public ResourceFilter getFilter()
+ {
+ if (filters != null && filters.length == 0)
+ return null;
+
+ if (filter == null)
+ {
+ if (filters == null)
+ {
+ filters = new ResourceFilter[visitors.length];
+ for (int i =0; i < visitors.length; i++)
+ filters[i] = visitors[i].getFilter();
+ }
+
+ filterFlags = new boolean[filters == null ? 0 : filters.length];
+ filter = new FederatedResourceFilter();
+ }
+ return filter;
+ }
+
+ public void visit(ResourceContext resource)
+ {
+ for (int i = 0; i < visitors.length; i++)
+ {
+ if (filterFlags == null || filterFlags.length <= i || filterFlags[i])
+ {
+ visitors[i].visit(resource);
+ }
+ }
+ }
+
+ private class FederatedRecurseFilter implements ResourceFilter
+ {
+ public boolean accepts(ResourceContext resource)
+ {
+ boolean accept = false;
+ for (int i = 0; i < recurseFilters.length; i++)
+ {
+ recurseFlags[i] = recurseFilters[i] == null || recurseFilters[i].accepts(resource);
+ if (recurseFlags[i])
+ accept = true;
+ }
+ return accept;
+ }
+ }
+
+ private class FederatedResourceFilter implements ResourceFilter
+ {
+ public boolean accepts(ResourceContext resource)
+ {
+ boolean accept = false;
+ for (int i = 0; i < filters.length; i++)
+ {
+ if (recurseFlags == null || recurseFlags.length <= i || recurseFlags[i])
+ {
+ filterFlags[i] = filters[i] == null || filters[i].accepts(resource);
+ if (filterFlags[i])
+ accept = true;
+ }
+ else
+ filterFlags[i] = false;
+ }
+ return accept;
+ }
+ }
+}
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-10-03 12:07:43 UTC (rev 79076)
+++ projects/jboss-cl/branches/Branch_2_0/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoaderPolicyModule.java 2008-10-03 12:15:56 UTC (rev 79077)
@@ -129,7 +129,7 @@
for (String path : paths)
{
- visitPath(null, path, visitor, filter, classLoader, included, includedFilter, excluded, excludedFilter);
+ visitPath(null, path, visitor, filter, recurseFilter, classLoader, included, includedFilter, excluded, excludedFilter, null);
}
}
}
@@ -141,13 +141,15 @@
* @param path the path
* @param visitor the visitor
* @param filter the filter
+ * @param recurseFilter the recurse filter
* @param classLoader the classloader
* @param included the included
* @param includedFilter the included filter
* @param excluded the excluded
* @param excludedFilter the excluded filter
+ * @param context the current context
*/
- protected void visitPath(File file, String path, ResourceVisitor visitor, ResourceFilter filter, ClassLoader classLoader, Collection<String> included, ClassFilter includedFilter, Collection<String> excluded, ClassFilter excludedFilter)
+ protected void visitPath(File file, String path, ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter, ClassLoader classLoader, Collection<String> included, ClassFilter includedFilter, Collection<String> excluded, ClassFilter excludedFilter, ResourceContext context)
{
boolean visit = includePath(path, included, includedFilter, excluded, excludedFilter);
@@ -155,7 +157,8 @@
if (visit)
{
- ResourceContext context = new DefaultResourceContext(url, path, classLoader);
+ if (context == null)
+ context = new DefaultResourceContext(url, path, classLoader);
if (filter == null || filter.accepts(context))
visitor.visit(context);
}
@@ -175,7 +178,11 @@
for (File child : files)
{
String childPath = path + child.getName();
- visitPath(child, childPath, visitor, filter, classLoader, included, includedFilter, excluded, excludedFilter);
+ ResourceContext childContext = new DefaultResourceContext(getURL(childPath), childPath, classLoader);
+ if (recurseFilter == null || recurseFilter.accepts(childContext))
+ {
+ visitPath(child, childPath, visitor, filter, recurseFilter, classLoader, included, includedFilter, excluded, excludedFilter, childContext);
+ }
}
}
}
Copied: projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/MockFederatedResourceVisitor.java (from rev 79076, projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/support/MockFederatedResourceVisitor.java)
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/MockFederatedResourceVisitor.java (rev 0)
+++ projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/MockFederatedResourceVisitor.java 2008-10-03 12:15:56 UTC (rev 79077)
@@ -0,0 +1,57 @@
+/*
+* 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.classloading.dependency.support;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.classloading.plugins.visitor.FederatedResourceVisitor;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class MockFederatedResourceVisitor extends FederatedResourceVisitor implements ResourcesAdapter
+{
+ private ResourceVisitor[] tmp;
+ private Set<String> resources = new HashSet<String>();
+
+ public MockFederatedResourceVisitor(ResourceVisitor[] visitors, ResourceFilter[] filters, ResourceFilter[] recurseFilters)
+ {
+ super(visitors, filters, recurseFilters);
+ tmp = visitors;
+ }
+
+ public Set<String> getResources()
+ {
+ for (ResourceVisitor rv : tmp)
+ {
+ if (rv instanceof ResourcesAdapter)
+ {
+ ResourcesAdapter ra = (ResourcesAdapter)rv;
+ resources.addAll(ra.getResources());
+ }
+ }
+ return resources;
+ }
+}
\ No newline at end of file
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-10-03 12:07:43 UTC (rev 79076)
+++ projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/MockFilteredResourceVisitor.java 2008-10-03 12:15:56 UTC (rev 79077)
@@ -21,14 +21,23 @@
*/
package org.jboss.test.classloading.dependency.support;
+import java.util.regex.Pattern;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
import org.jboss.classloading.spi.visitor.ResourceFilter;
-import org.jboss.classloading.spi.visitor.ResourceContext;
/**
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
public class MockFilteredResourceVisitor extends MockResourceVisitor
{
+ private Pattern excludePattern;
+
+ public MockFilteredResourceVisitor(String excludeString)
+ {
+ this.excludePattern = Pattern.compile(excludeString);
+ }
+
@Override
public ResourceFilter getFilter()
{
@@ -36,7 +45,7 @@
{
public boolean accepts(ResourceContext resource)
{
- return resource.isClass() && resource.getResourceName().contains("C.class") == false;
+ return resource.isClass() && excludePattern.matcher(resource.getResourceName()).find() == 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-10-03 12:07:43 UTC (rev 79076)
+++ projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/MockResourceVisitor.java 2008-10-03 12:15:56 UTC (rev 79077)
@@ -27,12 +27,11 @@
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;
/**
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-public class MockResourceVisitor implements ResourceVisitor
+public class MockResourceVisitor implements ResourcesAdapter
{
private Set<String> resources = new HashSet<String>();
Copied: projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/ResourcesAdapter.java (from rev 79076, projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/support/ResourcesAdapter.java)
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/ResourcesAdapter.java (rev 0)
+++ projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/support/ResourcesAdapter.java 2008-10-03 12:15:56 UTC (rev 79077)
@@ -0,0 +1,34 @@
+/*
+* 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.classloading.dependency.support;
+
+import java.util.Set;
+
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface ResourcesAdapter extends ResourceVisitor
+{
+ Set<String> getResources();
+}
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-10-03 12:07:43 UTC (rev 79076)
+++ projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/test/MockResourceVisitorUnitTestCase.java 2008-10-03 12:15:56 UTC (rev 79077)
@@ -30,9 +30,14 @@
import org.jboss.classloader.spi.filter.PackageClassFilter;
import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoaderPolicyModule;
import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+import org.jboss.classloading.spi.visitor.ResourceContext;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.classloading.dependency.support.MockFederatedResourceVisitor;
+import org.jboss.test.classloading.dependency.support.MockFilteredResourceVisitor;
import org.jboss.test.classloading.dependency.support.MockResourceVisitor;
-import org.jboss.test.classloading.dependency.support.MockFilteredResourceVisitor;
+import org.jboss.test.classloading.dependency.support.ResourcesAdapter;
import org.jboss.test.classloading.dependency.support.a.A;
import org.jboss.test.classloading.dependency.support.b.B;
import org.jboss.test.classloading.dependency.support.c.C;
@@ -92,27 +97,122 @@
public void testFiltered() throws Exception
{
MockClassLoadingMetaData a = createClassLoadingMetaData("a");
- testMockClassLoadingMetaData(a, new MockFilteredResourceVisitor());
+ testMockClassLoadingMetaData(a, new MockFilteredResourceVisitor("C.class"));
}
+ public void testRecurseFilter() throws Exception
+ {
+ Set<String> resources = new HashSet<String>(Arrays.asList(classes));
+ resources.remove(ClassLoaderUtils.classNameToPath(C.class));
+ MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+ a.setExcluded(new PackageClassFilter(new String[]{ResourcesAdapter.class.getPackage().getName()}));
+ a.setPaths(ResourcesAdapter.class);
+ ResourceFilter recurseFilter = new ResourceFilter()
+ {
+ public boolean accepts(ResourceContext resource)
+ {
+ String name = resource.getResourceName();
+ boolean result = name.contains("support/c") || name.contains("support\\c");
+ return result == false;
+ }
+ };
+ testMockClassLoadingMetaData(a, new MockResourceVisitor(), null, recurseFilter, resources);
+ }
+
+ public void testFederated() throws Exception
+ {
+ MockClassLoadingMetaData a = createClassLoadingMetaData("a");
+ MockFilteredResourceVisitor fa = new MockFilteredResourceVisitor("B\\.class|C\\.class");
+ MockFilteredResourceVisitor fb = new MockFilteredResourceVisitor("A\\.class|C\\.class");
+ testMockClassLoadingMetaData(a, new MockFederatedResourceVisitor(new ResourceVisitor[]{fa, fb}, null, null));
+ }
+
+ public void testFederatedWithRecurse() throws Exception
+ {
+ MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+ a.setExcluded(new PackageClassFilter(new String[]{ResourcesAdapter.class.getPackage().getName()}));
+ a.setPaths(ResourcesAdapter.class);
+ MockFilteredResourceVisitor fa = new MockFilteredResourceVisitor("A\\.class");
+ MockFilteredResourceVisitor fb = new MockFilteredResourceVisitor("B\\.class");
+ ResourceFilter recurseFilter = new ResourceFilter()
+ {
+ public boolean accepts(ResourceContext resource)
+ {
+ String name = resource.getResourceName();
+ boolean result = name.contains("support/c") || name.contains("support\\c");
+ return result == false;
+ }
+ };
+ MockFederatedResourceVisitor federatedRV = new MockFederatedResourceVisitor(new ResourceVisitor[]{fa, fb}, null, new ResourceFilter[]{recurseFilter, recurseFilter});
+ Set<String> resources = new HashSet<String>(Arrays.asList(classes));
+ resources.remove(ClassLoaderUtils.classNameToPath(C.class));
+ testMockClassLoadingMetaData(a, federatedRV, federatedRV.getFilter(), federatedRV.getRecurseFilter(), resources);
+ }
+
+ public void testFederatedWithRecurseMixed() throws Exception
+ {
+ MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+ a.setExcluded(new PackageClassFilter(new String[]{ResourcesAdapter.class.getPackage().getName()}));
+ a.setPaths(ResourcesAdapter.class);
+ MockFilteredResourceVisitor fa = new MockFilteredResourceVisitor("A\\.class|C\\.class");
+ MockFilteredResourceVisitor fb = new MockFilteredResourceVisitor("B\\.class");
+ ResourceFilter recurseFilter = new ResourceFilter()
+ {
+ public boolean accepts(ResourceContext resource)
+ {
+ String name = resource.getResourceName();
+ boolean result = name.contains("support/c") || name.contains("support\\c");
+ return result == false;
+ }
+ };
+ MockFederatedResourceVisitor federatedRV = new MockFederatedResourceVisitor(new ResourceVisitor[]{fa, fb}, null, new ResourceFilter[]{null, recurseFilter});
+ Set<String> resources = new HashSet<String>(Arrays.asList(classes));
+ resources.remove(ClassLoaderUtils.classNameToPath(C.class));
+ testMockClassLoadingMetaData(a, federatedRV, federatedRV.getFilter(), federatedRV.getRecurseFilter(), resources);
+ }
+
protected void testMockClassLoadingMetaData(MockClassLoadingMetaData a) throws Exception
{
testMockClassLoadingMetaData(a, new MockResourceVisitor());
}
- protected void testMockClassLoadingMetaData(MockClassLoadingMetaData a, MockResourceVisitor visitor) throws Exception
+ protected void testMockClassLoadingMetaData(MockClassLoadingMetaData a, ResourcesAdapter visitor) throws Exception
{
+ Set<String> resources = new HashSet<String>(Arrays.asList(classes));
+ resources.remove(ClassLoaderUtils.classNameToPath(C.class));
+ testMockClassLoadingMetaData(a, visitor, resources);
+ }
+
+ protected void testMockClassLoadingMetaData(MockClassLoadingMetaData a, ResourcesAdapter visitor, Set<String> expectedResources) throws Exception
+ {
+ testMockClassLoadingMetaData(a, visitor, visitor.getFilter(), null, expectedResources);
+ }
+
+ protected void testMockClassLoadingMetaData(MockClassLoadingMetaData a, ResourcesAdapter visitor, ResourceFilter filter, ResourceFilter recurseFilter, Set<String> expectedResources) throws Exception
+ {
KernelControllerContext contextA = install(a);
try
{
MockClassLoaderPolicyModule module = assertModule(contextA);
module.registerClassLoaderPolicy(system);
- module.visit(visitor);
+ if (recurseFilter != null)
+ {
+ if (filter != null)
+ module.visit(visitor, filter, recurseFilter);
+ else
+ module.visit(visitor, visitor.getFilter(), recurseFilter);
+ }
+ else if (filter != null)
+ {
+ module.visit(visitor, filter);
+ }
+ else
+ {
+ module.visit(visitor);
+ }
- Set<String> resources = new HashSet<String>(Arrays.asList(classes));
- resources.remove(ClassLoaderUtils.classNameToPath(C.class));
- assertEquals(resources, visitor.getResources());
+ assertEquals(expectedResources, visitor.getResources());
}
finally
{
Modified: projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java 2008-10-03 12:07:43 UTC (rev 79076)
+++ projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java 2008-10-03 12:15:56 UTC (rev 79077)
@@ -52,7 +52,7 @@
/**
* VFSClassLoaderPolicy.
- *
+ *
* @author <a href="adrian at jboss.org">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
@@ -66,13 +66,13 @@
/** A name for the policy */
private String name;
-
+
/** The delegates */
private List<? extends DelegateLoader> delegates;
-
+
/** The roots */
private VirtualFile[] roots;
-
+
/** The excluded roots */
private VirtualFile[] excludedRoots;
@@ -84,10 +84,10 @@
/** The excluded */
private ClassFilter excluded;
-
+
/** The excluded for export */
private ClassFilter excludedExport;
-
+
/** The exported packages */
private String[] exportedPackages;
@@ -96,20 +96,20 @@
/** Whether we are cachable */
private boolean cacheable = true;
-
+
/** Whether we are blacklistable */
private boolean blackListable = true;
-
+
/** Manifest cache */
private Map<URL, Manifest> manifestCache = new ConcurrentHashMap<URL, Manifest>();
-
+
/** Cache of virtual file information by path */
@SuppressWarnings("unchecked")
private Map<String, VirtualFileInfo> vfsCache = Collections.synchronizedMap(new SoftValueHashMap());
-
+
/**
* Determine a name from the roots
- *
+ *
* @param roots the roots
* @return the name
*/
@@ -117,7 +117,7 @@
{
if (roots == null)
return "";
-
+
try
{
for (VirtualFile root : roots)
@@ -128,10 +128,10 @@
}
return "";
}
-
+
/**
* Create a new VFSClassLoaderPolicy.
- *
+ *
* @param roots the roots
* @return the classloader policy
* @throws IllegalArgumentException for null roots
@@ -140,10 +140,10 @@
{
return new VFSClassLoaderPolicy(roots);
}
-
+
/**
* Create a new VFSClassLoaderPolicy.
- *
+ *
* @param name a name of the policy
* @param roots the roots
* @return the classloader policy
@@ -153,10 +153,10 @@
{
return new VFSClassLoaderPolicy(name, roots);
}
-
+
/**
* Create a new VFSClassLoaderPolicy.
- *
+ *
* @param roots the roots
* @param excludedRoots the excluded roots
* @return the classloader policy
@@ -166,10 +166,10 @@
{
return new VFSClassLoaderPolicy(roots, excludedRoots);
}
-
+
/**
* Create a new VFSClassLoaderPolicy.
- *
+ *
* @param name a name of the policy
* @param roots the roots
* @param excludedRoots the excluded roots
@@ -183,7 +183,7 @@
/**
* Create a new VFSClassLoaderPolicy.
- *
+ *
* @param roots the roots
* @throws IllegalArgumentException for null roots
*/
@@ -194,7 +194,7 @@
/**
* Create a new VFSClassLoaderPolicy.
- *
+ *
* @param roots the roots
* @param excludedRoots the excluded roots
* @throws IllegalArgumentException for null roots
@@ -206,7 +206,7 @@
/**
* Create a new VFSClassLoaderPolicy.
- *
+ *
* @param name the name
* @param roots the roots
* @throws IllegalArgumentException for null roots
@@ -218,7 +218,7 @@
/**
* Create a new VFSClassLoaderPolicy.
- *
+ *
* @param name the name
* @param roots the roots
* @param excludedRoots the excluded roots
@@ -263,7 +263,7 @@
/**
* Set the delegates.
- *
+ *
* @param delegates the delegates.
*/
public void setDelegates(List<? extends DelegateLoader> delegates)
@@ -273,7 +273,7 @@
/**
* Get the included.
- *
+ *
* @return the included.
*/
public ClassFilter getIncluded()
@@ -283,7 +283,7 @@
/**
* Set the included.
- *
+ *
* @param included the included.
*/
public void setIncluded(ClassFilter included)
@@ -293,7 +293,7 @@
/**
* Get the excluded.
- *
+ *
* @return the excluded.
*/
public ClassFilter getExcluded()
@@ -303,7 +303,7 @@
/**
* Set the excluded.
- *
+ *
* @param excluded the excluded.
*/
public void setExcluded(ClassFilter excluded)
@@ -313,7 +313,7 @@
/**
* Get the excludedExport.
- *
+ *
* @return the excludedExport.
*/
public ClassFilter getExcludedExport()
@@ -323,7 +323,7 @@
/**
* Set the excludedExport.
- *
+ *
* @param excludedExport the excludedExport.
*/
public void setExcludedExport(ClassFilter excludedExport)
@@ -333,7 +333,7 @@
/**
* Get the exportAll.
- *
+ *
* @return the exportAll.
*/
public ExportAll getExportAll()
@@ -343,7 +343,7 @@
/**
* Set the exportAll.
- *
+ *
* @param exportAll the exportAll.
*/
public void setExportAll(ExportAll exportAll)
@@ -361,7 +361,7 @@
/**
* Get the exported packages
- *
+ *
* @return the exported packages
*/
public String[] getExportedPackages()
@@ -371,7 +371,7 @@
/**
* Set the exportedPackages.
- *
+ *
* @param exportedPackages the exportedPackages.
*/
public void setExportedPackages(String[] exportedPackages)
@@ -393,7 +393,7 @@
/**
* Set the importAll.
- *
+ *
* @param importAll the importAll.
*/
public void setImportAll(boolean importAll)
@@ -409,7 +409,7 @@
/**
* Set the cacheable.
- *
+ *
* @param cacheable the cacheable.
*/
public void setCacheable(boolean cacheable)
@@ -425,7 +425,7 @@
/**
* Set the blackListable.
- *
+ *
* @param blackListable the blackListable.
*/
public void setBlackListable(boolean blackListable)
@@ -446,7 +446,7 @@
{
if (checkFilters(path, "getResource"))
return null;
-
+
VirtualFile child = findChild(path);
if (child != null)
{
@@ -462,7 +462,7 @@
}
return null;
}
-
+
@Override
public InputStream getResourceAsStream(String path)
{
@@ -508,7 +508,7 @@
/**
* Find a child from a path
- *
+ *
* @param path the path
* @return the child if found in the roots
*/
@@ -522,7 +522,7 @@
/**
* Find a root from a path
- *
+ *
* @param path the path
* @return the root if found in the roots
*/
@@ -536,7 +536,7 @@
/**
* Find the virtual file information for a path
- *
+ *
* @param path the path
* @return the virtual file information
*/
@@ -545,7 +545,7 @@
VirtualFileInfo result = vfsCache.get(path);
if (result != null)
return result;
-
+
for (VirtualFile root : roots)
{
try
@@ -564,7 +564,7 @@
}
return null;
}
-
+
@Override
public PackageInformation getClassPackageInformation(String className, String packageName)
{
@@ -586,7 +586,7 @@
else
manifestCache.put(rootURL, manifest);
}
-
+
if (manifest == NO_MANIFEST)
manifest = null;
}
@@ -631,10 +631,10 @@
throw new Error("Error determining protection domain for " + clazz, e);
}
}
-
+
/**
* Check the filters
- *
+ *
* @param path the path to check
* @param context the context
* @return true if it fails the filters
@@ -662,10 +662,10 @@
{
/** The file */
private VirtualFile file;
-
+
/** The root */
private VirtualFile root;
-
+
public VirtualFileInfo(VirtualFile file, VirtualFile root)
{
this.file = file;
@@ -674,7 +674,7 @@
/**
* Get the file.
- *
+ *
* @return the file.
*/
public VirtualFile getFile()
@@ -684,7 +684,7 @@
/**
* Get the root.
- *
+ *
* @return the root.
*/
public VirtualFile getRoot()
Modified: projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/metadata/test/VFSResourceVisitorUnitTestCase.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/metadata/test/VFSResourceVisitorUnitTestCase.java 2008-10-03 12:07:43 UTC (rev 79076)
+++ projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/metadata/test/VFSResourceVisitorUnitTestCase.java 2008-10-03 12:15:56 UTC (rev 79077)
@@ -28,12 +28,15 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import java.util.ArrayList;
import junit.framework.Test;
import org.jboss.classloader.plugins.ClassLoaderUtils;
+import org.jboss.classloading.plugins.visitor.FederatedResourceVisitor;
import org.jboss.classloading.spi.dependency.Module;
import org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory;
import org.jboss.classloading.spi.visitor.ClassVisitor;
@@ -357,6 +360,93 @@
}
}
+ public void testFederated() throws Exception
+ {
+ VFSClassLoaderFactory factory = new VFSClassLoaderFactory("test");
+ factory.setRoots(Arrays.asList(System.getProperty("test.dir") + "/support/"));
+ KernelDeployment deployment = install(factory);
+ try
+ {
+ final List<String> classes = new ArrayList<String>();
+ ResourceVisitor visitor = new ClassVisitor()
+ {
+ public void visit(ResourceContext resource)
+ {
+ classes.add(resource.getResourceName());
+ }
+ };
+ ResourceFilter rfA = new ResourceFilter()
+ {
+ public boolean accepts(ResourceContext resource)
+ {
+ return "a".equals(resource.getResourceName());
+ }
+ };
+ ResourceFilter rfB = new ResourceFilter()
+ {
+ public boolean accepts(ResourceContext resource)
+ {
+ return "b".equals(resource.getResourceName());
+ }
+ };
+ FederatedResourceVisitor fedRV = new FederatedResourceVisitor(
+ new ResourceVisitor[]{visitor, visitor},
+ null,
+ new ResourceFilter[]{rfA, rfB}
+ );
+
+ Module module = assertModule("test:0.0.0");
+ module.visit(fedRV, fedRV.getFilter(), fedRV.getRecurseFilter());
+
+ assertEquals(2, classes.size());
+ assertTrue(classes.contains("a/A.class"));
+ assertTrue(classes.contains("b/B.class"));
+ }
+ finally
+ {
+ undeploy(deployment);
+ }
+ }
+
+ public void testFederatedMixed() throws Exception
+ {
+ VFSClassLoaderFactory factory = new VFSClassLoaderFactory("test");
+ factory.setRoots(Arrays.asList(System.getProperty("test.dir") + "/support/"));
+ KernelDeployment deployment = install(factory);
+ try
+ {
+ final List<String> classes = new ArrayList<String>();
+ ResourceVisitor visitor = new ClassVisitor()
+ {
+ public void visit(ResourceContext resource)
+ {
+ classes.add(resource.getResourceName());
+ }
+ };
+ ResourceFilter rfA = new ResourceFilter()
+ {
+ public boolean accepts(ResourceContext resource)
+ {
+ return "a".equals(resource.getResourceName());
+ }
+ };
+ FederatedResourceVisitor fedRV = new FederatedResourceVisitor(
+ new ResourceVisitor[]{visitor, visitor},
+ null,
+ new ResourceFilter[]{rfA, null}
+ );
+
+ Module module = assertModule("test:0.0.0");
+ module.visit(fedRV, fedRV.getFilter(), fedRV.getRecurseFilter());
+
+ assertEquals(4, classes.size()); // A, A, B, C
+ }
+ finally
+ {
+ undeploy(deployment);
+ }
+ }
+
protected void visitModule()
{
Module module = assertModule("test:0.0.0");
Deleted: projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/policy/test/PackageInfoUnitTestCase.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/policy/test/PackageInfoUnitTestCase.java 2008-10-03 12:07:43 UTC (rev 79076)
+++ projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/policy/test/PackageInfoUnitTestCase.java 2008-10-03 12:15:56 UTC (rev 79077)
@@ -1,81 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * 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.classloading.vfs.policy.test;
-
-import java.net.URL;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.jboss.classloader.spi.PackageInformation;
-import org.jboss.classloading.spi.metadata.ExportAll;
-import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
-import org.jboss.test.BaseTestCase;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * Package related tests of VFSClassLoaderPolicy
- * @author Scott.Stark at jboss.org
- * @version $Revision: 78503 $
- */
-public class PackageInfoUnitTestCase extends BaseTestCase
-{
-
- public PackageInfoUnitTestCase(String name)
- {
- super(name);
- }
-
- public void testCorrectPackage()
- throws Exception
- {
- URL testear1xURL = getResource("/classloader/testear1x.ear");
- VirtualFile testear1x = VFS.getRoot(testear1xURL);
- VirtualFile jar1 = testear1x.getChild("lib/jar1.jar");
- assertNotNull(jar1);
- VirtualFile jar2 = testear1x.getChild("lib/jar2.jar");
- assertNotNull(jar2);
- VFSClassLoaderPolicy policy = VFSClassLoaderPolicy.createVFSClassLoaderPolicy("testCorrectPackage", testear1x, jar2, jar1);
- policy.setExportAll(ExportAll.NON_EMPTY);
- policy.setImportAll(true);
-
- PackageInformation utilInfo = policy.getClassPackageInformation("util.Shared", "util");
- /*
- Specification-Title: testear1x.ear/lib/jar1.jar
- Specification-Version: 1.0.1.GA
- Specification-Vendor: JBoss
- Implementation-Title: JBoss [division of RedHat]
- Implementation-URL: http://www.jboss.org/
- Implementation-Version: 1.0.1.GA
- Implementation-Vendor: JBoss.org
- Implementation-Vendor-Id: http://www.jboss.org/
- */
- assertEquals("testear1x.ear/lib/jar1.jar", utilInfo.specTitle);
- assertEquals("1.0.1.GA", utilInfo.specVersion);
- }
-
- public static Test suite()
- {
- return new TestSuite(PackageInfoUnitTestCase.class);
- }
-}
Copied: projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/policy/test/PackageInfoUnitTestCase.java (from rev 79076, projects/jboss-cl/trunk/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/policy/test/PackageInfoUnitTestCase.java)
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/policy/test/PackageInfoUnitTestCase.java (rev 0)
+++ projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/policy/test/PackageInfoUnitTestCase.java 2008-10-03 12:15:56 UTC (rev 79077)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * 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.classloading.vfs.policy.test;
+
+import java.net.URL;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.classloader.spi.PackageInformation;
+import org.jboss.classloading.spi.metadata.ExportAll;
+import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
+import org.jboss.test.BaseTestCase;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Package related tests of VFSClassLoaderPolicy
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class PackageInfoUnitTestCase extends BaseTestCase
+{
+
+ public PackageInfoUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testCorrectPackage()
+ throws Exception
+ {
+ URL testear1xURL = getResource("/classloader/testear1x.ear");
+ VirtualFile testear1x = VFS.getRoot(testear1xURL);
+ VirtualFile jar1 = testear1x.getChild("lib/jar1.jar");
+ assertNotNull(jar1);
+ VirtualFile jar2 = testear1x.getChild("lib/jar2.jar");
+ assertNotNull(jar2);
+ VFSClassLoaderPolicy policy = VFSClassLoaderPolicy.createVFSClassLoaderPolicy("testCorrectPackage", testear1x, jar2, jar1);
+ policy.setExportAll(ExportAll.NON_EMPTY);
+ policy.setImportAll(true);
+
+ PackageInformation utilInfo = policy.getClassPackageInformation("util.Shared", "util");
+ /*
+ Specification-Title: testear1x.ear/lib/jar1.jar
+ Specification-Version: 1.0.1.GA
+ Specification-Vendor: JBoss
+ Implementation-Title: JBoss [division of RedHat]
+ Implementation-URL: http://www.jboss.org/
+ Implementation-Version: 1.0.1.GA
+ Implementation-Vendor: JBoss.org
+ Implementation-Vendor-Id: http://www.jboss.org/
+ */
+ assertEquals("testear1x.ear/lib/jar1.jar", utilInfo.specTitle);
+ assertEquals("1.0.1.GA", utilInfo.specVersion);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(PackageInfoUnitTestCase.class);
+ }
+}
More information about the jboss-cvs-commits
mailing list