public Set<Class<?>> getClassesInJar(URL jartoScan, Set<Class<? extends Annotation>> annotationsToLookFor) {
if (jartoScan == null) {
throw MESSAGES.nullVar("jartoScan");
}
JPA_LOGGER.tracef("getClassesInJar url=%s annotations=%s", jartoScan.getPath(), annotationsToLookFor);
PersistenceUnitMetadata pu = PERSISTENCE_UNIT_METADATA_TLS.get();
if (pu == null) {
throw MESSAGES.missingPersistenceUnitMetadata();
}
if (pu.getAnnotationIndex() != null) {
Index index = getJarFileIndex(jartoScan, pu);
if (index == null) {
JPA_LOGGER.tracef("No classes to scan for annotations in jar '%s' (jars with classes '%s')",
jartoScan, pu.getAnnotationIndex().keySet());
return new HashSet<Class<?>>();
}
if (annotationsToLookFor == null) {
throw MESSAGES.nullVar("annotationsToLookFor");
}
if (annotationsToLookFor.size() == 0) {
throw MESSAGES.emptyParameter("annotationsToLookFor");
}
Set<Class<?>> result = new HashSet<Class<?>>();
for (Class<? extends Annotation> annClass : annotationsToLookFor) {
DotName annotation = DotName.createSimple(annClass.getName());
List<AnnotationInstance> classesWithAnnotation = index.getAnnotations(annotation);
Set<Class<?>> classesForAnnotation = new HashSet<Class<?>>();
for (AnnotationInstance annotationInstance : classesWithAnnotation) {
// verify that the annotation target is actually a class, since some frameworks
// may generate bytecode with annotations placed on methods (see AS7-2559)
if (annotationInstance.target() instanceof ClassInfo) {
String className = annotationInstance.target().toString();
try {
JPA_LOGGER.tracef("getClassesInJar found class %s with annotation %s", className, annClass.getName());
Class<?> clazz = pu.getClassLoader().loadClass(className);
result.add(clazz);
classesForAnnotation.add(clazz);
// TODO: fix temp classloader (get CFNE on entity class)
//result.add(pu.getNewTempClassLoader().loadClass(className));
} catch (ClassNotFoundException e) {