[jboss-cvs] JBossAS SVN: r64815 - projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 23 16:53:32 EDT 2007
Author: kabir.khan at jboss.com
Date: 2007-08-23 16:53:32 -0400 (Thu, 23 Aug 2007)
New Revision: 64815
Added:
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/SecurityActions.java
Modified:
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBossClassPoolFactory.java
projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedJBossClassPool.java
Log:
Fixes needed for scoped aop in jboss 5. JBoss 5 has an extra level of NoURLClassLoader containing the aop core classes. Made sure that this classloader gets a classpool which gets searched for classes. This is a temporary fix, which should be removed once we create a jboss 5 version of the class pool
Modified: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBossClassPoolFactory.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBossClassPoolFactory.java 2007-08-23 20:45:44 UTC (rev 64814)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/JBossClassPoolFactory.java 2007-08-23 20:53:32 UTC (rev 64815)
@@ -24,6 +24,9 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import org.jboss.aop.AspectManager;
import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
@@ -54,6 +57,7 @@
}
public ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
{
+ ClassPool parent = getCreateParentClassPools(cl, src, repository);
if (cl instanceof RepositoryClassLoader)
{
File tempdir = getTempDirectory(cl);
@@ -70,13 +74,25 @@
if (policy != null && policy.isScoped(cl))
{
//It is scoped
- return new ScopedJBossClassPool(cl, src, repository, tempdir, tmpCP);
+ return new ScopedJBossClassPool(cl, /*src*/parent, repository, tempdir, tmpCP);
}
- return new JBossClassPool(cl, src, repository, tempdir, tmpCP);
+ return new JBossClassPool(cl, /*src*/parent, repository, tempdir, tmpCP);
}
- return new AOPClassPool(cl, src, repository);
+ return new AOPClassPool(cl, /*src*/parent, repository);
}
+ private ClassPool getCreateParentClassPools(final ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ {
+ //Make sure that we get classpools for all the parent classloaders
+ ClassLoader parent = SecurityActions.getParent(cl);
+
+ if (parent != null)
+ {
+ return repository.registerClassLoader(parent);
+ }
+ return src;
+ }
+
private File getTempDirectory(ClassLoader cl)
{
File tempdir = null;
Modified: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedJBossClassPool.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedJBossClassPool.java 2007-08-23 20:45:44 UTC (rev 64814)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/ScopedJBossClassPool.java 2007-08-23 20:53:32 UTC (rev 64815)
@@ -24,6 +24,7 @@
import java.io.File;
import java.lang.ref.WeakReference;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Iterator;
import org.jboss.aop.AspectManager;
@@ -33,6 +34,7 @@
import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
import org.jboss.mx.loading.LoaderRepository;
import org.jboss.mx.loading.RepositoryClassLoader;
+import org.jboss.system.server.NoAnnotationURLClassLoader;
import javassist.ClassPool;
import javassist.CtClass;
@@ -73,7 +75,7 @@
}
break;
}
- prnt = cl.getParent();
+ prnt = SecurityActions.getParent(cl);
}
super.childFirstLookup = !parentFirst;
@@ -92,8 +94,15 @@
private URL getResourceUrlForClass(String resourcename)
{
- HeirarchicalLoaderRepository3 repo = getRepository();
- return repo.getResource(resourcename, super.getClassLoader());
+ try
+ {
+ HeirarchicalLoaderRepository3 repo = getRepository();
+ return repo.getResource(resourcename, super.getClassLoader());
+ }
+ catch(RuntimeException e)
+ {
+ throw e;
+ }
}
private boolean isMine(URL url)
@@ -127,6 +136,10 @@
{
return null;
}
+ if (isUnloadedClassLoader())
+ {
+ return null;
+ }
if (generatedClasses.get(classname) != null)
{
@@ -164,7 +177,7 @@
try
{
- ClassPool pool = getCorrectPoolForResource(url);
+ ClassPool pool = getCorrectPoolForResource(classname, url);
if (pool != lastPool.get())
{
lastPool.set(pool);
@@ -185,11 +198,15 @@
return null;
}
-
- private ClassPool getCorrectPoolForResource(URL url)
+
+ private ClassPool getCorrectPoolForResource(String classname, URL url)
{
synchronized(AspectManager.getRegisteredCLs())
{
+ //JBoss 5 has an extra NoAnnotationURLCLassLoader that is not on the default path, make sure that that is checked at the end
+ //FIXME This needs revisiting/removing once the
+ ArrayList noAnnotationURLClassLoaderPools = null;
+ String resource = url.toString();
for(Iterator it = AspectManager.getRegisteredCLs().values().iterator() ; it.hasNext() ; )
{
AOPClassPool candidate = (AOPClassPool)it.next();
@@ -204,18 +221,62 @@
//Sometimes the ClassLoader is a proxy for MBeanProxyExt?!
RepositoryClassLoader rcl = (RepositoryClassLoader)candidate.getClassLoader();
URL[] urls = rcl.getClasspath();
- String resource = url.toString();
+
for (int i = 0 ; i < urls.length ; i++)
{
- if (resource.indexOf(urls[i].toString()) >= 0)
+ if (resource.indexOf(urls[i].getFile()) >= 0)
{
return candidate;
}
}
}
+ //FIXME Remove once we have the JBoss 5 version of pool
+ else if (isInstanceOfNoAnnotationURLClassLoader(candidate.getClassLoader()))
+ {
+ if (noAnnotationURLClassLoaderPools == null)
+ {
+ noAnnotationURLClassLoaderPools = new ArrayList();
+ }
+ noAnnotationURLClassLoaderPools.add(candidate);
+ }
}
+
+ //FIXME Remove once we have the JBoss 5 version of pool
+ if (noAnnotationURLClassLoaderPools != null)
+ {
+ for (Iterator it = noAnnotationURLClassLoaderPools.iterator() ; it.hasNext() ; )
+ {
+ ClassPool pool = (ClassPool)it.next();
+
+ try
+ {
+ pool.get(classname);
+ return pool;
+ }
+ catch(NotFoundException ignoreTryNext)
+ {
+ }
+ }
+ }
}
return AOPClassPool.createAOPClassPool(ClassPool.getDefault(), AOPClassPoolRepository.getInstance());
}
+
+ /**
+ * NoAnnotationURLCLassLoader lives in different packages in JBoss 4 and 5
+ */
+ private boolean isInstanceOfNoAnnotationURLClassLoader(ClassLoader loader)
+ {
+ Class parent = loader.getClass();
+ while (parent != null)
+ {
+ if ("NoAnnotationURLClassLoader".equals(parent.getSimpleName()))
+ {
+ return true;
+ }
+ parent = parent.getSuperclass();
+ }
+ return false;
+ }
}
Added: projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/SecurityActions.java
===================================================================
--- projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/SecurityActions.java (rev 0)
+++ projects/aop/trunk/asintegration/src/main/org/jboss/aop/deployment/SecurityActions.java 2007-08-23 20:53:32 UTC (rev 64815)
@@ -0,0 +1,80 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.aop.deployment;
+
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SecurityActions
+{
+ interface GetParentAction
+ {
+ ClassLoader getParent(ClassLoader loader);
+
+ GetParentAction NON_PRIVILEGED = new GetParentAction()
+ {
+ public ClassLoader getParent(ClassLoader loader)
+ {
+ return loader.getParent();
+ }
+ };
+
+ GetParentAction PRIVILEGED = new GetParentAction()
+ {
+ public ClassLoader getParent(final ClassLoader loader)
+ {
+ try
+ {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<ClassLoader>()
+ {
+ public ClassLoader run() throws Exception
+ {
+ return loader.getParent();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw new RuntimeException(e.getException());
+ }
+ }
+ };
+ }
+
+ public static ClassLoader getParent(ClassLoader loader)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return GetParentAction.NON_PRIVILEGED.getParent(loader);
+ }
+ else
+ {
+ return GetParentAction.PRIVILEGED.getParent(loader);
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list