Search in sources :

Example 1 with WebAppBeanArchiveScanner

use of org.jboss.weld.environment.servlet.deployment.WebAppBeanArchiveScanner in project core by weld.

the class WeldServletLifecycle method createDeployment.

/**
 * Create servlet deployment.
 *
 * Can be overridden with custom servlet deployment. e.g. exact resources listing in restricted env like GAE
 *
 * @param context the servlet context
 * @param bootstrap the bootstrap
 * @return new servlet deployment
 */
protected CDI11Deployment createDeployment(ServletContext context, CDI11Bootstrap bootstrap) {
    ImmutableSet.Builder<Metadata<Extension>> extensionsBuilder = ImmutableSet.builder();
    extensionsBuilder.addAll(bootstrap.loadExtensions(WeldResourceLoader.getClassLoader()));
    if (isDevModeEnabled) {
        extensionsBuilder.add(new MetadataImpl<Extension>(DevelopmentMode.getProbeExtension(resourceLoader), "N/A"));
    }
    final Iterable<Metadata<Extension>> extensions = extensionsBuilder.build();
    final TypeDiscoveryConfiguration typeDiscoveryConfiguration = bootstrap.startExtensions(extensions);
    final EEModuleDescriptor eeModule = new EEModuleDescriptorImpl(context.getContextPath(), ModuleType.WEB);
    final DiscoveryStrategy strategy = DiscoveryStrategyFactory.create(resourceLoader, bootstrap, typeDiscoveryConfiguration.getKnownBeanDefiningAnnotations(), Boolean.parseBoolean(context.getInitParameter(Jandex.DISABLE_JANDEX_DISCOVERY_STRATEGY)));
    if (Jandex.isJandexAvailable(resourceLoader)) {
        try {
            Class<? extends BeanArchiveHandler> handlerClass = Reflections.loadClass(resourceLoader, JANDEX_SERVLET_CONTEXT_BEAN_ARCHIVE_HANDLER);
            strategy.registerHandler((SecurityActions.newConstructorInstance(handlerClass, new Class<?>[] { ServletContext.class }, context)));
        } catch (Exception e) {
            throw CommonLogger.LOG.unableToInstantiate(JANDEX_SERVLET_CONTEXT_BEAN_ARCHIVE_HANDLER, Arrays.toString(new Object[] { context }), e);
        }
    } else {
        strategy.registerHandler(new ServletContextBeanArchiveHandler(context));
    }
    strategy.setScanner(new WebAppBeanArchiveScanner(resourceLoader, bootstrap, context));
    Set<WeldBeanDeploymentArchive> beanDeploymentArchives = strategy.performDiscovery();
    String isolation = context.getInitParameter(CONTEXT_PARAM_ARCHIVE_ISOLATION);
    if (isolation == null || Boolean.valueOf(isolation)) {
        CommonLogger.LOG.archiveIsolationEnabled();
    } else {
        CommonLogger.LOG.archiveIsolationDisabled();
        Set<WeldBeanDeploymentArchive> flatDeployment = new HashSet<WeldBeanDeploymentArchive>();
        flatDeployment.add(WeldBeanDeploymentArchive.merge(bootstrap, beanDeploymentArchives));
        beanDeploymentArchives = flatDeployment;
    }
    for (BeanDeploymentArchive archive : beanDeploymentArchives) {
        archive.getServices().add(EEModuleDescriptor.class, eeModule);
    }
    CDI11Deployment deployment = new WeldDeployment(resourceLoader, bootstrap, beanDeploymentArchives, extensions) {

        @Override
        protected WeldBeanDeploymentArchive createAdditionalBeanDeploymentArchive() {
            WeldBeanDeploymentArchive archive = super.createAdditionalBeanDeploymentArchive();
            archive.getServices().add(EEModuleDescriptor.class, eeModule);
            return archive;
        }
    };
    if (strategy.getClassFileServices() != null) {
        deployment.getServices().add(ClassFileServices.class, strategy.getClassFileServices());
    }
    return deployment;
}
Also used : WeldBeanDeploymentArchive(org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive) Metadata(org.jboss.weld.bootstrap.spi.Metadata) CDI11Deployment(org.jboss.weld.bootstrap.spi.CDI11Deployment) EEModuleDescriptorImpl(org.jboss.weld.bootstrap.spi.helpers.EEModuleDescriptorImpl) WeldDeployment(org.jboss.weld.environment.deployment.WeldDeployment) DiscoveryStrategy(org.jboss.weld.environment.deployment.discovery.DiscoveryStrategy) Extension(javax.enterprise.inject.spi.Extension) ServletContextBeanArchiveHandler(org.jboss.weld.environment.servlet.deployment.ServletContextBeanArchiveHandler) TypeDiscoveryConfiguration(org.jboss.weld.bootstrap.api.TypeDiscoveryConfiguration) ImmutableSet(org.jboss.weld.util.collections.ImmutableSet) WebAppBeanArchiveScanner(org.jboss.weld.environment.servlet.deployment.WebAppBeanArchiveScanner) WeldBeanDeploymentArchive(org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) EEModuleDescriptor(org.jboss.weld.bootstrap.spi.EEModuleDescriptor) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 Extension (javax.enterprise.inject.spi.Extension)1 TypeDiscoveryConfiguration (org.jboss.weld.bootstrap.api.TypeDiscoveryConfiguration)1 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)1 CDI11Deployment (org.jboss.weld.bootstrap.spi.CDI11Deployment)1 EEModuleDescriptor (org.jboss.weld.bootstrap.spi.EEModuleDescriptor)1 Metadata (org.jboss.weld.bootstrap.spi.Metadata)1 EEModuleDescriptorImpl (org.jboss.weld.bootstrap.spi.helpers.EEModuleDescriptorImpl)1 WeldBeanDeploymentArchive (org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive)1 WeldDeployment (org.jboss.weld.environment.deployment.WeldDeployment)1 DiscoveryStrategy (org.jboss.weld.environment.deployment.discovery.DiscoveryStrategy)1 ServletContextBeanArchiveHandler (org.jboss.weld.environment.servlet.deployment.ServletContextBeanArchiveHandler)1 WebAppBeanArchiveScanner (org.jboss.weld.environment.servlet.deployment.WebAppBeanArchiveScanner)1 ImmutableSet (org.jboss.weld.util.collections.ImmutableSet)1