public synchronized void deploy()

in webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java [212:416]


    public synchronized void deploy(ScannerService scanner)
    {
        try
        {
            if (!deployed)
            {                
                //Load Extensions
                webBeansContext.getExtensionLoader().loadExtensionServices();

                // Bind manager
                JNDIService service = webBeansContext.getService(JNDIService.class);
                
                //Default jndi is just a map
                if(service instanceof DefaultJndiService)
                {
                    service.bind(WebBeansConstants.WEB_BEANS_MANAGER_JNDI_NAME, new InjectableBeanManager(webBeansContext.getBeanManagerImpl()));
                }
                //Assume, actual JNDI implementation
                else
                {
                    service.bind(WebBeansConstants.WEB_BEANS_MANAGER_JNDI_NAME, webBeansContext.getBeanManagerImpl().getReference());
                }

                // Register Manager built-in component
                webBeansContext.getBeanManagerImpl().addInternalBean(webBeansContext.getBeanManagerBean());
                // Register built-in RequestContextController
                webBeansContext.getBeanManagerImpl().addInternalBean(webBeansContext.getWebBeansUtil().getRequestContextControllerBean());
                webBeansContext.getInterceptorsManager().addCdiInterceptor(webBeansContext.getWebBeansUtil().getRequestContextInterceptorBean());
                webBeansContext.getInterceptorsManager().addPriorityClazzInterceptor(
                        ActivateRequestContextInterceptorBean.InterceptorClass.class,
                        jakarta.interceptor.Interceptor.Priority.PLATFORM_BEFORE + 100);

                //Fire Event
                fireBeforeBeanDiscoveryEvent();
                
                //Configure Default Beans
                configureDefaultBeans();

                Map<BeanArchiveInformation, List<AnnotatedType<?>>> annotatedTypesPerBda = annotatedTypesFromClassPath(scanner);

                List<AnnotatedType<?>> globalBdaAnnotatedTypes = annotatedTypesPerBda.get(defaultBeanArchiveInformation);

                // Deploy additional Annotated Types which got added via BeforeBeanDiscovery#addAnnotatedType
                final Collection<AnnotatedType<?>> additionalAnnotatedTypes =
                        webBeansContext.getBeanManagerImpl().getAdditionalAnnotatedTypes();
                addAdditionalAnnotatedTypes(additionalAnnotatedTypes, globalBdaAnnotatedTypes);

                for (List<AnnotatedType<?>> at : annotatedTypesPerBda.values())
                {
                    registerAlternativesDecoratorsAndInterceptorsWithPriority(at);
                }

                // Also configures deployments, interceptors, decorators.
                deployFromXML(scanner);

                addAdditionalAnnotatedTypes(fireAfterTypeDiscoveryEvent(), globalBdaAnnotatedTypes);


                Map<BeanArchiveInformation, Map<AnnotatedType<?>, ExtendedBeanAttributes<?>>> beanAttributesPerBda
                    = getBeanAttributes(annotatedTypesPerBda);

                // shouldn't be used anymore, view is now beanAttributes
                annotatedTypesPerBda.clear();

                SpecializationUtil specializationUtil = new SpecializationUtil(webBeansContext);
                specializationUtil.removeDisabledBeanAttributes(beanAttributesPerBda, null, true);


                //Checking stereotype conditions
                checkStereoTypes(beanAttributesPerBda);

                // Handle Specialization
                specializationUtil.removeDisabledBeanAttributes(
                        beanAttributesPerBda,
                        new SpecializationUtil.BeanAttributesProvider()
                        {
                            @Override
                            public <T> BeanAttributes get(AnnotatedType<T> at)
                            {
                                ExtendedBeanAttributes<?> data = null;
                                for (Map<AnnotatedType<?>, ExtendedBeanAttributes<?>> beanAttributes : beanAttributesPerBda.values())
                                {
                                    data = beanAttributes.get(at);
                                    if (data != null)
                                    {
                                        break;
                                    }

                                }
                                return data == null ? null : data.beanAttributes;
                            }
                        },
                        false);

                // create beans from the discovered AnnotatedTypes
                deployFromBeanAttributes(beanAttributesPerBda);

                configureProducerMethodSpecializations();

                // all beans which got 'overridden' by a Specialized version can be removed now
                removeDisabledBeans();
                
                // We are finally done with our bean discovery
                fireAfterBeanDiscoveryEvent();

                // activate InjectionResolver cache now
                webBeansContext.getBeanManagerImpl().getInjectionResolver().setStartup(false);

                if (!skipValidations)
                {
                    validateAlternatives(beanAttributesPerBda);

                    validateInjectionPoints();
                    validateDisposeParameters();

                    validateDecoratorDecoratedTypes();
                    validateDecoratorGenericTypes();

                    validateNames();
                }
                else
                {
                    webBeansContext.getBeanManagerImpl().getBeans().forEach(bean -> {
                        if (BuiltInOwbBean.class.isInstance(bean))
                        {
                            Class<?> proxyable = BuiltInOwbBean.class.cast(bean).proxyableType();
                            if (proxyable != null)
                            {
                                AbstractProducer producer = AbstractProducer.class.cast(OwbBean.class.cast(bean).getProducer());
                                AnnotatedType<?> annotatedType = webBeansContext.getAnnotatedElementFactory()
                                        .newAnnotatedType(proxyable);
                                producer.defineInterceptorStack(bean, annotatedType, webBeansContext);
                            }
                        }
                        else if (bean instanceof OwbBean &&
                                !(bean instanceof Interceptor) &&
                                !(bean instanceof Decorator))
                        {
                            AbstractProducer producer = null;
                            OwbBean<?> owbBean = (OwbBean<?>) bean;
                            if (ManagedBean.class.isInstance(bean)) // in this case don't use producer which can be wrapped
                            {
                                producer = ManagedBean.class.cast(bean).getOriginalInjectionTarget();
                            }
                            if (producer == null && owbBean.getProducer() instanceof AbstractProducer)
                            {
                                producer = (AbstractProducer) owbBean.getProducer();
                            }
                            if (producer != null)
                            {
                                AnnotatedType<?> annotatedType;
                                if (owbBean instanceof InjectionTargetBean)
                                {
                                    annotatedType = ((InjectionTargetBean<?>) owbBean).getAnnotatedType();
                                }
                                else
                                {
                                    annotatedType = webBeansContext.getAnnotatedElementFactory()
                                            .newAnnotatedType(owbBean.getReturnType());
                                }
                                producer.defineInterceptorStack(owbBean, annotatedType, webBeansContext);
                            }
                        }
                    });
                }

                if (webBeansContext.getNotificationManager().getObserverMethods().stream()
                        .anyMatch(ObserverMethod::isAsync))
                {
                    // enforce it to be loaded and ensuring it works before runtime
                    webBeansContext.getNotificationManager().getDefaultNotificationOptions()
                            .getExecutor().execute(() -> {});
                }

                // fire event
                fireAfterDeploymentValidationEvent();


                // do some cleanup after the deployment
                scanner.release();
                webBeansContext.getAnnotatedElementFactory().clear();
                webBeansContext.getNotificationManager().clearCaches();
                webBeansContext.getAnnotationManager().clearCaches();
            }
        }
        catch (UnsatisfiedResolutionException | UnproxyableResolutionException | AmbiguousResolutionException e)
        {
            throw new WebBeansDeploymentException(e);
        }
        // the tck expects a DeploymentException, but it really should be a DefinitionException, see i.e. https://issues.jboss.org/browse/CDITCK-346
        catch (IllegalArgumentException e)
        {
            throw new WebBeansConfigurationException(e);
        }
        catch (Exception e)
        {
            throw ExceptionUtil.throwAsRuntimeException(e);
        }
        finally
        {
            //if bootstrapping failed, it doesn't make sense to do it again
            //esp. because #addInternalBean might have been called already and would cause an exception in the next run
            deployed = true;
        }
    }