[jboss-cvs] JBossAS SVN: r76562 - in projects/jboss-cl/trunk: classloading/src/main/org/jboss/classloading/plugins/visitor and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 1 05:51:27 EDT 2008
Author: alesj
Date: 2008-08-01 05:51:27 -0400 (Fri, 01 Aug 2008)
New Revision: 76562
Added:
projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/VFSResourceContext.java
projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/plugins/visitor/
projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/plugins/visitor/AbstractResourceContext.java
projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/plugins/visitor/DefaultResourceContext.java
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
projects/jboss-cl/trunk/classloading-vfs/src/tests/org/jboss/test/classloading/vfs/metadata/test/VFSResourceVisitorUnitTestCase.java
projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/Module.java
projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoaderPolicyModule.java
projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/spi/visitor/ResourceContext.java
Log:
[JBCL-28]; resource context as interface.
[JBCL-29]; module visit urls
Added: projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/plugins/visitor/AbstractResourceContext.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/plugins/visitor/AbstractResourceContext.java (rev 0)
+++ projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/plugins/visitor/AbstractResourceContext.java 2008-08-01 09:51:27 UTC (rev 76562)
@@ -0,0 +1,151 @@
+/*
+* 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.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.jboss.classloader.plugins.ClassLoaderUtils;
+import org.jboss.classloading.spi.visitor.ResourceContext;
+
+/**
+ * Abstract resource context.
+ * Doesn't take url - super class should impl getURL.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractResourceContext implements ResourceContext
+{
+ /** The classloader */
+ private ClassLoader classLoader;
+
+ /** The resource name */
+ private String resourceName;
+
+ /**
+ * Create a new ResourceContext.
+ *
+ * @param resourceName the resource name
+ * @param classLoader the classloader
+ */
+ public AbstractResourceContext(String resourceName, ClassLoader classLoader)
+ {
+ if (resourceName == null)
+ throw new IllegalArgumentException("Null resourceName");
+ if (classLoader == null)
+ throw new IllegalArgumentException("Null classloader");
+
+ this.resourceName = resourceName;
+ this.classLoader = classLoader;
+ }
+
+ /**
+ * Get the classLoader.
+ *
+ * @return the classLoader.
+ */
+ public ClassLoader getClassLoader()
+ {
+ return classLoader;
+ }
+
+ /**
+ * Get the resourceName.
+ *
+ * @return the resourceName.
+ */
+ public String getResourceName()
+ {
+ return resourceName;
+ }
+
+ /**
+ * Get the class name
+ *
+ * @return the class name or null if it is not a class
+ */
+ public String getClassName()
+ {
+ return ClassLoaderUtils.resourceNameToClassName(getResourceName());
+ }
+
+ /**
+ * Whether the resource is a class
+ *
+ * @return true when the resource name ends with .class
+ */
+ public boolean isClass()
+ {
+ return resourceName.endsWith(".class");
+ }
+
+ /**
+ * Load a class
+ *
+ * Do isClass check before,
+ * unless you want to handle exception
+ * when resource is not actually a class.
+ *
+ * @return the class from resource
+ * @throws RuntimeException for any errors during class loading
+ */
+ public Class<?> loadClass()
+ {
+ String className = getClassName();
+ try
+ {
+ return classLoader.loadClass(className);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException("Unexpected error loading class: " + className, e);
+ }
+ }
+
+ /**
+ * Get the input stream for the resource
+ *
+ * @return the input stream
+ * @throws java.io.IOException for any error
+ */
+ public InputStream getInputStream() throws IOException
+ {
+ URL url = getUrl();
+ if (url == null)
+ throw new IllegalArgumentException("Null url: " + resourceName);
+
+ return url.openStream();
+ }
+
+ /**
+ * Get the bytes for the resource
+ *
+ * @return the byte array
+ * @throws java.io.IOException for any error
+ */
+ public byte[] getBytes() throws IOException
+ {
+ return ClassLoaderUtils.loadBytes(getInputStream());
+ }
+}
\ No newline at end of file
Added: projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/plugins/visitor/DefaultResourceContext.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/plugins/visitor/DefaultResourceContext.java (rev 0)
+++ projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/plugins/visitor/DefaultResourceContext.java 2008-08-01 09:51:27 UTC (rev 76562)
@@ -0,0 +1,62 @@
+/*
+* 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.net.URL;
+
+/**
+ * Default resource context.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DefaultResourceContext extends AbstractResourceContext
+{
+ /** The url of the resource */
+ private URL url;
+
+ /**
+ * Create a new ResourceContext.
+ *
+ * @param url the url
+ * @param resourceName the resource name
+ * @param classLoader the classloader
+ */
+ public DefaultResourceContext(URL url, String resourceName, ClassLoader classLoader)
+ {
+ super(resourceName, classLoader);
+
+ if (url == null)
+ throw new IllegalArgumentException("Null url");
+ this.url = url;
+ }
+
+ /**
+ * Get the url.
+ *
+ * @return the url.
+ */
+ public URL getUrl()
+ {
+ return url;
+ }
+}
Modified: projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/Module.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/Module.java 2008-08-01 06:23:42 UTC (rev 76561)
+++ projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/Module.java 2008-08-01 09:51:27 UTC (rev 76562)
@@ -347,8 +347,9 @@
* @param visitor the visitor
* @param filter the filter
* @param recurseFilter the recursion filter (null means recurse into everything)
+ * @param urls the urls we should visit
*/
- public void visit(ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter)
+ public void visit(ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter, URL... urls)
{
throw new UnsupportedOperationException("The module " + getContextName() + " does not support filtering: " + getClass().getName());
}
Modified: projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoaderPolicyModule.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoaderPolicyModule.java 2008-08-01 06:23:42 UTC (rev 76561)
+++ projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/spi/dependency/policy/mock/MockClassLoaderPolicyModule.java 2008-08-01 09:51:27 UTC (rev 76562)
@@ -31,6 +31,7 @@
import org.jboss.classloader.spi.filter.ClassFilter;
import org.jboss.classloader.test.support.MockClassLoaderHelper;
import org.jboss.classloader.test.support.MockClassLoaderPolicy;
+import org.jboss.classloading.plugins.visitor.DefaultResourceContext;
import org.jboss.classloading.spi.dependency.policy.ClassLoaderPolicyModule;
import org.jboss.classloading.spi.metadata.Capability;
import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
@@ -91,7 +92,7 @@
return classLoader.getResource(path);
}
- public void visit(ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter)
+ public void visit(ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter, URL... urls)
{
MockClassLoadingMetaData mclmd = getClassLoadingMetaData();
String[] paths = mclmd.getPaths();
@@ -117,7 +118,7 @@
if (excludedFilter != null && excludedFilter.matchesResourcePath(path))
continue;
- ResourceContext context = new ResourceContext(getURL(path), path, classLoader);
+ ResourceContext context = new DefaultResourceContext(getURL(path), path, classLoader);
if (filter == null || filter.accepts(context))
visitor.visit(context);
}
Modified: projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/spi/visitor/ResourceContext.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/spi/visitor/ResourceContext.java 2008-08-01 06:23:42 UTC (rev 76561)
+++ projects/jboss-cl/trunk/classloading/src/main/org/jboss/classloading/spi/visitor/ResourceContext.java 2008-08-01 09:51:27 UTC (rev 76562)
@@ -25,96 +25,49 @@
import java.io.InputStream;
import java.net.URL;
-import org.jboss.classloader.plugins.ClassLoaderUtils;
-
/**
* ResourceContext.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-public class ResourceContext
+public interface ResourceContext
{
- /** The url of the resource */
- private URL url;
-
- /** The classloader */
- private ClassLoader classLoader;
-
- /** The resource name */
- private String resourceName;
-
/**
- * Create a new ResourceContext.
- *
- * @param url the url
- * @param resourceName the resource name
- * @param classLoader the classloader
- */
- public ResourceContext(URL url, String resourceName, ClassLoader classLoader)
- {
- if (url == null)
- throw new IllegalArgumentException("Null url");
- if (resourceName == null)
- throw new IllegalArgumentException("Null resourceName");
- if (classLoader == null)
- throw new IllegalArgumentException("Null classloader");
-
- this.url = url;
- this.resourceName = resourceName;
- this.classLoader = classLoader;
- }
-
- /**
* Get the url.
*
* @return the url.
*/
- public URL getUrl()
- {
- return url;
- }
+ URL getUrl();
/**
* Get the classLoader.
*
* @return the classLoader.
*/
- public ClassLoader getClassLoader()
- {
- return classLoader;
- }
+ ClassLoader getClassLoader();
/**
* Get the resourceName.
*
* @return the resourceName.
*/
- public String getResourceName()
- {
- return resourceName;
- }
-
+ String getResourceName();
+
/**
* Get the class name
*
* @return the class name or null if it is not a class
*/
- public String getClassName()
- {
- return ClassLoaderUtils.resourceNameToClassName(getResourceName());
- }
-
+ String getClassName();
+
/**
* Whether the resource is a class
*
* @return true when the resource name ends with .class
*/
- public boolean isClass()
- {
- return resourceName.endsWith(".class");
- }
-
+ boolean isClass();
+
/**
* Load a class
*
@@ -125,38 +78,21 @@
* @return the class from resource
* @throws RuntimeException for any errors during class loading
*/
- public Class<?> loadClass()
- {
- String className = getClassName();
- try
- {
- return classLoader.loadClass(className);
- }
- catch (ClassNotFoundException e)
- {
- throw new RuntimeException("Unexpected error loading class: " + className, e);
- }
- }
-
+ Class<?> loadClass();
+
/**
* Get the input stream for the resource
*
* @return the input stream
* @throws IOException for any error
*/
- public InputStream getInputStream() throws IOException
- {
- return url.openStream();
- }
-
+ InputStream getInputStream() throws IOException;
+
/**
* Get the bytes for the resource
*
* @return the byte array
* @throws IOException for any error
*/
- public byte[] getBytes() throws IOException
- {
- return ClassLoaderUtils.loadBytes(getInputStream());
- }
+ byte[] getBytes() throws IOException;
}
Added: projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/VFSResourceContext.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/VFSResourceContext.java (rev 0)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/VFSResourceContext.java 2008-08-01 09:51:27 UTC (rev 76562)
@@ -0,0 +1,58 @@
+/*
+* 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.vfs;
+
+import java.net.URL;
+
+import org.jboss.classloading.plugins.visitor.AbstractResourceContext;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * VFS resource context.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class VFSResourceContext extends AbstractResourceContext
+{
+ private VirtualFile file;
+
+ public VFSResourceContext(VirtualFile file, String resourceName, ClassLoader classLoader)
+ {
+ super(resourceName, classLoader);
+
+ if (file == null)
+ throw new IllegalArgumentException("Null file");
+ this.file = file;
+ }
+
+ public URL getUrl()
+ {
+ try
+ {
+ return file.toURL();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
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 06:23:42 UTC (rev 76561)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java 2008-08-01 09:51:27 UTC (rev 76562)
@@ -21,6 +21,8 @@
*/
package org.jboss.classloading.plugins.vfs;
+import java.util.List;
+
import org.jboss.classloader.spi.filter.ClassFilter;
import org.jboss.classloading.spi.visitor.ResourceContext;
import org.jboss.classloading.spi.visitor.ResourceFilter;
@@ -35,15 +37,16 @@
* to determine resources
*
* @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
* @version $Revision: 1.1 $
*/
public class VFSResourceVisitor extends AbstractVirtualFileFilterWithAttributes implements VirtualFileVisitor
{
/** The roots */
- private VirtualFile[] roots;
+ private List<VirtualFile> roots;
/** The excluded roots */
- private VirtualFile[] excludedRoots;
+ private List<VirtualFile> excludedRoots;
/** The current root */
private VirtualFile root;
@@ -84,7 +87,7 @@
* @param filter the filter
* @param recurseFilter the recurse filter
*/
- public static void visit(VirtualFile[] roots, VirtualFile[] excludedRoots, ClassFilter included, ClassFilter excluded, ClassLoader classLoader, ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter)
+ public static void visit(List<VirtualFile> roots, List<VirtualFile> excludedRoots, ClassFilter included, ClassFilter excluded, ClassLoader classLoader, ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter)
{
VFSResourceVisitor vfsVisitor = new VFSResourceVisitor(roots, excludedRoots, included, excluded, classLoader, visitor, filter, recurseFilter);
for (VirtualFile root : roots)
@@ -105,6 +108,7 @@
* Create a new VFSResourceVisitor.
*
* @param roots the roots
+ * @param excludedRoots the excluded roots
* @param included the included packages
* @param excluded the excluded packages
* @param classLoader the classloader
@@ -112,7 +116,7 @@
* @param filter the filter
* @param recurseFilter the recurse filter
*/
- VFSResourceVisitor(VirtualFile[] roots, VirtualFile[] excludedRoots, ClassFilter included, ClassFilter excluded, ClassLoader classLoader, ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter)
+ VFSResourceVisitor(List<VirtualFile> roots, List<VirtualFile> excludedRoots, ClassFilter included, ClassFilter excluded, ClassLoader classLoader, ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter)
{
if (roots == null)
throw new IllegalArgumentException("Null roots");
@@ -177,7 +181,7 @@
try
{
String path = determinePath(file);
- ResourceContext resource = new ResourceContext(file.toURL(), path, classLoader);
+ ResourceContext resource = new VFSResourceContext(file, path, classLoader);
if (recurseFilter.accepts(resource) == false)
return false;
}
@@ -228,7 +232,7 @@
if (excluded != null && excluded.matchesResourcePath(path))
return;
- ResourceContext resource = new ResourceContext(file.toURL(), path, classLoader);
+ ResourceContext resource = new VFSResourceContext(file, path, classLoader);
//Check the filter and visit
if (filter == null || filter.accepts(resource))
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 06:23:42 UTC (rev 76561)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java 2008-08-01 09:51:27 UTC (rev 76562)
@@ -22,6 +22,9 @@
package org.jboss.classloading.spi.vfs.dependency;
import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -214,18 +217,78 @@
}
@Override
- public void visit(ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter)
+ public void visit(ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter, URL... urls)
{
ClassLoader classLoader = getClassLoader();
if (classLoader == null)
throw new IllegalStateException("ClassLoader has not been constructed for " + getContextName());
VirtualFile[] roots = determineVFSRoots();
- if (roots != null)
+ if (roots != null && roots.length > 0)
{
- ClassFilter included = getIncluded();
- ClassFilter excluded = getExcluded();
- VFSResourceVisitor.visit(roots, null, included, excluded, classLoader, visitor, filter, recurseFilter);
+ List<VirtualFile> rootsList = Arrays.asList(roots);
+ if (urls != null && urls.length > 0)
+ rootsList = matchUrlsWithRoots(urls, rootsList);
+
+ if (rootsList.isEmpty() == false)
+ {
+ ClassFilter included = getIncluded();
+ ClassFilter excluded = getExcluded();
+ VFSResourceVisitor.visit(rootsList, null, included, excluded, classLoader, visitor, filter, recurseFilter);
+ }
}
}
+
+ /**
+ * Match urls with roots.
+ *
+ * @param urls the urls
+ * @param roots the old roots
+ * @return new roots
+ */
+ protected static List<VirtualFile> matchUrlsWithRoots(URL[] urls, List<VirtualFile> roots)
+ {
+ try
+ {
+ String[] rootURLStrings = new String[urls.length];
+ List<VirtualFile> newRoots = new ArrayList<VirtualFile>(urls.length);
+ for (URL url : urls)
+ {
+ String urlString = stripProtocol(url);
+ for(int i=0; i < roots.size(); i++)
+ {
+ if (rootURLStrings[i] == null)
+ rootURLStrings[i] = stripProtocol(roots.get(i).toURL());
+
+ if (urlString.startsWith(rootURLStrings[i]))
+ {
+ VirtualFile newRoot = VFS.getRoot(url);
+ newRoots.add(newRoot);
+ break;
+ }
+ }
+ }
+ return newRoots;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Cannot match urls to roots.", e);
+ }
+ }
+
+ /**
+ * Strip the url protocol.
+ *
+ * @param url the url
+ * @return url external form w/o protocol
+ */
+ protected static String stripProtocol(URL url)
+ {
+ if (url == null)
+ throw new IllegalArgumentException("Null url");
+
+ String urlString = url.toExternalForm();
+ int p = urlString.indexOf(":/");
+ return urlString.substring(p + 2);
+ }
}
Modified: projects/jboss-cl/trunk/classloading-vfs/src/tests/org/jboss/test/classloading/vfs/metadata/test/VFSResourceVisitorUnitTestCase.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/tests/org/jboss/test/classloading/vfs/metadata/test/VFSResourceVisitorUnitTestCase.java 2008-08-01 06:23:42 UTC (rev 76561)
+++ projects/jboss-cl/trunk/classloading-vfs/src/tests/org/jboss/test/classloading/vfs/metadata/test/VFSResourceVisitorUnitTestCase.java 2008-08-01 09:51:27 UTC (rev 76562)
@@ -27,8 +27,10 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import java.util.TreeSet;
import junit.framework.Test;
import org.jboss.classloader.plugins.ClassLoaderUtils;
@@ -282,6 +284,67 @@
}
}
+ public void testUrlsParameter() throws Exception
+ {
+ VFSClassLoaderFactory factory = new VFSClassLoaderFactory("test");
+ factory.setRoots(Arrays.asList(System.getProperty("test.dir") + "/support/"));
+ KernelDeployment deployment = install(factory);
+ try
+ {
+ final Set<String> classes = new HashSet<String>();
+ ResourceVisitor visitor = new ClassVisitor()
+ {
+ public void visit(ResourceContext resource)
+ {
+ classes.add(resource.getResourceName());
+ }
+ };
+
+ URL aURL = new URL(System.getProperty("test.dir") + "/support/a");
+ Module module = assertModule("test:0.0.0");
+ module.visit(visitor, visitor.getFilter(), null, aURL);
+
+ assertEquals(1, classes.size());
+ assertEquals(classes.iterator().next(), A.class.getSimpleName() + ".class");
+ }
+ finally
+ {
+ undeploy(deployment);
+ }
+ }
+
+ public void testUrlsParameters() throws Exception
+ {
+ VFSClassLoaderFactory factory = new VFSClassLoaderFactory("test");
+ factory.setRoots(Arrays.asList(System.getProperty("test.dir") + "/support/"));
+ KernelDeployment deployment = install(factory);
+ try
+ {
+ final Set<String> classes = new TreeSet<String>();
+ ResourceVisitor visitor = new ClassVisitor()
+ {
+ public void visit(ResourceContext resource)
+ {
+ classes.add(resource.getResourceName());
+ }
+ };
+
+ URL aURL = new URL(System.getProperty("test.dir") + "/support/a");
+ URL bURL = new URL(System.getProperty("test.dir") + "/support/b");
+ Module module = assertModule("test:0.0.0");
+ module.visit(visitor, visitor.getFilter(), null, aURL, bURL);
+
+ assertEquals(2, classes.size());
+ Iterator<String> iterator = classes.iterator();
+ assertEquals(iterator.next(), A.class.getSimpleName() + ".class");
+ assertEquals(iterator.next(), B.class.getSimpleName() + ".class");
+ }
+ finally
+ {
+ undeploy(deployment);
+ }
+ }
+
protected void visitModule()
{
Module module = assertModule("test:0.0.0");
More information about the jboss-cvs-commits
mailing list