[jboss-cvs] JBossAS SVN: r104763 - in projects/jboss-cl/trunk: classloader/src/main/java/org/jboss/classloader/spi/base and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu May 13 09:52:44 EDT 2010
Author: alesj
Date: 2010-05-13 09:52:43 -0400 (Thu, 13 May 2010)
New Revision: 104763
Added:
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoadingTaskAwareLoader.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoadingTaskInfo.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicy.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicyFactory.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardDelegateLoader.java
projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/WildcardPackageUnitTestCase.java
Modified:
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderDomain.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderPolicy.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseDelegateLoader.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoaderManager.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoadingTask.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/metadata/PackageCapability.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/metadata/PackageRequirement.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/Domain.java
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java
projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/DynamicPackageUnitTestCase.java
Log:
[JBCL-162]; support dynamic wildcards -- initial work.
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderDomain.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderDomain.java 2010-05-13 13:46:44 UTC (rev 104762)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderDomain.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -1066,7 +1066,7 @@
@Override
protected Class<?> checkCacheAfter(BaseClassLoader classLoader, String name, String path, boolean allExports)
{
- if (parent == null || parent instanceof CacheLoader == false || isBlackListedClass(name) == false)
+ if (parent == null || parent instanceof CacheLoader == false || isBlackListedClass(path) == false)
return null;
ClassFilter filter = getParentPolicy().getAfterFilter();
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java 2010-05-13 13:46:44 UTC (rev 104762)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -37,6 +37,7 @@
import org.jboss.classloader.spi.filter.ClassFilterUtils;
import org.jboss.classloading.spi.RealClassLoader;
import org.jboss.logging.Logger;
+import org.jboss.util.collection.ConcurrentSet;
import org.jboss.util.collection.Iterators;
/**
@@ -63,13 +64,13 @@
private DelegateLoader loader;
/** The loaded classes */
- private Map<String, String> loadedClasses = new ConcurrentHashMap<String, String>();
+ private Set<String> loadedClasses = new ConcurrentSet<String>();
/** Our resource cache */
private Map<String, URL> resourceCache;
/** Our black list */
- private Map<String, String> blackList;
+ private Set<String> blackList;
/**
* Create a new ClassLoader with no parent.
@@ -94,7 +95,7 @@
resourceCache = new ConcurrentHashMap<String, URL>();
if (basePolicy.isBlackListable())
- blackList = new ConcurrentHashMap<String, String>();
+ blackList = new ConcurrentSet<String>();
log.debugf("Created %1s with policy %2s", this, policy);
}
@@ -188,7 +189,7 @@
public Set<String> listLoadedClasses()
{
- return Collections.unmodifiableSet(loadedClasses.keySet());
+ return Collections.unmodifiableSet(loadedClasses);
}
public Set<String> listLoadedResourceNames()
@@ -655,7 +656,7 @@
}
}, policy.getAccessControlContext());
- loadedClasses.put(name, name);
+ loadedClasses.add(name);
policy.classFound(new ClassFoundEvent(this, result));
return result;
@@ -697,7 +698,7 @@
}
// Is this resource blacklisted?
- if (blackList != null && blackList.containsKey(name))
+ if (blackList != null && blackList.contains(name))
{
if (trace)
log.trace(this + " resource is blacklisted " + name);
@@ -729,7 +730,7 @@
// Blacklist when not found
if (blackList != null && result == null)
- blackList.put(name, name);
+ blackList.add(name);
return result;
}
@@ -924,7 +925,7 @@
public int getResourceBlackListSize()
{
- Map<String, String> blackList = this.blackList;
+ Set<String> blackList = this.blackList;
if (blackList == null)
return 0;
return blackList.size();
@@ -940,10 +941,10 @@
public Set<String> listResourceBlackList()
{
- Map<String, String> blackList = this.blackList;
+ Set<String> blackList = this.blackList;
if (blackList == null)
return Collections.emptySet();
- return Collections.unmodifiableSet(blackList.keySet());
+ return Collections.unmodifiableSet(blackList);
}
public Map<String, URL> listResourceCache()
@@ -958,7 +959,7 @@
{
if (blackList != null)
{
- for (String name : blackList.keySet())
+ for (String name : blackList)
clearBlackList(name);
}
}
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderPolicy.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderPolicy.java 2010-05-13 13:46:44 UTC (rev 104762)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderPolicy.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -21,17 +21,13 @@
*/
package org.jboss.classloader.spi.base;
+import javax.management.ObjectName;
+
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.ProtectionDomain;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Formattable;
-import java.util.Formatter;
-import java.util.List;
+import java.util.*;
-import javax.management.ObjectName;
-
import org.jboss.classloader.spi.ClassLoaderDomain;
import org.jboss.classloader.spi.DelegateLoader;
import org.jboss.classloader.spi.ShutdownPolicy;
@@ -241,8 +237,7 @@
if (domain == null)
{
ShutdownPolicy result = getShutdownPolicy();
- if (result == null)
- result = ShutdownPolicy.UNREGISTER;
+ return (result != null) ? result : ShutdownPolicy.UNREGISTER;
}
return domain.determineShutdownPolicy(this);
}
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseDelegateLoader.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseDelegateLoader.java 2010-05-13 13:46:44 UTC (rev 104762)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseDelegateLoader.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -25,6 +25,7 @@
import java.net.URL;
import java.util.Set;
+import org.jboss.classloader.plugins.ClassLoaderUtils;
import org.jboss.classloader.spi.CacheLoader;
import org.jboss.classloader.spi.ClassLoaderPolicy;
import org.jboss.classloader.spi.ClassLoaderPolicyFactory;
@@ -110,8 +111,15 @@
{
// Nothing by default
}
-
- BaseClassLoader getBaseClassLoader(String message, String context)
+
+ /**
+ * Get BaseClassLoader.
+ *
+ * @param message the msg
+ * @param context the context; make sure this is always resource path
+ * @return policy's BaseClassLoader
+ */
+ protected BaseClassLoader getBaseClassLoader(String message, String context)
{
BaseClassLoader result = null;
BaseClassLoaderPolicy policy = getPolicy();
@@ -124,7 +132,8 @@
public Class<?> loadClass(String className)
{
- BaseClassLoader classLoader = getBaseClassLoader("loading class ", className);
+ String path = ClassLoaderUtils.classNameToPath(className);
+ BaseClassLoader classLoader = getBaseClassLoader("loading class ", path);
if (classLoader != null)
return classLoader.loadClassLocally(className);
return null;
@@ -156,17 +165,12 @@
public void getPackages(Set<Package> packages)
{
- BaseClassLoader classLoader;
- try
- {
- classLoader = delegate.getClassLoader();
- }
- catch (IllegalStateException e)
- {
- log.warn("Not getting packages from policy that has no classLoader: " + toLongString());
+ if (delegate == null)
return;
- }
- classLoader.getPackagesLocally(packages);
+
+ BaseClassLoader classLoader = delegate.getClassLoaderUnchecked();
+ if (classLoader != null)
+ classLoader.getPackagesLocally(packages);
}
public Class<?> checkClassCache(BaseClassLoader classLoader, String name, String path, boolean allExports)
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoaderManager.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoaderManager.java 2010-05-13 13:46:44 UTC (rev 104762)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoaderManager.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -21,12 +21,7 @@
*/
package org.jboss.classloader.spi.base;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.WeakHashMap;
+import java.util.*;
import org.jboss.classloader.spi.Loader;
import org.jboss.classloader.spi.base.ClassLoadingTask.ThreadTask;
@@ -344,8 +339,13 @@
List<ThreadTask> taskList;
BaseClassLoader classLoader = null;
- if (loader instanceof BaseDelegateLoader)
+ if (loader instanceof ClassLoadingTaskAwareLoader)
{
+ ClassLoadingTaskAwareLoader cltal = (ClassLoadingTaskAwareLoader) loader;
+ classLoader = cltal.getBaseClassLoader(task);
+ }
+ if (classLoader == null && loader instanceof BaseDelegateLoader)
+ {
BaseDelegateLoader delegateLoader = (BaseDelegateLoader) loader;
BaseClassLoaderPolicy policy = delegateLoader.getPolicy();
if (policy == null)
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoadingTask.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoadingTask.java 2010-05-13 13:46:44 UTC (rev 104762)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoadingTask.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -37,9 +37,10 @@
*
* @author Scott.Stark at jboss.org
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
* @version $Revision: 1.1 $
*/
-class ClassLoadingTask
+class ClassLoadingTask implements ClassLoadingTaskInfo
{
/** The log */
protected static Logger log = Logger.getLogger("org.jboss.detailed.classloader.ClassLoadingTask");
@@ -108,7 +109,7 @@
*
* @return the className.
*/
- String getClassName()
+ public String getClassName()
{
return className;
}
@@ -401,15 +402,21 @@
*/
BaseClassLoader getClassLoader()
{
- if (loader instanceof BaseDelegateLoader)
+ BaseClassLoader classLoader = null;
+ if (loader instanceof ClassLoadingTaskAwareLoader)
{
+ ClassLoadingTaskAwareLoader cltal = (ClassLoadingTaskAwareLoader) loader;
+ classLoader = cltal.getBaseClassLoader(getLoadTask());
+ }
+ if (classLoader == null && loader instanceof BaseDelegateLoader)
+ {
BaseDelegateLoader delegateLoader = (BaseDelegateLoader) loader;
BaseClassLoaderPolicy policy = delegateLoader.getPolicy();
if (policy == null)
throw new IllegalStateException("Null classloader policy for " + loader);
- return policy.getClassLoader();
+ classLoader = policy.getClassLoader();
}
- return null;
+ return classLoader;
}
/**
Added: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoadingTaskAwareLoader.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoadingTaskAwareLoader.java (rev 0)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoadingTaskAwareLoader.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.classloader.spi.base;
+
+/**
+ * Loader that knows how to get BaseClassLoader based on task
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ClassLoadingTaskAwareLoader
+{
+ /**
+ * Get classloader.
+ *
+ * @param task the current classloading task
+ * @return matching classloader or null
+ */
+ BaseClassLoader getBaseClassLoader(ClassLoadingTaskInfo task);
+}
Copied: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoadingTaskInfo.java (from rev 104736, projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoadingTask.java)
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoadingTaskInfo.java (rev 0)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/ClassLoadingTaskInfo.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.classloader.spi.base;
+
+/**
+ * ClassLoadingTaskInfo.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ClassLoadingTaskInfo
+{
+ /**
+ * Get the className.
+ *
+ * @return the className.
+ */
+ String getClassName();
+}
\ No newline at end of file
Modified: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/metadata/PackageCapability.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/metadata/PackageCapability.java 2010-05-13 13:46:44 UTC (rev 104762)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/metadata/PackageCapability.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -24,6 +24,7 @@
import java.util.Collections;
import java.util.Set;
+import org.jboss.classloader.spi.filter.ClassFilter;
import org.jboss.classloading.spi.dependency.Module;
import org.jboss.classloading.spi.metadata.ExportPackages;
import org.jboss.classloading.spi.metadata.Requirement;
@@ -50,7 +51,7 @@
Last,
/** Split packages generate an error. This is the default. */
Error
- };
+ }
/** The split package policy. Default is {@link SplitPackagePolicy#Error} */
private SplitPackagePolicy splitPolicy = SplitPackagePolicy.Error;
@@ -123,9 +124,19 @@
{
if (requirement instanceof PackageRequirement == false)
return false;
+
PackageRequirement requirePackage = (PackageRequirement) requirement;
- if (getName().equals(requirePackage.getName()) == false)
- return false;
+ if (requirePackage.isWildcard())
+ {
+ ClassFilter filter = requirePackage.toClassFilter();
+ if (filter.matchesPackageName(getName()) == false)
+ return false;
+ }
+ else // for non-wildcard, we intentionaly still use direct string equals
+ {
+ if (getName().equals(requirePackage.getName()) == false)
+ return false;
+ }
return requirePackage.getVersionRange().isInRange(getVersion());
}
Modified: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/metadata/PackageRequirement.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/metadata/PackageRequirement.java 2010-05-13 13:46:44 UTC (rev 104762)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/metadata/PackageRequirement.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -46,6 +46,9 @@
/** The serialVersionUID */
private static final long serialVersionUID = -7552921085464308835L;
+ /** The filter */
+ private transient ClassFilter filter;
+
/**
* Create a new PackageRequirement.
*/
@@ -93,21 +96,23 @@
*/
public ClassFilter toClassFilter()
{
- ClassFilter filter;
- String packageName = getName();
- if ("*".equals(packageName))
+ if (filter == null)
{
- filter = EverythingClassFilter.INSTANCE;
+ String packageName = getName();
+ if ("*".equals(packageName))
+ {
+ filter = EverythingClassFilter.INSTANCE;
+ }
+ else if (packageName.endsWith(".*"))
+ {
+ packageName = packageName.substring(0, packageName.length() - 2);
+ filter = RecursivePackageClassFilter.createRecursivePackageClassFilter(packageName);
+ }
+ else
+ {
+ filter = PackageClassFilter.createPackageClassFilter(packageName);
+ }
}
- else if (packageName.endsWith(".*"))
- {
- packageName = packageName.substring(0, packageName.length() - 2);
- filter = RecursivePackageClassFilter.createRecursivePackageClassFilter(packageName);
- }
- else
- {
- filter = PackageClassFilter.createPackageClassFilter(packageName);
- }
return filter;
}
Modified: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/Domain.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/Domain.java 2010-05-13 13:46:44 UTC (rev 104762)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/Domain.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -99,6 +99,16 @@
}
/**
+ * Get ClassLoading.
+ *
+ * @return the classloading
+ */
+ public ClassLoading getClassLoading()
+ {
+ return classLoading;
+ }
+
+ /**
* Get the parentDomainName.
*
* @return the parentDomainName.
Modified: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java 2010-05-13 13:46:44 UTC (rev 104762)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -260,17 +260,25 @@
throw new IllegalStateException("No controller context");
Controller controller = context.getController();
- DynamicClassLoaderPolicyFactory factory = new DynamicClassLoaderPolicyFactory(controller, domain, item);
-
Requirement requirement = item.getRequirement();
if (requirement instanceof PackageRequirement)
{
PackageRequirement pr = (PackageRequirement)requirement;
- // TODO -- handle wildcards
- return new FilteredDelegateLoader(factory, pr.toClassFilter());
+ ClassFilter filter = pr.toClassFilter();
+ if (pr.isWildcard())
+ {
+ ClassLoaderPolicyFactory factory = new WildcardClassLoaderPolicyFactory(domain, item);
+ return new WildcardDelegateLoader(factory, filter);
+ }
+ else
+ {
+ ClassLoaderPolicyFactory factory = new DynamicClassLoaderPolicyFactory(controller, domain, item);
+ return new FilteredDelegateLoader(factory, filter);
+ }
}
else
{
+ ClassLoaderPolicyFactory factory = new DynamicClassLoaderPolicyFactory(controller, domain, item);
return new LazyFilteredDelegateLoader(factory);
}
}
Added: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicy.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicy.java (rev 0)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicy.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -0,0 +1,240 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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.spi.dependency.policy;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.base.BaseClassLoader;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloading.plugins.metadata.PackageRequirement;
+import org.jboss.classloading.spi.dependency.*;
+
+/**
+ * WildcardClassLoaderPolicy.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class WildcardClassLoaderPolicy extends ClassLoaderPolicy implements ModuleRegistry
+{
+ /** The domain */
+ private Domain domain;
+
+ /** The package requirement */
+ private PackageRequirement requirement;
+
+ /** The moduke */
+ private Module module;
+
+ /** The matching imported modules */
+ private volatile List<Module> modules;
+
+ /** The resources cache */
+ private Map<String, Module> resourceCache = new ConcurrentHashMap<String, Module>();
+
+ public WildcardClassLoaderPolicy(Domain domain, PackageRequirement requirement, Module module)
+ {
+ this.domain = domain;
+ this.requirement = requirement;
+ this.module = module;
+ }
+
+ /**
+ * Find module which has a resource parameter.
+ *
+ * @param resource the resource
+ * @return found module or null
+ */
+ protected Module findModule(String resource)
+ {
+ Module cached = resourceCache.get(resource);
+ if (cached != null)
+ return cached;
+
+ ClassFilter filter = requirement.toClassFilter();
+ if (filter.matchesResourcePath(resource))
+ {
+ for (Module m : getModules())
+ {
+ URL url = m.getResource(resource);
+ if (url != null)
+ {
+ resourceCache.put(resource, m);
+ return m;
+ }
+ }
+ }
+ return null;
+ }
+
+ public URL getResource(String path)
+ {
+ Module cached = resourceCache.get(path);
+ if (cached != null)
+ return cached.getResource(path);
+
+ ClassFilter filter = requirement.toClassFilter();
+ if (filter.matchesResourcePath(path))
+ {
+ for (Module m : getModules())
+ {
+ URL url = m.getResource(path);
+ if (url != null)
+ {
+ resourceCache.put(path, m);
+ return url;
+ }
+ }
+ }
+ return null;
+ }
+
+ public void getResources(String name, Set<URL> urls) throws IOException
+ {
+ ClassFilter filter = requirement.toClassFilter();
+ if (filter.matchesResourcePath(name))
+ {
+ for (Module m : getModules())
+ {
+ Enumeration<URL> eu = m.getResources(name);
+ while (eu.hasMoreElements())
+ urls.add(eu.nextElement());
+ }
+ }
+ }
+
+ @Override
+ protected boolean isCacheable()
+ {
+ return false; // don't cache
+ }
+
+ protected void reset(Module module)
+ {
+ String domainName = module.getDeterminedDomainName();
+ Domain current = domain;
+ while (current != null && domainName.equals(domain.getName()) == false)
+ current = current.getParentDomain();
+
+ // We have a domain match, do reset
+ if (current != null)
+ {
+ modules = null;
+ resourceCache.clear();
+ }
+ }
+
+ public void addModule(Module module)
+ {
+ reset(module);
+ }
+
+ public void removeModule(Module module)
+ {
+ reset(module);
+
+ // Unregister this policy as module listener
+ if (module == this.module)
+ {
+ ClassLoading classLoading = domain.getClassLoading();
+ classLoading.removeModuleRegistry(this);
+ this.module = null;
+ }
+ }
+
+ /**
+ * Lazy get modules.
+ *
+ * @return the matching modules
+ */
+ private List<Module> getModules()
+ {
+ if (modules == null)
+ {
+ List<Module> tmp = new ArrayList<Module>();
+ List<ExportPackage> eps = getExportedPackages();
+ for (ExportPackage ep : eps)
+ {
+ Module m = ep.getModule();
+ if (m != module) // sanity check
+ tmp.add(m);
+ }
+ modules = tmp;
+ }
+ return modules;
+ }
+
+ /**
+ * Get matching imported modules.
+ *
+ * @return the matching import modules
+ */
+ private List<ExportPackage> getExportedPackages()
+ {
+ List<ExportPackage> modules = new ArrayList<ExportPackage>();
+ fillModules(domain, modules);
+ return modules;
+ }
+
+ /**
+ * Fill modules according to domain rules.
+ *
+ * @param domain the current domain
+ * @param modules the modules to fill
+ */
+ private void fillModules(Domain domain, List<ExportPackage> modules)
+ {
+ Domain parent = domain.getParentDomain();
+ boolean parentFirst = domain.isParentFirst();
+
+ if (parent != null && parentFirst)
+ fillModules(parent, modules);
+
+ Collection<ExportPackage> eps = domain.getExportedPackages(requirement.getName(), requirement.getVersionRange());
+ if (eps != null && eps.isEmpty() == false)
+ modules.addAll(eps);
+
+ if (parent != null && parentFirst == false)
+ fillModules(parent, modules);
+ }
+
+ /**
+ * Get BaseClassLoader from module.
+ *
+ * @param context the context
+ * @return matching classloader or null
+ */
+ BaseClassLoader getBaseClassLoader(String context)
+ {
+ Module m = findModule(context);
+ if (m != null)
+ {
+ ClassLoader cl = ClassLoading.getClassLoaderForModule(m);
+ if (cl instanceof BaseClassLoader)
+ return BaseClassLoader.class.cast(cl);
+ }
+ return null;
+ }
+}
Copied: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicyFactory.java (from rev 104736, projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/DynamicClassLoaderPolicyFactory.java)
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicyFactory.java (rev 0)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardClassLoaderPolicyFactory.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -0,0 +1,81 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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.spi.dependency.policy;
+
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.ClassLoaderPolicyFactory;
+import org.jboss.classloading.plugins.metadata.PackageRequirement;
+import org.jboss.classloading.spi.dependency.ClassLoading;
+import org.jboss.classloading.spi.dependency.Domain;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.dependency.RequirementDependencyItem;
+import org.jboss.classloading.spi.metadata.Requirement;
+
+/**
+ * WildcardClassLoaderPolicyFactory.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class WildcardClassLoaderPolicyFactory implements ClassLoaderPolicyFactory
+{
+ /** The domain */
+ private Domain domain;
+
+ /** The package requirement */
+ private PackageRequirement requirement;
+
+ /** The module */
+ private Module module;
+
+ /**
+ * Create a new WildcardClassLoaderPolicyFactory.
+ *
+ * @param domain the domain
+ * @param item the requirement item
+ */
+ public WildcardClassLoaderPolicyFactory(Domain domain, RequirementDependencyItem item)
+ {
+ if (domain == null)
+ throw new IllegalArgumentException("Null domain");
+ if (item == null)
+ throw new IllegalArgumentException("Null item");
+ Requirement requirement = item.getRequirement();
+ if (requirement == null || requirement instanceof PackageRequirement == false)
+ throw new IllegalArgumentException("Illegal requirement: " + requirement);
+ PackageRequirement pr = (PackageRequirement) requirement;
+ if (pr.isWildcard() == false)
+ throw new IllegalArgumentException("Requirement is not wildcard: " + pr);
+ if (item.getModule() == null)
+ throw new IllegalArgumentException("Null module");
+ this.domain = domain;
+ this.requirement = pr;
+ this.module = item.getModule();
+ }
+
+ public ClassLoaderPolicy createClassLoaderPolicy()
+ {
+ WildcardClassLoaderPolicy policy = new WildcardClassLoaderPolicy(domain, requirement, module);
+ ClassLoading classLoading = domain.getClassLoading();
+ classLoading.addModuleRegistry(policy); // so we know when to reset on module change
+ return policy;
+ }
+}
\ No newline at end of file
Added: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardDelegateLoader.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardDelegateLoader.java (rev 0)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/WildcardDelegateLoader.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.spi.dependency.policy;
+
+import org.jboss.classloader.plugins.ClassLoaderUtils;
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.ClassLoaderPolicyFactory;
+import org.jboss.classloader.spi.base.BaseClassLoader;
+import org.jboss.classloader.spi.base.ClassLoadingTaskAwareLoader;
+import org.jboss.classloader.spi.base.ClassLoadingTaskInfo;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloader.spi.filter.FilteredDelegateLoader;
+
+/**
+ * Wildcard delegate loader.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class WildcardDelegateLoader extends FilteredDelegateLoader implements ClassLoadingTaskAwareLoader
+{
+ public WildcardDelegateLoader(ClassLoaderPolicyFactory factory, ClassFilter filter)
+ {
+ super(factory, filter);
+ }
+
+ @Override
+ protected BaseClassLoader getBaseClassLoader(String message, String context)
+ {
+ ClassLoaderPolicy policy = getPolicy();
+ if (policy instanceof WildcardClassLoaderPolicy == false)
+ throw new IllegalArgumentException("Can only handle wildcard policy: " + policy);
+
+ WildcardClassLoaderPolicy wclp = (WildcardClassLoaderPolicy) policy;
+ return wclp.getBaseClassLoader(context);
+ }
+
+ public BaseClassLoader getBaseClassLoader(ClassLoadingTaskInfo task)
+ {
+ String path = ClassLoaderUtils.classNameToPath(task.getClassName());
+ return getBaseClassLoader(null, path);
+ }
+}
Modified: projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/DynamicPackageUnitTestCase.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/DynamicPackageUnitTestCase.java 2010-05-13 13:46:44 UTC (rev 104762)
+++ projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/DynamicPackageUnitTestCase.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -34,7 +34,7 @@
import junit.framework.Test;
/**
- * ReExportPackageUnitTestCase.
+ * DynamicPackageUnitTestCase.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @author <a href="ales.justin at jboss.org">Ales Justin</a>
Copied: projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/WildcardPackageUnitTestCase.java (from rev 104736, projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/DynamicPackageUnitTestCase.java)
===================================================================
--- projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/WildcardPackageUnitTestCase.java (rev 0)
+++ projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/WildcardPackageUnitTestCase.java 2010-05-13 13:52:43 UTC (rev 104763)
@@ -0,0 +1,125 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test;
+
+import org.jboss.classloader.spi.ImportType;
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.metadata.helpers.AbstractRequirement;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.classloading.dependency.support.a.A;
+import org.jboss.test.classloading.dependency.support.b.B;
+
+import junit.framework.Test;
+
+/**
+ * WildcardPackageUnitTestCase.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class WildcardPackageUnitTestCase extends AbstractMockClassLoaderUnitTest
+{
+ public static Test suite()
+ {
+ return suite(WildcardPackageUnitTestCase.class);
+ }
+
+ public WildcardPackageUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testWildcardPackage() throws Exception
+ {
+ ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+
+ MockClassLoadingMetaData a1 = new MockClassLoadingMetaData("a1");
+ a1.getRequirements().addRequirement(factory.createWildcardPackage(A.class.getPackage().getName()));
+ KernelControllerContext contextA1 = install(a1);
+ try
+ {
+ ClassLoader clA1 = assertClassLoader(contextA1);
+ assertLoadClassFail(A.class, clA1);
+
+ MockClassLoadingMetaData a2 = new MockClassLoadingMetaData("a2");
+ a2.setPathsAndPackageNames(A.class);
+ KernelControllerContext contextA2 = install(a2);
+ try
+ {
+ ClassLoader clA2 = assertClassLoader(contextA2);
+ assertLoadClass(A.class, clA2);
+ assertLoadClass(A.class, clA1, clA2);
+ }
+ finally
+ {
+ uninstall(contextA2);
+ }
+ assertNoClassLoader(contextA2);
+ }
+ finally
+ {
+ uninstall(contextA1);
+ }
+ assertNoClassLoader(contextA1);
+ }
+
+ // deploy B first, then A
+ public void testWildcardImportAexportAandB2() throws Exception
+ {
+ ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+
+ MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+ b.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+ b.getCapabilities().addCapability(factory.createPackage(B.class.getPackage().getName()));
+ b.setPathsAndPackageNames(A.class, B.class);
+ KernelControllerContext contextB = install(b);
+ try
+ {
+ assertClassLoader(contextB); // force CL install
+
+ MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+
+ Requirement aPackage = factory.createWildcardPackage(A.class.getPackage().getName());
+ ((AbstractRequirement)aPackage).setImportType(ImportType.AFTER);
+
+ a.getRequirements().addRequirement(aPackage);
+ a.setPaths(A.class);
+ KernelControllerContext contextA = install(a);
+ try
+ {
+ ClassLoader clA = assertClassLoader(contextA);
+ assertLoadClassFail(B.class, clA);
+ }
+ finally
+ {
+ uninstall(contextA);
+ }
+ assertNoClassLoader(contextA);
+ }
+ finally
+ {
+ uninstall(contextB);
+ }
+ assertNoClassLoader(contextB);
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list