[jboss-cvs] JBossAS SVN: r95169 - in projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki: scanner and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Oct 20 09:14:00 EDT 2009
Author: alesj
Date: 2009-10-20 09:14:00 -0400 (Tue, 20 Oct 2009)
New Revision: 95169
Modified:
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScanner.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/AbstractAnnotationScanner.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/DefaultAnnotationScanner.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/JavassistAnnotationScanner.java
Log:
Use single cl.
Modified: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScanner.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScanner.java 2009-10-20 12:40:59 UTC (rev 95168)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScanner.java 2009-10-20 13:14:00 UTC (rev 95169)
@@ -35,10 +35,10 @@
* Scan using the context class loader as well as the additional
* classloaders specified to resolve annotation class definitions.
*
- * @param urls The URLs with the .jar files
- * @param cls Additional class loaders
+ * @param urls the URLs
+ * @param classLoader the class loader
* @return The annotation repository
* @throws Exception for any error
*/
- AnnotationRepository scan(URL[] urls, ClassLoader... cls) throws Exception;
+ AnnotationRepository scan(URL[] urls, ClassLoader classLoader) throws Exception;
}
Modified: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/AbstractAnnotationScanner.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/AbstractAnnotationScanner.java 2009-10-20 12:40:59 UTC (rev 95168)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/AbstractAnnotationScanner.java 2009-10-20 13:14:00 UTC (rev 95169)
@@ -41,27 +41,38 @@
*/
public abstract class AbstractAnnotationScanner<T extends AnnotationRepository> implements AnnotationScanner
{
- public AnnotationRepository scan(URL[] urls, ClassLoader... cls) throws Exception
+ public AnnotationRepository scan(URL[] urls, ClassLoader classLoader) throws Exception
{
- T repository = createAnnotationRepository(cls);
- List<URL> list = new ArrayList<URL>();
- for (URL url : urls)
+ T repository = createAnnotationRepository(classLoader);
+
+ // something in javassist uses TCL
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(classLoader);
+ try
{
- VFS vfs = VFS.getVFS(url);
- VirtualFile file = vfs.getChild("META-INF/" + AnnotationRepository.PAPAKI_METADATA_BINARY);
- if (file != null)
- reattach(repository, file, cls);
- else
- list.add(url);
- }
+ List<URL> list = new ArrayList<URL>();
+ for (URL url : urls)
+ {
+ VFS vfs = VFS.getVFS(url);
+ VirtualFile file = vfs.getChild("META-INF/" + AnnotationRepository.PAPAKI_METADATA_BINARY);
+ if (file != null)
+ reattach(repository, file, classLoader);
+ else
+ list.add(url);
+ }
- if (list.isEmpty() == false)
- rescan(repository, list.toArray(new URL[list.size()]), cls);
+ if (list.isEmpty() == false)
+ rescan(repository, list.toArray(new URL[list.size()]), classLoader);
- return repository;
+ return repository;
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(tcl);
+ }
}
- protected void reattach(T repo, VirtualFile papaki, ClassLoader... cls) throws Exception
+ protected void reattach(T repo, VirtualFile papaki, ClassLoader classLoader) throws Exception
{
InputStream is = papaki.openStream();
ObjectInputStream ois;
@@ -75,11 +86,11 @@
is.close();
}
- AnnotationRepository oldRepo = (AnnotationRepository)ois.readObject();
+ AnnotationRepository oldRepo = (AnnotationRepository)ois.readObject();
repo.merge(oldRepo);
}
- protected abstract T createAnnotationRepository(ClassLoader... cls);
+ protected abstract T createAnnotationRepository(ClassLoader classLoader);
- protected abstract void rescan(T repo, URL[] urls, ClassLoader... cls) throws Exception;
+ protected abstract void rescan(T repo, URL[] urls, ClassLoader classLoader) throws Exception;
}
Modified: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/DefaultAnnotationScanner.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/DefaultAnnotationScanner.java 2009-10-20 12:40:59 UTC (rev 95168)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/DefaultAnnotationScanner.java 2009-10-20 13:14:00 UTC (rev 95169)
@@ -31,7 +31,6 @@
import org.jboss.virtual.VirtualFile;
import java.net.URL;
-import java.util.Arrays;
/**
* Default annotation scanner.
@@ -45,15 +44,12 @@
private ClassFilter excluded;
private ResourceFilter recurseFilter;
- protected DefaultAnnotationRepository createAnnotationRepository(ClassLoader... cls)
+ protected DefaultAnnotationRepository createAnnotationRepository(ClassLoader classLoader)
{
- if (cls == null || cls.length > 1)
- throw new IllegalArgumentException("Illegal cls length: " + Arrays.toString(cls));
-
- return new DefaultAnnotationRepository(cls[0]);
+ return new DefaultAnnotationRepository(classLoader);
}
- protected void rescan(DefaultAnnotationRepository repo, URL[] urls, ClassLoader... cls) throws Exception
+ protected void rescan(DefaultAnnotationRepository repo, URL[] urls, ClassLoader classLoader) throws Exception
{
VirtualFile[] roots = new VirtualFile[urls.length];
for (int i = 0; i < roots.length; i++)
@@ -61,23 +57,11 @@
roots[i] = VFS.getRoot(urls[i]);
}
- ResourceVisitor visitor = createResourceVisitor(repo, cls);
- ClassLoader classLoader = cls[0];
-
- // something in javassist uses TCL
- ClassLoader tcl = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(classLoader);
- try
- {
- VFSResourceVisitor.visit(roots, excludedRoots, included, excluded, classLoader, visitor, visitor.getFilter(), recurseFilter, urls);
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(tcl);
- }
+ ResourceVisitor visitor = createResourceVisitor(repo, classLoader);
+ VFSResourceVisitor.visit(roots, excludedRoots, included, excluded, classLoader, visitor, visitor.getFilter(), recurseFilter, urls);
}
- protected ResourceVisitor createResourceVisitor(DefaultAnnotationRepository repository, ClassLoader... cls)
+ protected ResourceVisitor createResourceVisitor(DefaultAnnotationRepository repository, ClassLoader classLoader)
{
return new GenericAnnotationResourceVisitor(repository);
}
Modified: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/JavassistAnnotationScanner.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/JavassistAnnotationScanner.java 2009-10-20 12:40:59 UTC (rev 95168)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/JavassistAnnotationScanner.java 2009-10-20 13:14:00 UTC (rev 95169)
@@ -39,18 +39,15 @@
private ClassPool pool;
@Override
- protected ResourceVisitor createResourceVisitor(DefaultAnnotationRepository repository, ClassLoader... cls)
+ protected ResourceVisitor createResourceVisitor(DefaultAnnotationRepository repository, ClassLoader classLoader)
{
ClassPool cp = pool;
if (cp == null)
cp = ClassPool.getDefault();
- for (ClassLoader cl : cls)
- {
- ClassPath classPath = new LoaderClassPath(cl);
- cp.appendClassPath(classPath);
- }
-
+ ClassPath classPath = new LoaderClassPath(classLoader);
+ cp.appendClassPath(classPath);
+
return new JavassistAnnotationResourceVisitor(repository, cp);
}
More information about the jboss-cvs-commits
mailing list