[jboss-cvs] JBossAS SVN: r102716 - in projects/jboss-reflect/trunk: src/main/java/org/jboss/reflect/plugins/javassist and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Mar 22 06:43:51 EDT 2010
Author: kabir.khan at jboss.com
Date: 2010-03-22 06:43:50 -0400 (Mon, 22 Mar 2010)
New Revision: 102716
Added:
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoCacheTestCase.java
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoUtilTestCase.java
Modified:
projects/jboss-reflect/trunk/pom.xml
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/AbstractBeanInfoTest.java
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoUnitTestCase.java
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/support/NumberChild.java
Log:
[JBREFLECT-107] [JBREFLECT-2] Test bean info working with javassist. Comment out the javassist version of BeanInfoUtilTestCase
Modified: projects/jboss-reflect/trunk/pom.xml
===================================================================
--- projects/jboss-reflect/trunk/pom.xml 2010-03-22 09:08:32 UTC (rev 102715)
+++ projects/jboss-reflect/trunk/pom.xml 2010-03-22 10:43:50 UTC (rev 102716)
@@ -40,6 +40,10 @@
<includes>
<include>org/jboss/test/**/*TestCase.java</include>
</includes>
+ <excludes>
+ <!-- Enable once JBREFLECT-2 is fixed -->
+ <exclude>**/JavassistBeanInfoUtilTestCase.java</exclude>
+ </excludes>
<useSystemClassLoader>true</useSystemClassLoader>
</configuration>
</plugin>
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java 2010-03-22 09:08:32 UTC (rev 102715)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java 2010-03-22 10:43:50 UTC (rev 102716)
@@ -270,7 +270,7 @@
* @return the info
* @throws ClassNotFoundException when the class cannot be found
*/
- public TypeInfo get(String name, ClassLoader cl, Class<?> clazz) throws ClassNotFoundException
+ protected TypeInfo get(String name, ClassLoader cl, Class<?> clazz) throws ClassNotFoundException
{
if (name == null)
throw new IllegalArgumentException("Null name");
@@ -280,7 +280,7 @@
try
{
CtClass ctClass = poolFactory.getPoolForLoader(cl).get(name);
- return get(ctClass, clazz);
+ return get(ctClass, clazz, cl);
}
catch(NotFoundException nfe)
{
@@ -320,11 +320,29 @@
* @param clazz the class
* @return the info
*/
- @SuppressWarnings("unchecked")
- public TypeInfo get(CtClass ctClass, Class<?> clazz)
+ protected TypeInfo get(CtClass ctClass, Class<?> clazz)
{
if (ctClass == null)
throw new IllegalArgumentException("Null class");
+
+ if (clazz != null && clazz.getClassLoader() != null)
+ return get(ctClass, clazz, clazz.getClassLoader());
+ else
+ return get(ctClass, clazz, ctClass.getClassPool().getClassLoader());
+ }
+
+ /**
+ * Get the information for a class
+ *
+ * @param ctClass the class
+ * @param clazz the class
+ * @param cl the class loader
+ * @return the info
+ */
+ protected TypeInfo get(CtClass ctClass, Class<?> clazz, ClassLoader cl)
+ {
+ if (ctClass == null)
+ throw new IllegalArgumentException("Null class");
TypeInfo primitive = PrimitiveInfo.valueOf(ctClass.getName());
if (primitive != null)
@@ -357,7 +375,7 @@
}
}
- Map<String, WeakReference<TypeInfo>> classLoaderCache = getClassLoaderCache(ctClass.getClassPool().getClassLoader());
+ Map<String, WeakReference<TypeInfo>> classLoaderCache = getClassLoaderCache(cl);
TypeInfo result = getFromCache(ctClass.getName(), classLoaderCache);
if (result != null)
return result;
@@ -717,7 +735,12 @@
Class<?> clazz = PrimitiveInfo.getPrimativeArrayComponentType(s);
return PrimitiveInfo.valueOf(clazz.getName());
}
+ else if (type instanceof javassist.bytecode.SignatureAttribute.TypeVariable)
+ {
+ return getTypeInfo(loader, spy.getTypeBound((javassist.bytecode.SignatureAttribute.TypeVariable)type), spy);
+ }
+ //Should not happen
throw new IllegalArgumentException("Bad type " + type + " - " + type.getClass().getName());
}
Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/AbstractBeanInfoTest.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/AbstractBeanInfoTest.java 2010-03-22 09:08:32 UTC (rev 102715)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/AbstractBeanInfoTest.java 2010-03-22 10:43:50 UTC (rev 102716)
@@ -68,7 +68,7 @@
super(name);
}
- protected void setJavassist()
+ protected void setJavassistConfiguration()
{
configuration = new JavassistConfiguration();
}
Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java 2010-03-22 09:08:32 UTC (rev 102715)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java 2010-03-22 10:43:50 UTC (rev 102716)
@@ -74,17 +74,20 @@
URL url1 = clazz.getProtectionDomain().getCodeSource().getLocation();
URL[] urls = {url1};
ClassLoader cl1 = new URLClassLoader(urls, null);
+ registerClassLoader(cl1);
clazz = Class.forName(ClassInfo.class.getName());
URL url2 = clazz.getProtectionDomain().getCodeSource().getLocation();
urls = new URL[]{url1, url2};
ClassLoader cl2 = new URLClassLoader(urls, null);
+ registerClassLoader(cl2);
Configuration configuration = getConfiguration();
ClassInfo ci1 = configuration.getClassInfo(className, cl1);
ClassInfo ci2 = configuration.getClassInfo(className, cl2);
assertEquals(ci1, ci2);
+ assertNotSame(ci1, ci2);
className = "org.jboss.test.beaninfo.support.BeanInfoCache";
BeanInfo bi1 = configuration.getBeanInfo(className, cl1);
@@ -135,7 +138,7 @@
@SuppressWarnings("unchecked")
protected Type getType(String type, Class<?> clazz) throws Exception
{
- Method method = getClass().getDeclaredMethod("get" + type + clazz.getSimpleName());
+ Method method = BeanInfoCacheTestCase.class.getDeclaredMethod("get" + type + clazz.getSimpleName());
return method.getGenericReturnType();
}
@@ -183,4 +186,9 @@
{
return null;
}
+
+ protected void registerClassLoader(ClassLoader cl)
+ {
+
+ }
}
\ No newline at end of file
Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoCacheTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoCacheTestCase.java (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoCacheTestCase.java 2010-03-22 10:43:50 UTC (rev 102716)
@@ -0,0 +1,97 @@
+/*
+* 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.test.beaninfo.test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javassist.ClassPool;
+import javassist.LoaderClassPath;
+import junit.framework.Test;
+
+import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl;
+import org.jboss.reflect.plugins.javassist.classpool.ClassPoolFactory;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JavassistBeanInfoCacheTestCase extends BeanInfoCacheTestCase
+{
+ MockClassPoolFactory factory = new MockClassPoolFactory();
+
+ public JavassistBeanInfoCacheTestCase(String name)
+ {
+ super(name);
+ setJavassistConfiguration();
+ JavassistTypeInfoFactoryImpl.setPoolFactory(factory);
+ }
+
+ public static Test suite()
+ {
+ return suite(JavassistBeanInfoCacheTestCase.class);
+ }
+
+
+ @Override
+ protected void registerClassLoader(ClassLoader cl)
+ {
+ factory.registerClassLoader(cl);
+ }
+
+ private static class MockClassPoolFactory implements ClassPoolFactory
+ {
+ Map<ClassLoader, ClassPool> pools = new HashMap<ClassLoader, ClassPool>();
+
+ void registerClassLoader(ClassLoader cl)
+ {
+ ClassPool pool = new ClassLoaderAwareClassPool(ClassPool.getDefault(), cl);
+ pools.put(cl, pool);
+ }
+
+ public ClassPool getPoolForLoader(ClassLoader classLoader)
+ {
+ ClassPool pool = pools.get(classLoader);
+ if (pool != null)
+ return pool;
+ return ClassPool.getDefault();
+ }
+ }
+
+ private static class ClassLoaderAwareClassPool extends ClassPool
+ {
+ ClassLoader cl;
+ public ClassLoaderAwareClassPool(ClassPool parent, ClassLoader cl)
+ {
+ super(parent);
+ this.cl = cl;
+ childFirstLookup = true;
+ appendClassPath(new LoaderClassPath(cl));
+ }
+
+ public ClassLoader getClassLoader()
+ {
+ return cl;
+ }
+ }
+}
Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoUnitTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoUnitTestCase.java 2010-03-22 09:08:32 UTC (rev 102715)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoUnitTestCase.java 2010-03-22 10:43:50 UTC (rev 102716)
@@ -39,7 +39,7 @@
public JavassistBeanInfoUnitTestCase(String name)
{
super(name);
- setJavassist();
+ setJavassistConfiguration();
}
}
\ No newline at end of file
Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoUtilTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoUtilTestCase.java (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoUtilTestCase.java 2010-03-22 10:43:50 UTC (rev 102716)
@@ -0,0 +1,44 @@
+/*
+* 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.test.beaninfo.test;
+
+import junit.framework.Test;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JavassistBeanInfoUtilTestCase extends BeanInfoUtilTestCase
+{
+ public JavassistBeanInfoUtilTestCase(String name)
+ {
+ super(name);
+ setJavassistConfiguration();
+ }
+
+ public static Test suite()
+ {
+ return suite(JavassistBeanInfoUtilTestCase.class);
+ }
+
+}
Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/support/NumberChild.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/support/NumberChild.java 2010-03-22 09:08:32 UTC (rev 102715)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/support/NumberChild.java 2010-03-22 10:43:50 UTC (rev 102716)
@@ -29,6 +29,8 @@
public class NumberChild extends Number
{
+ private static final long serialVersionUID = 1L;
+
@Override
public double doubleValue()
{
More information about the jboss-cvs-commits
mailing list