Search in sources :

Example 1 with DotName

use of org.jboss.jandex.DotName in project wildfly by wildfly.

the class JSFAnnotationProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Map<Class<? extends Annotation>, Set<Class<?>>> instances = new HashMap<Class<? extends Annotation>, Set<Class<?>>>();
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (compositeIndex == null) {
        // Can not continue without index
        return;
    }
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (module == null) {
        // Can not continue without module
        return;
    }
    final ClassLoader classLoader = module.getClassLoader();
    for (FacesAnnotation annotation : FacesAnnotation.values()) {
        final List<AnnotationInstance> annotationInstances = compositeIndex.getAnnotations(annotation.indexName);
        if (annotationInstances == null || annotationInstances.isEmpty()) {
            continue;
        }
        final Set<Class<?>> discoveredClasses = new HashSet<Class<?>>();
        instances.put(annotation.annotationClass, discoveredClasses);
        for (AnnotationInstance annotationInstance : annotationInstances) {
            final AnnotationTarget target = annotationInstance.target();
            if (target instanceof ClassInfo) {
                final DotName className = ClassInfo.class.cast(target).name();
                final Class<?> annotatedClass;
                try {
                    annotatedClass = classLoader.loadClass(className.toString());
                } catch (ClassNotFoundException e) {
                    throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.classLoadingFailed(className));
                }
                discoveredClasses.add(annotatedClass);
            } else {
                throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.invalidAnnotationLocation(annotation, target));
            }
        }
    }
    deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(FACES_ANNOTATIONS_SC_ATTR, instances));
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) DotName(org.jboss.jandex.DotName) Annotation(java.lang.annotation.Annotation) ServletContextAttribute(org.jboss.as.web.common.ServletContextAttribute) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance) HashSet(java.util.HashSet) ClassInfo(org.jboss.jandex.ClassInfo)

Example 2 with DotName

use of org.jboss.jandex.DotName 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);
        }
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) VirtualFile(org.jboss.vfs.VirtualFile) HashSet(java.util.HashSet) Set(java.util.Set) ModuleDependency(org.jboss.as.server.deployment.module.ModuleDependency) HashMap(java.util.HashMap) WarMetaData(org.jboss.as.web.common.WarMetaData) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) DotName(org.jboss.jandex.DotName) ServletContainerInitializer(javax.servlet.ServletContainerInitializer) HandlesTypes(javax.servlet.annotation.HandlesTypes) HashSet(java.util.HashSet) ServiceModuleLoader(org.jboss.as.server.moduleservice.ServiceModuleLoader) ModuleSpecification(org.jboss.as.server.deployment.module.ModuleSpecification) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) ClassInfo(org.jboss.jandex.ClassInfo)

Example 3 with DotName

use of org.jboss.jandex.DotName in project wildfly by wildfly.

the class WSClassVerificationProcessor method verifyApacheCXFModuleDependencyRequirement.

private void verifyApacheCXFModuleDependencyRequirement(DeploymentUnit unit) {
    if (!hasCxfModuleDependency(unit)) {
        //notify user if he clearly forgot the CXF module dependency
        final CompositeIndex index = unit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
        final DotName[] dotNames = { WEB_SERVICE_ANNOTATION, WEB_SERVICE_PROVIDER_ANNOTATION };
        for (final DotName dotName : dotNames) {
            for (AnnotationInstance ai : index.getAnnotations(dotName)) {
                AnnotationTarget at = ai.target();
                if (at instanceof ClassInfo) {
                    final ClassInfo clazz = (ClassInfo) ai.target();
                    for (DotName dn : clazz.annotations().keySet()) {
                        if (dn.toString().startsWith("org.apache.cxf")) {
                            WSLogger.ROOT_LOGGER.missingModuleDependency(dn.toString(), clazz.name().toString(), "org.apache.cxf");
                        }
                    }
                }
            }
        }
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) DotName(org.jboss.jandex.DotName) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 4 with DotName

use of org.jboss.jandex.DotName in project wildfly by wildfly.

the class ASHelper method isJaxwsService.

public static boolean isJaxwsService(final ClassInfo current, final CompositeIndex index) {
    ClassInfo tmp = current;
    while (tmp != null) {
        final DotName superName = tmp.superName();
        if (JAXWS_SERVICE_CLASS.equals(superName)) {
            return true;
        }
        tmp = index.getClassByName(superName);
    }
    return false;
}
Also used : DotName(org.jboss.jandex.DotName) ClassInfo(org.jboss.jandex.ClassInfo)

Example 5 with DotName

use of org.jboss.jandex.DotName in project wildfly by wildfly.

the class WeldClassFileInfo method isAssignableTo.

/**
     * @param to
     * @param name
     * @return <code>true</code> if the name is equal to the fromName, or if the name represents a superclass or superinterface of the fromName,
     *         <code>false</code> otherwise
     */
private boolean isAssignableTo(DotName name, Class<?> to) {
    if (to.getName().equals(name.toString())) {
        return true;
    }
    if (OBJECT_NAME.equals(name)) {
        // there's nothing assignable from Object.class except for Object.class
        return false;
    }
    ClassInfo fromClassInfo = index.getClassByName(name);
    if (fromClassInfo == null) {
        // We reached a class that is not in the index. Let's use reflection.
        final Class<?> clazz = loadClass(name.toString());
        return to.isAssignableFrom(clazz);
    }
    DotName superName = fromClassInfo.superName();
    if (superName != null && isAssignableTo(superName, to)) {
        return true;
    }
    if (fromClassInfo.interfaces() != null) {
        for (DotName interfaceName : fromClassInfo.interfaces()) {
            if (isAssignableTo(interfaceName, to)) {
                return true;
            }
        }
    }
    return false;
}
Also used : DotName(org.jboss.jandex.DotName) ClassInfo(org.jboss.jandex.ClassInfo)

Aggregations

DotName (org.jboss.jandex.DotName)15 ClassInfo (org.jboss.jandex.ClassInfo)10 AnnotationInstance (org.jboss.jandex.AnnotationInstance)7 HashSet (java.util.HashSet)6 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)6 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)5 HashMap (java.util.HashMap)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)3 Set (java.util.Set)2 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)2 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)2 AnnotationTarget (org.jboss.jandex.AnnotationTarget)2 AnnotationValue (org.jboss.jandex.AnnotationValue)2 Module (org.jboss.modules.Module)2 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ServletContainerInitializer (javax.servlet.ServletContainerInitializer)1 HandlesTypes (javax.servlet.annotation.HandlesTypes)1 FieldInjectionTarget (org.jboss.as.ee.component.FieldInjectionTarget)1