Search in sources :

Example 26 with Index

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

the class WeldImplicitDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
        return;
    }
    if (Utils.getRootDeploymentUnit(deploymentUnit).getAttachment(WeldConfiguration.ATTACHMENT_KEY).isRequireBeanDescriptor()) {
        // if running in the require-bean-descriptor mode then bean archives are found by BeansXmlProcessor
        return;
    }
    /*
         * look for classes with bean defining annotations
         */
    final Set<AnnotationType> beanDefiningAnnotations = new HashSet<>(getRootDeploymentUnit(deploymentUnit).getAttachment(WeldAttachments.BEAN_DEFINING_ANNOTATIONS));
    final Map<ResourceRoot, Index> indexes = AnnotationIndexUtils.getAnnotationIndexes(deploymentUnit);
    final ExplicitBeanArchiveMetadataContainer explicitBeanArchiveMetadata = deploymentUnit.getAttachment(ExplicitBeanArchiveMetadataContainer.ATTACHMENT_KEY);
    final ResourceRoot classesRoot = deploymentUnit.getAttachment(WeldAttachments.CLASSES_RESOURCE_ROOT);
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    for (Entry<ResourceRoot, Index> entry : indexes.entrySet()) {
        ResourceRoot resourceRoot = entry.getKey();
        if (resourceRoot == classesRoot) {
            // BDA for WEB-INF/classes is keyed under deploymentRoot in explicitBeanArchiveMetadata
            resourceRoot = deploymentRoot;
        }
        /*
             * Make sure bean defining annotations used in archives with bean-discovery-mode="none" are not considered here
             * WFLY-4388
             */
        if (explicitBeanArchiveMetadata != null && explicitBeanArchiveMetadata.getBeanArchiveMetadata().containsKey(resourceRoot)) {
            continue;
        }
        for (final AnnotationType annotation : beanDefiningAnnotations) {
            if (!entry.getValue().getAnnotations(annotation.getName()).isEmpty()) {
                WeldDeploymentMarker.mark(deploymentUnit);
                return;
            }
        }
    }
    /*
         * look for session beans and managed beans
         */
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final Iterable<ImplicitBeanArchiveDetector> detectors = ServiceLoader.load(ImplicitBeanArchiveDetector.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldImplicitDeploymentProcessor.class));
    for (ComponentDescription component : eeModuleDescription.getComponentDescriptions()) {
        for (ImplicitBeanArchiveDetector detector : detectors) {
            if (detector.isImplicitBeanArchiveRequired(component)) {
                WeldDeploymentMarker.mark(deploymentUnit);
                return;
            }
        }
    }
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) Index(org.jboss.jandex.Index) AnnotationType(org.jboss.as.weld.discovery.AnnotationType) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ImplicitBeanArchiveDetector(org.jboss.as.weld.spi.ImplicitBeanArchiveDetector) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Utils.getRootDeploymentUnit(org.jboss.as.weld.util.Utils.getRootDeploymentUnit) ExplicitBeanArchiveMetadataContainer(org.jboss.as.weld.deployment.ExplicitBeanArchiveMetadataContainer) HashSet(java.util.HashSet)

Example 27 with Index

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

