[jboss-cvs] JBossAS SVN: r102737 - projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Mar 22 18:35:30 EDT 2010
Author: alesj
Date: 2010-03-22 18:35:30 -0400 (Mon, 22 Mar 2010)
New Revision: 102737
Added:
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ClassesVisitor.java
Modified:
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ScannerImpl.java
Log:
Null checks and impl empty param behavior.
Copied: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ClassesVisitor.java (from rev 102733, projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/PatternVisitor.java)
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ClassesVisitor.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ClassesVisitor.java 2010-03-22 22:35:30 UTC (rev 102737)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.scanning.hibernate;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.classloading.spi.visitor.ClassVisitor;
+import org.jboss.classloading.spi.visitor.ResourceContext;
+
+/**
+ * Hibernate's classes visitor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ClassesVisitor extends ClassVisitor
+{
+ private Set<String> strings;
+
+ public ClassesVisitor()
+ {
+ this(null);
+ }
+
+ public ClassesVisitor(Set<String> strings)
+ {
+ if (strings == null)
+ strings = new HashSet<String>();
+ this.strings = strings;
+ }
+
+ public void visit(ResourceContext resource)
+ {
+ strings.add(resource.getClassName());
+ }
+
+ public Set<String> getStrings()
+ {
+ return strings;
+ }
+}
\ No newline at end of file
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ScannerImpl.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ScannerImpl.java 2010-03-22 22:34:50 UTC (rev 102736)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ScannerImpl.java 2010-03-22 22:35:30 UTC (rev 102737)
@@ -59,6 +59,8 @@
/** The deployment unit */
private DeploymentUnit unit;
+ /** Do we allow query invocation search */
+ private boolean allowQueryInvocationSearch; // by default false, as we expect things to be pre-indexed
/** Do we cache new results */
private boolean cacheNewResults;
@@ -155,11 +157,17 @@
public Set<Package> getPackagesInJar(URL jartoScan, Set<Class<? extends Annotation>> annotationsToLookFor)
{
+ if (jartoScan == null)
+ throw new IllegalArgumentException("Null jar to scan url");
+ if (annotationsToLookFor == null)
+ throw new IllegalArgumentException("Null annotations to look for");
+
+
if (annotationsToLookFor.size() > 0)
throw new AssertionFailure("Improper use of NativeScanner: must not filter packages");
Set<Package> p = packages.get(jartoScan);
- if (p == null)
+ if (p == null && allowQueryInvocationSearch)
{
Module module = AttachmentLocator.searchAncestors(unit, Module.class);
if (module == null)
@@ -184,47 +192,64 @@
if (cacheNewResults)
packages.put(jartoScan, p);
}
- return p;
+
+ return p != null ? Collections.unmodifiableSet(p) : Collections.<Package>emptySet();
}
public Set<Class<?>> getClassesInJar(URL jartoScan, Set<Class<? extends Annotation>> annotationsToLookFor)
{
+ if (jartoScan == null)
+ throw new IllegalArgumentException("Null jar to scan url");
+ if (annotationsToLookFor == null)
+ throw new IllegalArgumentException("Null annotations to look for");
+
Set<String> strings = new HashSet<String>();
- Set<Class<? extends Annotation>> missingCacheAnnotations = new HashSet<Class<? extends Annotation>>();
- Map<Class<? extends Annotation>, Set<String>> map = classes.get(jartoScan);
- if (map != null)
+ if (annotationsToLookFor.isEmpty())
{
- for (Class<? extends Annotation> annClass : annotationsToLookFor)
+ Module module = AttachmentLocator.searchAncestors(unit, Module.class);
+ if (module == null)
+ throw new IllegalArgumentException("No such module: " + unit);
+
+ ClassesVisitor visitor = new ClassesVisitor(strings);
+ module.visit(visitor, visitor.getFilter(), null, jartoScan);
+ }
+ else
+ {
+ Set<Class<? extends Annotation>> missingCacheAnnotations = new HashSet<Class<? extends Annotation>>();
+ Map<Class<? extends Annotation>, Set<String>> map = classes.get(jartoScan);
+ if (map != null)
{
- Set<String> s = map.get(annClass);
- if (s != null)
+ for (Class<? extends Annotation> annClass : annotationsToLookFor)
{
- strings.addAll(s);
+ Set<String> s = map.get(annClass);
+ if (s != null)
+ {
+ strings.addAll(s);
+ }
+ else
+ {
+ missingCacheAnnotations.add(annClass);
+ }
}
- else
- {
- missingCacheAnnotations.add(annClass);
- }
}
- }
- else
- {
- missingCacheAnnotations.addAll(annotationsToLookFor);
- }
+ else
+ {
+ missingCacheAnnotations.addAll(annotationsToLookFor);
+ }
- if (missingCacheAnnotations.isEmpty() == false)
- {
-
- Map<Class<? extends Annotation>, Set<String>> temp = findClasses(missingCacheAnnotations);
- if (cacheNewResults)
+ if (allowQueryInvocationSearch && missingCacheAnnotations.isEmpty() == false)
{
- if (map != null)
- map.putAll(temp);
- else
- classes.put(jartoScan, temp);
+ Map<Class<? extends Annotation>, Set<String>> temp = findClasses(missingCacheAnnotations);
+ if (cacheNewResults)
+ {
+ if (map != null)
+ map.putAll(temp);
+ else
+ classes.put(jartoScan, temp);
+ }
+ for (Set<String> vals : temp.values())
+ strings.addAll(vals);
}
- for (Set<String> vals : temp.values())
- strings.addAll(vals);
}
Set<Class<?>> result = new HashSet<Class<?>>();
@@ -240,6 +265,11 @@
public Set<NamedInputStream> getFilesInJar(URL jartoScan, Set<String> filePatterns)
{
+ if (jartoScan == null)
+ throw new IllegalArgumentException("Null jar to scan url");
+ if (filePatterns == null)
+ throw new IllegalArgumentException("Null file patterns to look for");
+
Set<NamedInputStream> result = new HashSet<NamedInputStream>();
Map<String, Set<NamedInputStream>> map = files.get(jartoScan);
if (map != null)
@@ -269,14 +299,14 @@
for (String pattern : filePatterns)
{
Set<NamedInputStream> niss = map.get(pattern);
- if (niss == null)
+ if (niss == null && allowQueryInvocationSearch)
{
if (root == null)
root = getFile(jartoScan);
try
{
- List<VirtualFile> children = root.getChildren(new PatternFilter(pattern));
+ List<VirtualFile> children = root.getChildrenRecursively(new PatternFilter(pattern));
niss = toNIS(children);
if (cacheNewResults)
map.put(pattern, niss);
@@ -316,6 +346,10 @@
public String getUnqualifiedJarName(URL jarUrl)
{
+ if (jarUrl == null)
+ throw new IllegalArgumentException("Null jar url");
+
+
VirtualFile file = getFile(jarUrl);
return file.getName();
}
@@ -332,6 +366,11 @@
}
}
+ public void setAllowQueryInvocationSearch(boolean allowQueryInvocationSearch)
+ {
+ this.allowQueryInvocationSearch = allowQueryInvocationSearch;
+ }
+
public void setCacheNewResults(boolean cacheNewResults)
{
this.cacheNewResults = cacheNewResults;
More information about the jboss-cvs-commits
mailing list