use of org.jboss.jandex.ClassInfo in project wildfly by wildfly.
the class EjbResourceInjectionAnnotationProcessor method deploy.
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
final List<AnnotationInstance> resourceAnnotations = index.getAnnotations(EJB_ANNOTATION_NAME);
PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
for (AnnotationInstance annotation : resourceAnnotations) {
final AnnotationTarget annotationTarget = annotation.target();
final EJBResourceWrapper annotationWrapper = new EJBResourceWrapper(annotation, propertyReplacer);
if (annotationTarget instanceof FieldInfo) {
processField(deploymentUnit, annotationWrapper, (FieldInfo) annotationTarget, moduleDescription);
} else if (annotationTarget instanceof MethodInfo) {
processMethod(deploymentUnit, annotationWrapper, (MethodInfo) annotationTarget, moduleDescription);
} else if (annotationTarget instanceof ClassInfo) {
processClass(deploymentUnit, annotationWrapper, (ClassInfo) annotationTarget, moduleDescription);
}
}
final List<AnnotationInstance> ejbsAnnotations = index.getAnnotations(EJBS_ANNOTATION_NAME);
for (AnnotationInstance annotation : ejbsAnnotations) {
final AnnotationTarget annotationTarget = annotation.target();
if (annotationTarget instanceof ClassInfo) {
final AnnotationValue annotationValue = annotation.value();
final AnnotationInstance[] ejbAnnotations = annotationValue.asNestedArray();
for (AnnotationInstance ejbAnnotation : ejbAnnotations) {
final EJBResourceWrapper annotationWrapper = new EJBResourceWrapper(ejbAnnotation, propertyReplacer);
processClass(deploymentUnit, annotationWrapper, (ClassInfo) annotationTarget, moduleDescription);
}
} else {
throw EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(EJBs.class.getName(), annotation.target());
}
}
}
use of org.jboss.jandex.ClassInfo in project wildfly by wildfly.
the class MessageDrivenComponentDescriptionFactory method processMessageBeans.
private void processMessageBeans(final DeploymentUnit deploymentUnit, final Collection<AnnotationInstance> messageBeanAnnotations, final CompositeIndex compositeIndex) throws DeploymentUnitProcessingException {
if (messageBeanAnnotations.isEmpty())
return;
final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
final PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName();
DeploymentDescriptorEnvironment deploymentDescriptorEnvironment = null;
for (final AnnotationInstance messageBeanAnnotation : messageBeanAnnotations) {
final AnnotationTarget target = messageBeanAnnotation.target();
final ClassInfo beanClassInfo = (ClassInfo) target;
if (!assertMDBClassValidity(beanClassInfo)) {
continue;
}
final String ejbName = beanClassInfo.name().local();
final AnnotationValue nameValue = messageBeanAnnotation.value("name");
final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? ejbName : propertyReplacer.replaceProperties(nameValue.asString());
final MessageDrivenBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName, MessageDrivenBeanMetaData.class);
final String beanClassName;
final String messageListenerInterfaceName;
final Properties activationConfigProperties = getActivationConfigProperties(messageBeanAnnotation, propertyReplacer);
final String messagingType;
if (beanMetaData != null) {
beanClassName = override(beanClassInfo.name().toString(), beanMetaData.getEjbClass());
deploymentDescriptorEnvironment = new DeploymentDescriptorEnvironment("java:comp/env/", beanMetaData);
if (beanMetaData instanceof MessageDrivenBeanMetaData) {
//It may actually be GenericBeanMetadata instance
final MessageDrivenBeanMetaData mdb = (MessageDrivenBeanMetaData) beanMetaData;
messagingType = mdb.getMessagingType();
final ActivationConfigMetaData activationConfigMetaData = mdb.getActivationConfig();
if (activationConfigMetaData != null) {
final ActivationConfigPropertiesMetaData propertiesMetaData = activationConfigMetaData.getActivationConfigProperties();
if (propertiesMetaData != null) {
for (final ActivationConfigPropertyMetaData propertyMetaData : propertiesMetaData) {
activationConfigProperties.put(propertyMetaData.getKey(), propertyMetaData.getValue());
}
}
}
} else if (beanMetaData instanceof JBossGenericBeanMetaData) {
//TODO: fix the hierarchy so this is not needed
final JBossGenericBeanMetaData mdb = (JBossGenericBeanMetaData) beanMetaData;
messagingType = mdb.getMessagingType();
final ActivationConfigMetaData activationConfigMetaData = mdb.getActivationConfig();
if (activationConfigMetaData != null) {
final ActivationConfigPropertiesMetaData propertiesMetaData = activationConfigMetaData.getActivationConfigProperties();
if (propertiesMetaData != null) {
for (final ActivationConfigPropertyMetaData propertyMetaData : propertiesMetaData) {
activationConfigProperties.put(propertyMetaData.getKey(), propertyMetaData.getValue());
}
}
}
} else {
messagingType = null;
}
messageListenerInterfaceName = messagingType != null ? messagingType : getMessageListenerInterface(compositeIndex, messageBeanAnnotation);
} else {
beanClassName = beanClassInfo.name().toString();
messageListenerInterfaceName = getMessageListenerInterface(compositeIndex, messageBeanAnnotation);
}
final String defaultResourceAdapterName = this.getDefaultResourceAdapterName(deploymentUnit.getServiceRegistry());
final MessageDrivenComponentDescription beanDescription = new MessageDrivenComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, messageListenerInterfaceName, activationConfigProperties, defaultResourceAdapterName, beanMetaData);
beanDescription.setDeploymentDescriptorEnvironment(deploymentDescriptorEnvironment);
addComponent(deploymentUnit, beanDescription);
}
EjbDeploymentMarker.mark(deploymentUnit);
}
use of org.jboss.jandex.ClassInfo in project wildfly by wildfly.
the class HibernateAnnotationScanner method getClassesInJar.
@Override
public Set<Class<?>> getClassesInJar(URL jarToScan, Set<Class<? extends Annotation>> annotationsToLookFor) {
if (jarToScan == null) {
throw JPA_LOGGER.nullVar("jarToScan");
}
JPA_LOGGER.tracef("getClassesInJar url=%s annotations=%s", jarToScan.getPath(), annotationsToLookFor);
PersistenceUnitMetadata pu = PERSISTENCE_UNIT_METADATA_TLS.get();
if (pu == null) {
throw JPA_LOGGER.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 JPA_LOGGER.nullVar("annotationsToLookFor");
}
if (annotationsToLookFor.size() == 0) {
throw JPA_LOGGER.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) {
// 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.cacheTempClassLoader().loadClass(className);
result.add(clazz);
classesForAnnotation.add(clazz);
} catch (ClassNotFoundException e) {
JPA_LOGGER.cannotLoadEntityClass(e, className);
} catch (NoClassDefFoundError e) {
JPA_LOGGER.cannotLoadEntityClass(e, className);
}
}
}
cacheClasses(pu, jarToScan, annClass, classesForAnnotation);
}
return result;
} else {
return getCachedClasses(pu, jarToScan, annotationsToLookFor);
}
}
use of org.jboss.jandex.ClassInfo in project wildfly by wildfly.
the class HibernateAnnotationScanner method getPackagesInJar.
@Override
public Set<Package> getPackagesInJar(URL jarToScan, Set<Class<? extends Annotation>> annotationsToLookFor) {
if (jarToScan == null) {
throw JPA_LOGGER.nullVar("jarToScan");
}
JPA_LOGGER.tracef("getPackagesInJar url=%s annotations=%s", jarToScan.getPath(), annotationsToLookFor);
Set<Class<?>> resultClasses = new HashSet<Class<?>>();
PersistenceUnitMetadata pu = PERSISTENCE_UNIT_METADATA_TLS.get();
if (pu == null) {
throw JPA_LOGGER.missingPersistenceUnitMetadata();
}
if (annotationsToLookFor.size() > 0) {
// Hibernate doesn't pass any annotations currently
resultClasses = getClassesInJar(jarToScan, annotationsToLookFor);
} else {
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<Package>();
}
Collection<ClassInfo> allClasses = index.getKnownClasses();
for (ClassInfo classInfo : allClasses) {
String className = classInfo.name().toString();
try {
resultClasses.add(pu.cacheTempClassLoader().loadClass(className));
} catch (ClassNotFoundException e) {
JPA_LOGGER.cannotLoadEntityClass(e, className);
} catch (NoClassDefFoundError e) {
JPA_LOGGER.cannotLoadEntityClass(e, className);
}
}
}
}
if (pu.getAnnotationIndex() != null || annotationsToLookFor.size() > 0) {
Map<String, Package> uniquePackages = new HashMap<String, Package>();
for (Class<?> classWithAnnotation : resultClasses) {
Package classPackage = classWithAnnotation.getPackage();
if (classPackage != null) {
JPA_LOGGER.tracef("getPackagesInJar found package %s", classPackage);
uniquePackages.put(classPackage.getName(), classPackage);
}
}
Set<Package> packages = new HashSet<Package>(uniquePackages.values());
cachePackages(pu, jarToScan, packages);
return new HashSet<Package>(packages);
} else {
return getCachedPackages(pu, jarToScan);
}
}
use of org.jboss.jandex.ClassInfo in project wildfly by wildfly.
the class ServletContainerInitializerDeploymentProcessor method deploy.
/**
* Process SCIs.
*/
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
final ServiceModuleLoader loader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
// Skip non web deployments
return;
}
WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
assert warMetaData != null;
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
if (module == null) {
throw UndertowLogger.ROOT_LOGGER.failedToResolveModule(deploymentUnit);
}
final ClassLoader classLoader = module.getClassLoader();
ScisMetaData scisMetaData = deploymentUnit.getAttachment(ScisMetaData.ATTACHMENT_KEY);
if (scisMetaData == null) {
scisMetaData = new ScisMetaData();
deploymentUnit.putAttachment(ScisMetaData.ATTACHMENT_KEY, scisMetaData);
}
Set<ServletContainerInitializer> scis = scisMetaData.getScis();
Set<Class<? extends ServletContainerInitializer>> sciClasses = new HashSet<>();
if (scis == null) {
scis = new HashSet<ServletContainerInitializer>();
scisMetaData.setScis(scis);
}
Map<ServletContainerInitializer, Set<Class<?>>> handlesTypes = scisMetaData.getHandlesTypes();
if (handlesTypes == null) {
handlesTypes = new HashMap<ServletContainerInitializer, Set<Class<?>>>();
scisMetaData.setHandlesTypes(handlesTypes);
}
// Find the SCIs from shared modules
for (ModuleDependency dependency : moduleSpecification.getAllDependencies()) {
try {
Module depModule = loader.loadModule(dependency.getIdentifier());
ServiceLoader<ServletContainerInitializer> serviceLoader = depModule.loadService(ServletContainerInitializer.class);
for (ServletContainerInitializer service : serviceLoader) {
if (sciClasses.add(service.getClass())) {
scis.add(service);
}
}
} catch (ModuleLoadException e) {
if (dependency.isOptional() == false) {
throw UndertowLogger.ROOT_LOGGER.errorLoadingSCIFromModule(dependency.getIdentifier(), e);
}
}
}
// Find local ServletContainerInitializer services
List<String> order = warMetaData.getOrder();
Map<String, VirtualFile> localScis = warMetaData.getScis();
if (order != null && localScis != null) {
for (String jar : order) {
VirtualFile sci = localScis.get(jar);
if (sci != null) {
scis.addAll(loadSci(classLoader, sci, jar, true, sciClasses));
}
}
}
// Process HandlesTypes for ServletContainerInitializer
Map<Class<?>, Set<ServletContainerInitializer>> typesMap = new HashMap<Class<?>, Set<ServletContainerInitializer>>();
for (ServletContainerInitializer service : scis) {
if (service.getClass().isAnnotationPresent(HandlesTypes.class)) {
HandlesTypes handlesTypesAnnotation = service.getClass().getAnnotation(HandlesTypes.class);
Class<?>[] typesArray = handlesTypesAnnotation.value();
if (typesArray != null) {
for (Class<?> type : typesArray) {
Set<ServletContainerInitializer> servicesSet = typesMap.get(type);
if (servicesSet == null) {
servicesSet = new HashSet<ServletContainerInitializer>();
typesMap.put(type, servicesSet);
}
servicesSet.add(service);
handlesTypes.put(service, new HashSet<Class<?>>());
}
}
}
}
Class<?>[] typesArray = typesMap.keySet().toArray(new Class<?>[0]);
final CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
if (index == null) {
throw UndertowLogger.ROOT_LOGGER.unableToResolveAnnotationIndex(deploymentUnit);
}
//WFLY-4205, look in the parent as well as the war
CompositeIndex parentIndex = deploymentUnit.getParent() == null ? null : deploymentUnit.getParent().getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
// Find classes which extend, implement, or are annotated by HandlesTypes
for (Class<?> type : typesArray) {
DotName className = DotName.createSimple(type.getName());
Set<ClassInfo> classInfos = new HashSet<>();
classInfos.addAll(processHandlesType(className, type, index));
if (parentIndex != null) {
classInfos.addAll(processHandlesType(className, type, parentIndex));
}
Set<Class<?>> classes = loadClassInfoSet(classInfos, classLoader);
Set<ServletContainerInitializer> sciSet = typesMap.get(type);
for (ServletContainerInitializer sci : sciSet) {
handlesTypes.get(sci).addAll(classes);
}
}
}
Aggregations