Search in sources :

Example 36 with CompositeIndex

use of org.jboss.as.server.deployment.annotation.CompositeIndex in project wildfly by wildfly.

the class AroundInvokeAnnotationParsingProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
    final List<AnnotationInstance> aroundInvokes = index.getAnnotations(AROUND_INVOKE_ANNOTATION_NAME);
    for (AnnotationInstance annotation : aroundInvokes) {
        processAroundInvoke(eeModuleDescription, annotation.target());
    }
}
Also used : EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance)

Example 37 with CompositeIndex

use of org.jboss.as.server.deployment.annotation.CompositeIndex in project wildfly by wildfly.

the class JaxrsScanningProcessor method scan.

protected void scan(final DeploymentUnit du, final ClassLoader classLoader, final ResteasyDeploymentData resteasyDeploymentData) throws DeploymentUnitProcessingException, ModuleLoadException {
    final CompositeIndex index = du.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (!resteasyDeploymentData.shouldScan()) {
        return;
    }
    if (!resteasyDeploymentData.isDispatcherCreated()) {
        final Set<ClassInfo> applicationClasses = index.getAllKnownSubclasses(APPLICATION);
        try {
            for (ClassInfo c : applicationClasses) {
                if (Modifier.isAbstract(c.flags()))
                    continue;
                @SuppressWarnings("unchecked") Class<? extends Application> scanned = (Class<? extends Application>) classLoader.loadClass(c.name().toString());
                resteasyDeploymentData.getScannedApplicationClasses().add(scanned);
            }
        } catch (ClassNotFoundException e) {
            throw JaxrsLogger.JAXRS_LOGGER.cannotLoadApplicationClass(e);
        }
    }
    List<AnnotationInstance> resources = null;
    List<AnnotationInstance> providers = null;
    if (resteasyDeploymentData.isScanResources()) {
        resources = index.getAnnotations(JaxrsAnnotations.PATH.getDotName());
    }
    if (resteasyDeploymentData.isScanProviders()) {
        providers = index.getAnnotations(JaxrsAnnotations.PROVIDER.getDotName());
    }
    if ((resources == null || resources.isEmpty()) && (providers == null || providers.isEmpty()))
        return;
    final Set<ClassInfo> pathInterfaces = new HashSet<ClassInfo>();
    if (resources != null) {
        for (AnnotationInstance e : resources) {
            final ClassInfo info;
            if (e.target() instanceof ClassInfo) {
                info = (ClassInfo) e.target();
            } else if (e.target() instanceof MethodInfo) {
                //ignore
                continue;
            } else {
                JAXRS_LOGGER.classOrMethodAnnotationNotFound("@Path", e.target());
                continue;
            }
            if (info.annotations().containsKey(DECORATOR)) {
                //we can't pick up on programatically added decorators, but that is such an edge case it should not really matter
                continue;
            }
            if (!Modifier.isInterface(info.flags())) {
                resteasyDeploymentData.getScannedResourceClasses().add(info.name().toString());
            } else {
                pathInterfaces.add(info);
            }
        }
    }
    if (providers != null) {
        for (AnnotationInstance e : providers) {
            if (e.target() instanceof ClassInfo) {
                ClassInfo info = (ClassInfo) e.target();
                if (info.annotations().containsKey(DECORATOR)) {
                    //we can't pick up on programatically added decorators, but that is such an edge case it should not really matter
                    continue;
                }
                if (!Modifier.isInterface(info.flags())) {
                    resteasyDeploymentData.getScannedProviderClasses().add(info.name().toString());
                }
            } else {
                JAXRS_LOGGER.classAnnotationNotFound("@Provider", e.target());
            }
        }
    }
    // look for all implementations of interfaces annotated @Path
    for (final ClassInfo iface : pathInterfaces) {
        final Set<ClassInfo> implementors = index.getAllKnownImplementors(iface.name());
        for (final ClassInfo implementor : implementors) {
            if (implementor.annotations().containsKey(DECORATOR)) {
                //we can't pick up on programatically added decorators, but that is such an edge case it should not really matter
                continue;
            }
            resteasyDeploymentData.getScannedResourceClasses().add(implementor.name().toString());
        }
    }
}
Also used : CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) MethodInfo(org.jboss.jandex.MethodInfo) Application(javax.ws.rs.core.Application) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo) HashSet(java.util.HashSet)

Example 38 with CompositeIndex

use of org.jboss.as.server.deployment.annotation.CompositeIndex in project wildfly by wildfly.

the class PassivationAnnotationParsingProcessor method deploy.

public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
    for (DotName annotationName : PASSIVATION_ANNOTATIONS) {
        final List<AnnotationInstance> lifecycles = index.getAnnotations(annotationName);
        for (AnnotationInstance annotation : lifecycles) {
            processPassivation(eeModuleDescription, annotation.target(), annotationName, applicationClasses);
        }
    }
}
Also used : EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DotName(org.jboss.jandex.DotName) AnnotationInstance(org.jboss.jandex.AnnotationInstance)

Aggregations

CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)38 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)29 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)17 AnnotationInstance (org.jboss.jandex.AnnotationInstance)17 ClassInfo (org.jboss.jandex.ClassInfo)12 HashSet (java.util.HashSet)6 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)6 AnnotationTarget (org.jboss.jandex.AnnotationTarget)6 DotName (org.jboss.jandex.DotName)6 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)5 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)5 PropertyReplacer (org.jboss.metadata.property.PropertyReplacer)5 Module (org.jboss.modules.Module)5 HashMap (java.util.HashMap)4 WarMetaData (org.jboss.as.web.common.WarMetaData)4 AnnotationValue (org.jboss.jandex.AnnotationValue)4 ModuleDependency (org.jboss.as.server.deployment.module.ModuleDependency)3 MethodInfo (org.jboss.jandex.MethodInfo)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2