the class BeanArchiveProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
        return;
    }
    WeldLogger.DEPLOYMENT_LOGGER.processingWeldDeployment(deploymentUnit.getName());
    final Map<ResourceRoot, Index> indexes = AnnotationIndexUtils.getAnnotationIndexes(deploymentUnit);
    final Map<ResourceRoot, BeanDeploymentArchiveImpl> bdaMap = new HashMap<ResourceRoot, BeanDeploymentArchiveImpl>();
    final Components components = new Components(deploymentUnit, indexes);
    final ResourceRootHandler handler = new ResourceRootHandler(deploymentUnit, components, indexes);
    for (ResourceRoot resourceRoot : deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS)) {
        if (ModuleRootMarker.isModuleRoot(resourceRoot) && !SubDeploymentMarker.isSubDeployment(resourceRoot)) {
            if (isClassesRoot(resourceRoot)) {
                // this is handled below
                continue;
            }
            handler.handleResourceRoot(bdaMap, resourceRoot);
        }
    }
    if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
        handler.handleResourceRoot(bdaMap, handler.deploymentResourceRoot);
    }
    if (!bdaMap.containsKey(handler.deploymentResourceRoot)) {
        // there is not root bda, let's create one
        BeanDeploymentArchiveImpl bda = new BeanDeploymentArchiveImpl(Collections.<String>emptySet(), Collections.<String>emptySet(), BeansXml.EMPTY_BEANS_XML, handler.module, getDeploymentUnitId(deploymentUnit), BeanArchiveType.SYNTHETIC, true);
        WeldLogger.DEPLOYMENT_LOGGER.beanArchiveDiscovered(bda);
        bdaMap.put(handler.deploymentResourceRoot, bda);
    }
    deploymentUnit.putAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE, bdaMap.get(handler.deploymentResourceRoot));
    /*
         * Finish EE component processing
         */
    for (Entry<ResourceRoot, Collection<ComponentDescription>> entry : components.componentDescriptions.entrySet()) {
        BeanDeploymentArchiveImpl bda = bdaMap.get(entry.getKey());
        String id = null;
        if (bda != null) {
            id = bda.getId();
        } else {
            id = deploymentUnit.getAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE).getId();
        }
        for (ComponentDescription componentDescription : entry.getValue()) {
            componentDescription.setBeanDeploymentArchiveId(id);
        }
    }
    final BeanDeploymentModule bdm = new BeanDeploymentModule(handler.module.getIdentifier().toString(), deploymentUnit, bdaMap.values());
    deploymentUnit.putAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE, bdm);
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) BeanDeploymentArchiveImpl(org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl) HashMap(java.util.HashMap) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) Index(org.jboss.jandex.Index) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) Collection(java.util.Collection) BeanDeploymentModule(org.jboss.as.weld.deployment.BeanDeploymentModule) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Utils.getRootDeploymentUnit(org.jboss.as.weld.util.Utils.getRootDeploymentUnit)

Example 28 with Index

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

the class IndexUtils method createIndex.

static CompositeIndex createIndex(Object... resources) throws IOException {
    final ClassLoader classLoader = IndexUtils.class.getClassLoader();
    final Indexer indexer = new Indexer();
    for (Object resource : resources) {
        addResource(resource, indexer, classLoader);
    }
    final Index index = indexer.complete();
    return new CompositeIndex(Collections.singleton(index));
}
Also used : Indexer(org.jboss.jandex.Indexer) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) Index(org.jboss.jandex.Index)

Example 29 with Index

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

the class WarAnnotationDeploymentProcessor method deploy.

/**
 * Process web annotations.
 */
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        // Skip non web deployments
        return;
    }
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    assert warMetaData != null;
    Map<String, WebMetaData> annotationsMetaData = warMetaData.getAnnotationsMetaData();
    if (annotationsMetaData == null) {
        annotationsMetaData = new HashMap<String, WebMetaData>();
        warMetaData.setAnnotationsMetaData(annotationsMetaData);
    }
    Map<ResourceRoot, Index> indexes = AnnotationIndexUtils.getAnnotationIndexes(deploymentUnit);
    // Process lib/*.jar
    for (final Entry<ResourceRoot, Index> entry : indexes.entrySet()) {
        final Index jarIndex = entry.getValue();
        annotationsMetaData.put(entry.getKey().getRootName(), processAnnotations(jarIndex));
    }
    Map<ModuleIdentifier, CompositeIndex> additionalModelAnnotations = deploymentUnit.getAttachment(Attachments.ADDITIONAL_ANNOTATION_INDEXES_BY_MODULE);
    if (additionalModelAnnotations != null) {
        final List<WebMetaData> additional = new ArrayList<WebMetaData>();
        for (Entry<ModuleIdentifier, CompositeIndex> entry : additionalModelAnnotations.entrySet()) {
            for (Index index : entry.getValue().getIndexes()) {
                additional.add(processAnnotations(index));
            }
        }
        warMetaData.setAdditionalModuleAnnotationsMetadata(additional);
    }
}
Also used : WarMetaData(org.jboss.as.web.common.WarMetaData) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) ArrayList(java.util.ArrayList) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) Index(org.jboss.jandex.Index) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) WebMetaData(org.jboss.metadata.web.spec.WebMetaData)

