[jboss-cvs] JBossAS SVN: r82544 - in projects/aop/trunk: asintegration-core/src/main/org/jboss/aop/classpool and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Dec 24 08:38:33 EST 2008
Author: kabir.khan at jboss.com
Date: 2008-12-24 08:38:33 -0500 (Wed, 24 Dec 2008)
New Revision: 82544
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/util/ClassLoaderUtils.java
projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractClassPoolDomain.java
projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/BasicClassPoolDomain.java
projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/ClassPoolDomainInternal.java
projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/ClassPoolToClassPoolDomainAdapter.java
projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DelegatingClassPool.java
projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/classpool/jbosscl/JBossClClassPoolDomain.java
projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/classpool/jbosscl/JBossClDelegatingClassPool.java
projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolDelegatingTestSuite.java
projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolSanityTestSuite.java
projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolTestSuite.java
Log:
[JBAOP-666] The tests so far all pass now. To get them pass I had to modify jboss-cl and deploy a local snapshot to be able to get hold of the BaseClassLoader a DelegatingClassLoader maps to. While awaiting a fix, I have commented out the line that uses the non-existant jboss-cl code in JbossClClassPoolDomain.getCachedOrCreateInternal.
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/util/ClassLoaderUtils.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/util/ClassLoaderUtils.java 2008-12-24 11:52:24 UTC (rev 82543)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/util/ClassLoaderUtils.java 2008-12-24 13:38:33 UTC (rev 82544)
@@ -41,4 +41,16 @@
}
}
+ public static String getPackageName(String classname)
+ {
+ int last = classname.lastIndexOf('.');
+ if (last < 0)
+ {
+ return "";
+ }
+ else
+ {
+ return classname.substring(0, last);
+ }
+ }
}
Modified: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractClassPoolDomain.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractClassPoolDomain.java 2008-12-24 11:52:24 UTC (rev 82543)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractClassPoolDomain.java 2008-12-24 13:38:33 UTC (rev 82544)
@@ -48,15 +48,15 @@
if (parentPool instanceof BaseClassPool)
{
- return getCachedOrCreate((BaseClassPool)parentPool, classname, create);
+ return getCachedOrCreateFromPool((BaseClassPool)parentPool, classname, create);
}
else
{
- return getCachedOrCreate(parentPool, classname, create);
+ return getCachedOrCreateFromPool(parentPool, classname, create);
}
}
- protected CtClass getCachedOrCreate(BaseClassPool parentPool, String classname, boolean create)
+ protected CtClass getCachedOrCreateFromPool(BaseClassPool parentPool, String classname, boolean create)
{
if (parentPool == null)
{
@@ -86,7 +86,7 @@
return clazz;
}
- protected CtClass getCachedOrCreate(ClassPool parentPool, String classname, boolean create)
+ protected CtClass getCachedOrCreateFromPool(ClassPool parentPool, String classname, boolean create)
{
try
{
Modified: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/BasicClassPoolDomain.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/BasicClassPoolDomain.java 2008-12-24 11:52:24 UTC (rev 82543)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/BasicClassPoolDomain.java 2008-12-24 13:38:33 UTC (rev 82544)
@@ -97,8 +97,10 @@
public synchronized CtClass getCachedOrCreate(DelegatingClassPool initiatingPool, String classname, boolean create)
{
- CtClass clazz = getCachedOrCreateInternal(classname, create);
+ String resourceName = ClassLoaderUtils.getResourceName(classname);
+ CtClass clazz = getCachedOrCreateInternal(initiatingPool, classname, resourceName, create);
+
if (clazz == null)
{
clazz = getCachedOrCreateFromPoolParent(initiatingPool, classname, create);
@@ -106,42 +108,78 @@
return clazz;
}
- public CtClass getCachedOrCreateInternal(String classname, boolean create)
+ public CtClass getCachedOrCreateInternal(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create)
{
CtClass clazz = null;
- if (parentFirst && parent!= null)
+ if (isParentBefore())
{
- clazz = parent.getCachedOrCreateInternal(classname, create);
+ clazz = getCachedOrCreateInternalFromParent(initiatingPool, classname, resourceName, create);
}
if (clazz == null)
{
- String resourceName = delegatingPools.size() > 0 ? ClassLoaderUtils.getResourceName(classname) : null;
- for (DelegatingClassPool pool : delegatingPools)
+ String packageName = ClassLoaderUtils.getPackageName(classname);
+ for (DelegatingClassPool pool : getPoolsForPackage(packageName))
{
- if (pool.isLocalResource(resourceName))
+ clazz = attemptLoadFromPool(pool, classname, resourceName, create);
+ if (clazz != null)
{
- clazz = pool.getCachedLocally(classname);
- if (clazz == null && create)
- {
- clazz = pool.createCtClass(classname, true);
- }
- if (clazz != null)
- {
- break;
- }
+ break;
}
}
}
- if (clazz == null && parent != null && !parentFirst)
+ if (clazz == null && isParentAfter())
{
- clazz = parent.getCachedOrCreateInternal(classname, create);
+ clazz = getCachedOrCreateInternalFromParent(initiatingPool, classname, resourceName, create);
}
return clazz;
}
+ protected CtClass attemptLoadFromPool(DelegatingClassPool pool, String classname, String resourceName, boolean create)
+ {
+ CtClass clazz = null;
+ if (pool.isLocalResource(resourceName))
+ {
+ clazz = pool.getCachedLocally(classname);
+ if (clazz == null && create)
+ {
+ return pool.createCtClass(classname, true);
+ }
+ }
+ return clazz;
+ }
+
+ public CtClass getCachedOrCreateInternalFromParent(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create)
+ {
+ return parent.getCachedOrCreateInternal(initiatingPool, classname, resourceName, create);
+ }
+
public String toString()
{
return super.toString() + "[" + domainName + "]";
}
+ public List<DelegatingClassPool> getClassPools()
+ {
+ return delegatingPools;
+ }
+
+ protected boolean isParentBefore()
+ {
+ return parentFirst && parent!= null;
+ }
+
+ protected boolean isParentAfter()
+ {
+ return parent != null && !parentFirst;
+ }
+
+ protected ClassPoolDomainInternal getParentDomain()
+ {
+ return parent;
+ }
+
+ protected List<DelegatingClassPool> getPoolsForPackage(String packageName)
+ {
+ return delegatingPools;
+ }
}
Modified: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/ClassPoolDomainInternal.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/ClassPoolDomainInternal.java 2008-12-24 11:52:24 UTC (rev 82543)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/ClassPoolDomainInternal.java 2008-12-24 13:38:33 UTC (rev 82544)
@@ -30,6 +30,7 @@
*/
interface ClassPoolDomainInternal extends ClassPoolDomain
{
- CtClass getCachedOrCreateInternal(String classname, boolean create);
+ CtClass getCachedOrCreateInternal(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create);
+ CtClass getCachedOrCreateInternalFromParent(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create);
CtClass getCachedOrCreate(DelegatingClassPool initiatingPool, String classname, boolean create);
}
Modified: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/ClassPoolToClassPoolDomainAdapter.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/ClassPoolToClassPoolDomainAdapter.java 2008-12-24 11:52:24 UTC (rev 82543)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/ClassPoolToClassPoolDomainAdapter.java 2008-12-24 13:38:33 UTC (rev 82544)
@@ -53,18 +53,23 @@
}
- public synchronized CtClass getCachedOrCreateInternal(String classname, boolean create)
+ public synchronized CtClass getCachedOrCreateInternal(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create)
{
if (pool instanceof BaseClassPool)
{
- return getCachedOrCreate((BaseClassPool)pool, classname, create);
+ return getCachedOrCreateFromPool((BaseClassPool)pool, classname, create);
}
else
{
- return getCachedOrCreate(pool, classname, create);
+ return getCachedOrCreateFromPool(pool, classname, create);
}
}
+ public CtClass getCachedOrCreateInternalFromParent(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create)
+ {
+ return null;
+ }
+
public String getDomainName()
{
return null;
Modified: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DelegatingClassPool.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DelegatingClassPool.java 2008-12-24 11:52:24 UTC (rev 82543)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DelegatingClassPool.java 2008-12-24 13:38:33 UTC (rev 82544)
@@ -49,9 +49,13 @@
protected DelegatingClassPool(ClassPoolDomain domain, ClassLoader cl, ClassPool parent, ScopedClassPoolRepository repository)
{
super(cl, parent, repository);
+ if (domain == null)
+ {
+ throw new IllegalArgumentException("Domain was null");
+ }
if (domain instanceof ClassPoolDomainInternal == false)
{
- throw new IllegalArgumentException("domain must implement ClassPoolDomainInternal");
+ throw new IllegalArgumentException("Domain must implement ClassPoolDomainInternal");
}
this.domain = (ClassPoolDomainInternal)domain;
domain.addClassPool(this);
Modified: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/classpool/jbosscl/JBossClClassPoolDomain.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/classpool/jbosscl/JBossClClassPoolDomain.java 2008-12-24 11:52:24 UTC (rev 82543)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/classpool/jbosscl/JBossClClassPoolDomain.java 2008-12-24 13:38:33 UTC (rev 82544)
@@ -21,9 +21,25 @@
*/
package org.jboss.aop.classpool.jbosscl;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+
+import org.jboss.aop.AspectManager;
import org.jboss.aop.classpool.BasicClassPoolDomain;
import org.jboss.aop.classpool.ClassPoolDomain;
import org.jboss.aop.classpool.ClassPoolToClassPoolDomainAdapter;
+import org.jboss.aop.classpool.DelegatingClassPool;
+import org.jboss.classloader.spi.DelegateLoader;
+import org.jboss.classloading.spi.dependency.Module;
/**
*
@@ -32,6 +48,11 @@
*/
public class JBossClClassPoolDomain extends BasicClassPoolDomain
{
+ Map<String, Set<DelegatingClassPool>> poolsByPackage = new HashMap<String, Set<DelegatingClassPool>>();
+ final static List<DelegatingClassPool> EMPTY_LIST = Collections.unmodifiableList(Collections.EMPTY_LIST);
+
+ AspectManager manager = AspectManager.instance();
+
public JBossClClassPoolDomain(String domainName, ClassPoolDomain parent)
{
// FIXME JBossClClassPool constructor
@@ -43,4 +64,110 @@
return new JBossClClassPoolToClassPoolDomainAdapter();
}
+ synchronized void setupPoolsByPackage(DelegatingClassPool pool)
+ {
+ if (pool instanceof JBossClDelegatingClassPool == false)
+ {
+ throw new IllegalStateException("Not an instance of JBossClDelegatingClassPool: " + pool.getClass().getName());
+ }
+
+ Module module = getModuleForPool(pool);
+
+ for (String pkg : module.getPackageNames())
+ {
+ Set<DelegatingClassPool> pools = poolsByPackage.get(pkg);
+ if (pools == null)
+ {
+ pools = new LinkedHashSet<DelegatingClassPool>();
+ poolsByPackage.put(pkg, pools);
+ }
+ pools.add(pool);
+ }
+ }
+
+ @Override
+ public synchronized void removeClassPool(DelegatingClassPool pool)
+ {
+ super.removeClassPool(pool);
+
+ Module module = getModuleForPool(pool);
+
+ for (String pkg : module.getPackageNames())
+ {
+ Set<DelegatingClassPool> pools = poolsByPackage.get(pkg);
+ if (pools != null)
+ {
+ pools.remove(pool);
+ }
+ }
+ }
+
+ @Override
+ public CtClass getCachedOrCreateInternal(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create)
+ {
+ Module module = getModuleForPool(initiatingPool);
+ if (module.isImportAll())
+ {
+ //Use the old "big ball of mud" model
+ return super.getCachedOrCreateInternal(initiatingPool, classname, resourceName, create);
+ }
+
+ //Attempt OSGi style loading
+ CtClass clazz = null;
+ if (isParentBefore())
+ {
+ clazz = getCachedOrCreateInternalFromParent(null, classname, resourceName, create);
+ }
+
+ //Check imports first
+ List<? extends DelegateLoader> delegates = module.getDelegates();
+ if (delegates != null)
+ {
+ for (DelegateLoader delegate : delegates)
+ {
+ //TODO This is a hack, need a proper API in jboss-cl
+ System.out.println("Commented out loader from delegate in JBossClClassPoolDomain");
+ ClassLoader loader = null;//delegate.getBaseClassLoader("a BaseClassLoader", "");
+
+ //TODO Should be a nicer way to do this
+ ClassPool pool = manager.findClassPool(loader);
+ try
+ {
+ clazz = pool.get(classname);
+ }
+ catch(NotFoundException e)
+ {
+ }
+ }
+ }
+
+ //Try to check the initiating pool itself
+ if (clazz == null && initiatingPool != null)
+ {
+ clazz = attemptLoadFromPool(initiatingPool, classname, resourceName, create);
+ }
+
+ if (clazz == null && isParentAfter())
+ {
+ clazz = getCachedOrCreateInternalFromParent(null, classname, resourceName, create);
+ }
+ return clazz;
+ }
+
+ private Module getModuleForPool(DelegatingClassPool pool)
+ {
+ return ((JBossClDelegatingClassPool)pool).getModule();
+ }
+
+ @Override
+ protected List<DelegatingClassPool> getPoolsForPackage(String packageName)
+ {
+ Set<DelegatingClassPool> poolSet = poolsByPackage.get(packageName);
+ if (poolSet == null)
+ {
+ return EMPTY_LIST;
+ }
+ return new ArrayList<DelegatingClassPool>(poolSet);
+ }
+
}
Modified: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/classpool/jbosscl/JBossClDelegatingClassPool.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/classpool/jbosscl/JBossClDelegatingClassPool.java 2008-12-24 11:52:24 UTC (rev 82543)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/classpool/jbosscl/JBossClDelegatingClassPool.java 2008-12-24 13:38:33 UTC (rev 82544)
@@ -44,7 +44,7 @@
*/
public class JBossClDelegatingClassPool extends DelegatingClassPool
{
- Module module;
+ private Module module;
// For loadClass tmpdir creation for UCL
protected final Object tmplock = new Object();
@@ -56,9 +56,19 @@
{
throw new IllegalStateException("Null Module");
}
+ if (domain instanceof JBossClClassPoolDomain == false)
+ {
+ throw new IllegalArgumentException("Domain was not instance of JBossClClassPoolDomain: " + domain.getClass().getName());
+ }
this.module = module;
+ ((JBossClClassPoolDomain)domain).setupPoolsByPackage(this);
}
+ Module getModule()
+ {
+ return module;
+ }
+
//Copied from JBoss5ClassPool
public Class<?> toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
{
Modified: projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolDelegatingTestSuite.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolDelegatingTestSuite.java 2008-12-24 11:52:24 UTC (rev 82543)
+++ projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolDelegatingTestSuite.java 2008-12-24 13:38:33 UTC (rev 82544)
@@ -39,7 +39,7 @@
public static Test suite()
{
- TestSuite suite = new TestSuite("UclClassPool All Tests");
+ TestSuite suite = new TestSuite("JBoss-cl Pool Tests");
suite.addTest(ClassPoolWithRepositoryTestCase.suite());
suite.addTest(ClassPoolWithModuleDependencyTestCase.suite());
Modified: projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolSanityTestSuite.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolSanityTestSuite.java 2008-12-24 11:52:24 UTC (rev 82543)
+++ projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolSanityTestSuite.java 2008-12-24 13:38:33 UTC (rev 82544)
@@ -39,7 +39,7 @@
public static Test suite()
{
- TestSuite suite = new TestSuite("UclClassPool All Tests");
+ TestSuite suite = new TestSuite("JBoss-cl Sanity Tests");
suite.addTest(ClassLoaderWithRepositorySanityTestCase.suite());
suite.addTest(ClassLoaderWithModuleDependencySanityTestCase.suite());
Modified: projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolTestSuite.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolTestSuite.java 2008-12-24 11:52:24 UTC (rev 82543)
+++ projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolTestSuite.java 2008-12-24 13:38:33 UTC (rev 82544)
@@ -39,7 +39,7 @@
public static Test suite()
{
- TestSuite suite = new TestSuite("UclClassPool All Tests");
+ TestSuite suite = new TestSuite("JBoss-cl All Tests");
suite.addTest(JBossClClassPoolSanityTestSuite.suite());
suite.addTest(JBossClClassPoolDelegatingTestSuite.suite());
More information about the jboss-cvs-commits
mailing list