[jboss-cvs] JBossAS SVN: r95398 - in projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann: repository and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Oct 22 08:58:59 EDT 2009
Author: alesj
Date: 2009-10-22 08:58:59 -0400 (Thu, 22 Oct 2009)
New Revision: 95398
Modified:
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/AnnotationScannerFactory.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultConfiguration.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/GenericAnnotationResourceVisitor.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/IntrospectionTypeInfoProvider.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/TypeInfoProvider.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/javassist/JavassistTypeInfoProvider.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/scanner/DefaultAnnotationScanner.java
Log:
TypeInfoProvider needs before/after, to be able to cleanup; e.g. Javassist pools.
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/AnnotationScannerFactory.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/AnnotationScannerFactory.java 2009-10-22 12:49:08 UTC (rev 95397)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/AnnotationScannerFactory.java 2009-10-22 12:58:59 UTC (rev 95398)
@@ -52,11 +52,6 @@
*/
static boolean haveJavassist = false;
- /**
- * Javassist configuration
- */
- private static DefaultConfiguration configuration;
-
static
{
try
@@ -77,10 +72,6 @@
{
defaultStrategy = JAVA_LANG_REFLECT;
}
-
- // javassist type info
- configuration = new DefaultConfiguration();
- configuration.setTypeInfoProvider(new JavassistTypeInfoProvider());
}
/**
@@ -113,7 +104,11 @@
DefaultAnnotationScanner scanner = new DefaultAnnotationScanner();
if (strategy == JAVASSIST)
+ {
+ DefaultConfiguration configuration = new DefaultConfiguration();
+ configuration.setTypeInfoProvider(new JavassistTypeInfoProvider());
scanner.setConfiguration(configuration);
+ }
return scanner;
}
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultConfiguration.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultConfiguration.java 2009-10-22 12:49:08 UTC (rev 95397)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultConfiguration.java 2009-10-22 12:58:59 UTC (rev 95398)
@@ -37,7 +37,7 @@
private boolean keepAnnotations;
private boolean checkInterfaces;
private boolean checkSuper;
- private TypeInfoProvider typeInfoProvider = new IntrospectionTypeInfoProvider();
+ private TypeInfoProvider typeInfoProvider = IntrospectionTypeInfoProvider.INSTANCE;
public DefaultConfiguration()
{
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/GenericAnnotationResourceVisitor.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/GenericAnnotationResourceVisitor.java 2009-10-22 12:49:08 UTC (rev 95397)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/GenericAnnotationResourceVisitor.java 2009-10-22 12:58:59 UTC (rev 95398)
@@ -53,19 +53,17 @@
private DefaultAnnotationRepository repository;
private Configuration configuration;
- public GenericAnnotationResourceVisitor(DefaultAnnotationRepository repository)
+ public GenericAnnotationResourceVisitor(DefaultAnnotationRepository repository, Configuration configuration)
{
+ if (repository == null)
+ throw new IllegalArgumentException("Null repository.");
+ if (configuration == null)
+ throw new IllegalArgumentException("Null configuration");
+
this.repository = repository;
+ this.configuration = configuration;
}
- protected synchronized Configuration configuration()
- {
- if (configuration == null)
- configuration = new DefaultConfiguration();
-
- return configuration;
- }
-
@SuppressWarnings("deprecation")
protected boolean isRelevant(ClassInfo ci)
{
@@ -74,7 +72,7 @@
protected ClassInfo createClassInfo(ResourceContext context) throws Exception
{
- TypeInfoProvider typeInfoProvider = configuration().typeInfoProvider();
+ TypeInfoProvider typeInfoProvider = configuration.typeInfoProvider();
TypeInfo typeInfo = typeInfoProvider.createTypeInfo(context);
if (typeInfo instanceof ClassInfo == false)
throw new IllegalArgumentException("Can only handle class info: " + typeInfo);
@@ -84,7 +82,7 @@
public ResourceFilter getFilter()
{
- return configuration().resourceFilter();
+ return configuration.resourceFilter();
}
public void visit(ResourceContext resource)
@@ -102,15 +100,11 @@
}
}
}
- catch (ClassNotFoundException e)
- {
- if (configuration().forceAnnotations())
- throw new RuntimeException(e);
-
- logThrowable(resource, e);
- }
catch (Throwable t)
{
+ if (configuration.forceAnnotations())
+ throw new RuntimeException(t);
+
logThrowable(resource, t);
}
}
@@ -122,7 +116,7 @@
*/
protected List<CommitElement> createCommitList()
{
- return configuration().forceAnnotations() ? new RepositoryPutList(repository) : new ArrayList<CommitElement>();
+ return configuration.forceAnnotations() ? new RepositoryPutList(repository) : new ArrayList<CommitElement>();
}
/**
@@ -146,7 +140,7 @@
*/
protected void handleClass(ClassInfo classInfo, List<CommitElement> commit) throws Exception
{
- if (classInfo == null || configuration().isRelevant(classInfo) == false)
+ if (classInfo == null || configuration.isRelevant(classInfo) == false)
return;
String className = classInfo.getName();
@@ -167,8 +161,8 @@
handleMembers(ElementType.METHOD, classInfo.getDeclaredMethods(), className, commit);
handleMembers(ElementType.FIELD, classInfo.getDeclaredFields(), className, commit);
- boolean checkInterfaces = configuration().checkInterfaces();
- boolean checkSuper = configuration().checkSuper();
+ boolean checkInterfaces = configuration.checkInterfaces();
+ boolean checkSuper = configuration.checkSuper();
if (checkInterfaces || checkSuper)
{
if (checkInterfaces)
@@ -312,14 +306,4 @@
}
}
}
-
- /**
- * Set configuration().
- *
- * @param configuration the configuration
- */
- public synchronized void setConfiguration(Configuration configuration)
- {
- this.configuration = configuration;
- }
}
\ No newline at end of file
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/IntrospectionTypeInfoProvider.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/IntrospectionTypeInfoProvider.java 2009-10-22 12:49:08 UTC (rev 95397)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/IntrospectionTypeInfoProvider.java 2009-10-22 12:58:59 UTC (rev 95398)
@@ -30,9 +30,19 @@
* Introspection type info provider
*/
public class IntrospectionTypeInfoProvider implements TypeInfoProvider
-{
+{
+ public static final TypeInfoProvider INSTANCE = new IntrospectionTypeInfoProvider();
+
private TypeInfoFactory factory = new IntrospectionTypeInfoFactory();
+ public void beforeVisit(ClassLoader classLoader)
+ {
+ }
+
+ public void afterVisit(ClassLoader classLoader)
+ {
+ }
+
public TypeInfo createTypeInfo(ResourceContext context) throws Exception
{
return factory.getTypeInfo(context.loadClass());
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/TypeInfoProvider.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/TypeInfoProvider.java 2009-10-22 12:49:08 UTC (rev 95397)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/TypeInfoProvider.java 2009-10-22 12:58:59 UTC (rev 95398)
@@ -32,6 +32,20 @@
public interface TypeInfoProvider
{
/**
+ * Prepare provider before visiting resources.
+ *
+ * @param classLoader the classLoader
+ */
+ void beforeVisit(ClassLoader classLoader);
+
+ /**
+ * Cleanup provider after visiting resources.
+ *
+ * @param classLoader the classLoader
+ */
+ void afterVisit(ClassLoader classLoader);
+
+ /**
* Create type info.
*
* @param context the resource context
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/javassist/JavassistTypeInfoProvider.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/javassist/JavassistTypeInfoProvider.java 2009-10-22 12:49:08 UTC (rev 95397)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/javassist/JavassistTypeInfoProvider.java 2009-10-22 12:58:59 UTC (rev 95398)
@@ -23,8 +23,10 @@
import java.io.InputStream;
+import javassist.ClassPath;
import javassist.ClassPool;
import javassist.CtClass;
+import javassist.LoaderClassPath;
import org.jboss.classloading.spi.visitor.ResourceContext;
import org.jboss.mcann.repository.TypeInfoProvider;
import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl;
@@ -40,6 +42,7 @@
public class JavassistTypeInfoProvider implements TypeInfoProvider
{
private ClassPool pool;
+ private ClassPath path;
public JavassistTypeInfoProvider()
{
@@ -50,32 +53,45 @@
this.pool = pool;
}
- protected ClassPool getClassPool(ResourceContext context)
+ public void beforeVisit(ClassLoader classLoader)
{
- ClassPool cp = pool;
- if (cp == null)
+ if (pool == null)
{
ClassPoolFactory factory = JavassistTypeInfoFactoryImpl.getPoolFactory();
- cp = factory.getPoolForLoader(context.getClassLoader());
+ ClassPool cp = factory.getPoolForLoader(classLoader);
- if (cp == null)
- cp = ClassPool.getDefault();
+ ClassPool defaultCP = ClassPool.getDefault();
+ if (cp == null || cp == defaultCP)
+ {
+ cp = new ClassPool(defaultCP);
+ path = new LoaderClassPath(classLoader);
+ cp.appendClassPath(path);
+ }
+
+ pool = cp;
}
+ }
- return cp;
+ public void afterVisit(ClassLoader classLoader)
+ {
+ if (path != null)
+ {
+ ClassPool cp = pool;
+ pool = null;
+ cp.removeClassPath(path);
+ path = null;
+ }
}
public TypeInfo createTypeInfo(ResourceContext context) throws Exception
{
- ClassPool cp = getClassPool(context);
-
InputStream stream = context.getInputStream();
if (stream == null)
throw new IllegalArgumentException("Null stream: " + context);
try
{
- CtClass ctClass = cp.makeClass(stream);
+ CtClass ctClass = pool.makeClass(stream);
return JavassistUtil.toTypeInfo(ctClass);
}
finally
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/scanner/DefaultAnnotationScanner.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/scanner/DefaultAnnotationScanner.java 2009-10-22 12:49:08 UTC (rev 95397)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/scanner/DefaultAnnotationScanner.java 2009-10-22 12:58:59 UTC (rev 95398)
@@ -30,6 +30,8 @@
import org.jboss.mcann.repository.Configuration;
import org.jboss.mcann.repository.DefaultAnnotationRepository;
import org.jboss.mcann.repository.GenericAnnotationResourceVisitor;
+import org.jboss.mcann.repository.DefaultConfiguration;
+import org.jboss.mcann.repository.TypeInfoProvider;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
@@ -40,7 +42,7 @@
*/
public class DefaultAnnotationScanner extends AbstractAnnotationScanner<DefaultAnnotationRepository>
{
- protected Configuration configuration;
+ protected Configuration configuration = new DefaultConfiguration();
protected VirtualFile[] excludedRoots;
protected ClassFilter included;
protected ClassFilter excluded;
@@ -54,13 +56,33 @@
protected void rescan(DefaultAnnotationRepository repo, URL[] urls, ClassLoader classLoader) throws Exception
{
ResourceVisitor visitor = createResourceVisitor(repo);
- ResourceFilter filter = (configuration != null) ? configuration.resourceFilter() : null;
+ ResourceFilter filter = configuration.resourceFilter();
if (filter == null)
filter = visitor.getFilter();
- visit(classLoader, urls, visitor, filter);
+ beforeVisit(classLoader);
+ try
+ {
+ visit(classLoader, urls, visitor, filter);
+ }
+ finally
+ {
+ afterVisit(classLoader);
+ }
}
+ protected void beforeVisit(ClassLoader classLoader)
+ {
+ TypeInfoProvider typeInfoProvider = configuration.typeInfoProvider();
+ typeInfoProvider.beforeVisit(classLoader);
+ }
+
+ protected void afterVisit(ClassLoader classLoader)
+ {
+ TypeInfoProvider typeInfoProvider = configuration.typeInfoProvider();
+ typeInfoProvider.afterVisit(classLoader);
+ }
+
protected void visit(ClassLoader classLoader, URL[] urls, ResourceVisitor visitor, ResourceFilter filter) throws Exception
{
VirtualFile[] roots = new VirtualFile[urls.length];
@@ -74,13 +96,13 @@
protected ResourceVisitor createResourceVisitor(DefaultAnnotationRepository repository)
{
- GenericAnnotationResourceVisitor visitor = new GenericAnnotationResourceVisitor(repository);
- visitor.setConfiguration(configuration);
- return visitor;
+ return new GenericAnnotationResourceVisitor(repository, configuration);
}
public void setConfiguration(Configuration configuration)
{
+ if (configuration == null)
+ throw new IllegalArgumentException("Null configuration");
this.configuration = configuration;
}
More information about the jboss-cvs-commits
mailing list