Example 30 with Index

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

the class ParsedRaDeploymentProcessor method process.

public static ServiceBuilder<ResourceAdapterDeployment> process(final ConnectorXmlDescriptor connectorXmlDescriptor, final IronJacamarXmlDescriptor ironJacamarXmlDescriptor, final ClassLoader classLoader, final ServiceTarget serviceTarget, final Map<ResourceRoot, Index> annotationIndexes, final ServiceName duServiceName, final ManagementResourceRegistration registration, Resource deploymentResource) throws DeploymentUnitProcessingException {
    Connector cmd = connectorXmlDescriptor != null ? connectorXmlDescriptor.getConnector() : null;
    final Activation activation = ironJacamarXmlDescriptor != null ? ironJacamarXmlDescriptor.getIronJacamar() : null;
    try {
        // Annotation merging
        Annotations annotator = new Annotations();
        if (annotationIndexes != null && annotationIndexes.size() > 0) {
            DEPLOYMENT_CONNECTOR_LOGGER.debugf("ParsedRaDeploymentProcessor: Found %d annotationIndexes", annotationIndexes.size());
            for (Index index : annotationIndexes.values()) {
                // Don't apply any empty indexes, as IronJacamar doesn't like that atm.
                if (index.getKnownClasses() != null && index.getKnownClasses().size() > 0) {
                    AnnotationRepository repository = new JandexAnnotationRepositoryImpl(index, classLoader);
                    cmd = annotator.merge(cmd, repository, classLoader);
                    DEPLOYMENT_CONNECTOR_LOGGER.debugf("ParsedRaDeploymentProcessor: CMD=%s", cmd);
                }
            }
        }
        if (annotationIndexes == null || annotationIndexes.size() == 0)
            DEPLOYMENT_CONNECTOR_LOGGER.debugf("ParsedRaDeploymentProcessor: Found 0 annotationIndexes");
        // FIXME: when the connector is null the Iron Jacamar data is ignored
        if (cmd != null) {
            // Validate metadata
            cmd.validate();
            // Merge metadata
            cmd = (new Merger()).mergeConnectorWithCommonIronJacamar(activation, cmd);
        }
        TransactionSupportEnum transactionSupport = TransactionSupportEnum.NoTransaction;
        if (cmd != null && cmd.getResourceadapter() != null && cmd.getResourceadapter().getOutboundResourceadapter() != null) {
            transactionSupport = cmd.getResourceadapter().getOutboundResourceadapter().getTransactionSupport();
        }
        if (activation != null && activation.getTransactionSupport() != null) {
            transactionSupport = activation.getTransactionSupport();
        }
        final ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(connectorXmlDescriptor.getDeploymentName());
        final ResourceAdapterDeploymentService raDeploymentService = new ResourceAdapterDeploymentService(connectorXmlDescriptor, cmd, activation, classLoader, deployerServiceName, duServiceName, registration, deploymentResource);
        // Create the service
        ServiceBuilder<ResourceAdapterDeployment> builder = Services.addServerExecutorDependency(serviceTarget.addService(deployerServiceName, raDeploymentService), raDeploymentService.getExecutorServiceInjector(), false).addDependency(ConnectorServices.IRONJACAMAR_MDR, AS7MetadataRepository.class, raDeploymentService.getMdrInjector()).addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, raDeploymentService.getRaRepositoryInjector()).addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, raDeploymentService.getManagementRepositoryInjector()).addDependency(ConnectorServices.RESOURCE_ADAPTER_REGISTRY_SERVICE, ResourceAdapterDeploymentRegistry.class, raDeploymentService.getRegistryInjector()).addDependency(ConnectorServices.TRANSACTION_INTEGRATION_SERVICE, TransactionIntegration.class, raDeploymentService.getTxIntegrationInjector()).addDependency(ConnectorServices.CONNECTOR_CONFIG_SERVICE, JcaSubsystemConfiguration.class, raDeploymentService.getConfigInjector()).addDependency(ConnectorServices.IDLE_REMOVER_SERVICE).addDependency(ConnectorServices.CONNECTION_VALIDATOR_SERVICE).addDependency(NamingService.SERVICE_NAME);
        if (transactionSupport == null || transactionSupport.equals(TransactionSupportEnum.NoTransaction)) {
            builder.addDependency(ConnectorServices.NON_TX_CCM_SERVICE, CachedConnectionManager.class, raDeploymentService.getCcmInjector());
        } else {
            builder.addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, raDeploymentService.getCcmInjector());
        }
        if (activation != null && ActivationSecurityUtil.isLegacySecurityRequired(activation)) {
            builder.addDependency(SubjectFactoryService.SERVICE_NAME, SubjectFactory.class, raDeploymentService.getSubjectFactoryInjector()).addDependency(SimpleSecurityManagerService.SERVICE_NAME, ServerSecurityManager.class, raDeploymentService.getServerSecurityManager());
        }
        return builder;
    } catch (Throwable t) {
        throw new DeploymentUnitProcessingException(t);
    }
}
Also used : JandexAnnotationRepositoryImpl(org.jboss.as.connector.annotations.repository.jandex.JandexAnnotationRepositoryImpl) ResourceAdapterDeployment(org.jboss.as.connector.metadata.deployment.ResourceAdapterDeployment) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) Connector(org.jboss.jca.common.api.metadata.spec.Connector) SubjectFactory(org.jboss.security.SubjectFactory) JcaSubsystemConfiguration(org.jboss.as.connector.subsystems.jca.JcaSubsystemConfiguration) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) Index(org.jboss.jandex.Index) ResourceAdapterDeploymentService(org.jboss.as.connector.services.resourceadapters.deployment.ResourceAdapterDeploymentService) Annotations(org.jboss.jca.common.annotations.Annotations) Merger(org.jboss.jca.common.metadata.merge.Merger) ServiceName(org.jboss.msc.service.ServiceName) AnnotationRepository(org.jboss.jca.common.spi.annotations.repository.AnnotationRepository) ResourceAdapterRepository(org.jboss.jca.core.spi.rar.ResourceAdapterRepository) TransactionSupportEnum(org.jboss.jca.common.api.metadata.common.TransactionSupportEnum) ResourceAdapterDeploymentRegistry(org.jboss.as.connector.services.resourceadapters.deployment.registry.ResourceAdapterDeploymentRegistry)

Aggregations

Index (org.jboss.jandex.Index)50 Indexer (org.jboss.jandex.Indexer)24 InputStream (java.io.InputStream)21 Test (org.junit.Test)18 File (java.io.File)16 URI (java.net.URI)15 AnnotationRepository (org.jboss.jca.common.spi.annotations.repository.AnnotationRepository)13 VirtualFile (org.jboss.vfs.VirtualFile)13 URL (java.net.URL)11 SuffixMatchFilter (org.jboss.vfs.util.SuffixMatchFilter)11 ClassInfo (org.jboss.jandex.ClassInfo)10 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)6 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 Map (java.util.Map)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 CompositeIndex (org.jboss.jandex.CompositeIndex)4