Search in sources :

Example 6 with WeldConfiguration

use of org.jboss.weld.config.WeldConfiguration in project core by weld.

the class ExternalConfigurationConfigTest method testBootstrapConfiguration.

@Test
public void testBootstrapConfiguration() {
    WeldConfiguration configuration = manager.getServices().get(WeldConfiguration.class);
    assertFalse(configuration.getBooleanProperty(ConfigurationKey.CONCURRENT_DEPLOYMENT));
    assertEquals(Integer.valueOf(200), configuration.getIntegerProperty(ConfigurationKey.PRELOADER_THREAD_POOL_SIZE));
    assertEquals("/home/weld", configuration.getStringProperty(ConfigurationKey.PROXY_DUMP));
}
Also used : WeldConfiguration(org.jboss.weld.config.WeldConfiguration) Test(org.junit.Test)

Example 7 with WeldConfiguration

use of org.jboss.weld.config.WeldConfiguration in project core by weld.

the class JsonObjects method createDeploymentJson.

/**
 * @param beanManager
 * @return the root resource representation
 */
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "We want to catch all exceptions, runtime included.")
static String createDeploymentJson(BeanManagerImpl beanManager, Probe probe) {
    Map<BeanDeploymentArchive, BeanManagerImpl> beanDeploymentArchivesMap = Container.instance(beanManager).beanDeploymentArchives();
    AnnotationApiAbstraction annotationApi = beanManager.getServices().get(AnnotationApiAbstraction.class);
    JsonObjectBuilder deploymentBuilder = Json.objectBuilder();
    // INIT TS
    deploymentBuilder.add(INIT_TS, probe.getInitTs());
    // CONTEXT ID
    deploymentBuilder.add(CONTEXT_ID, beanManager.getContextId());
    // WELD VERSION
    deploymentBuilder.add(VERSION, Formats.getSimpleVersion());
    // BEAN DEPLOYMENT ARCHIVES
    JsonArrayBuilder bdasBuilder = Json.arrayBuilder();
    List<BeanDeploymentArchive> bdas = new ArrayList<BeanDeploymentArchive>(beanDeploymentArchivesMap.keySet());
    Collections.sort(bdas, probe.getBdaComparator());
    for (BeanDeploymentArchive bda : bdas) {
        JsonObjectBuilder bdaBuilder = createSimpleBdaJson(bda.getId());
        // If beans.xml is not found it's likely an implicit bean archive
        BeansXml beansXml = bda.getBeansXml();
        bdaBuilder.add(BEAN_DISCOVERY_MODE, beansXml != null ? beansXml.getBeanDiscoveryMode().toString() : BeanDiscoveryMode.ANNOTATED.toString());
        // beans.xml
        if (beansXml != null) {
            JsonObjectBuilder beansXmlBuilder = Json.objectBuilder();
            if (beansXml.equals(BeansXml.EMPTY_BEANS_XML)) {
                beansXmlBuilder.add(MARKER, Boolean.TRUE);
            } else {
                beansXmlBuilder.add(Strings.URL, beansXml.getUrl() != null ? beansXml.getUrl().toString() : EMPTY);
                beansXmlBuilder.add(VERSION, beansXml.getVersion() != null ? beansXml.getVersion().toString() : EMPTY);
                beansXmlBuilder.add(TRIMMED, beansXml.isTrimmed());
                if (beansXml.getScanning() != null && (!beansXml.getScanning().getExcludes().isEmpty() || !beansXml.getScanning().getExcludes().isEmpty())) {
                    JsonArrayBuilder scanBuilder = Json.arrayBuilder();
                    createMetadataArrayJson(scanBuilder, beansXml.getScanning().getExcludes(), EXCLUDE);
                    createMetadataArrayJson(scanBuilder, beansXml.getScanning().getIncludes(), INCLUDE);
                    beansXmlBuilder.add(SCAN, scanBuilder);
                }
            }
            bdaBuilder.add(Strings.BEANS_XML, beansXmlBuilder);
        }
        // Enablement - interceptors, decorators, alternatives
        JsonObjectBuilder enablementBuilder = Json.objectBuilder(true);
        ModuleEnablement enablement = beanDeploymentArchivesMap.get(bda).getEnabled();
        JsonArrayBuilder interceptors = Json.arrayBuilder();
        for (Class<?> interceptor : Components.getSortedProbeComponetCandidates(enablement.getInterceptors())) {
            Bean<?> interceptorBean = findEnabledBean(interceptor, BeanKind.INTERCEPTOR, probe);
            if (interceptorBean != null) {
                JsonObjectBuilder builder = decorateProbeComponent(interceptor, createSimpleBeanJson(interceptorBean, probe));
                if (beansXml != null) {
                    for (Metadata<String> meta : beansXml.getEnabledInterceptors()) {
                        if (meta.getValue().equals(interceptorBean.getBeanClass().getName())) {
                            // Locally enabled
                            builder.add(BEANS_XML, true);
                        }
                    }
                }
                Object priority = interceptorBean.getBeanClass().getAnnotation(annotationApi.PRIORITY_ANNOTATION_CLASS);
                if (priority != null) {
                    builder.add(PRIORITY, annotationApi.getPriority(priority));
                }
                if (builder.has(PRIORITY) && builder.has(BEANS_XML)) {
                    builder.add(CONFLICTS, true);
                }
                interceptors.add(builder);
            }
        }
        enablementBuilder.add(INTERCEPTORS, interceptors);
        JsonArrayBuilder decorators = Json.arrayBuilder();
        for (Class<?> decorator : enablement.getDecorators()) {
            Bean<?> decoratorBean = findEnabledBean(decorator, BeanKind.DECORATOR, probe);
            if (decoratorBean != null) {
                JsonObjectBuilder builder = createSimpleBeanJson(decoratorBean, probe);
                if (beansXml != null) {
                    for (Metadata<String> meta : beansXml.getEnabledDecorators()) {
                        if (meta.getValue().equals(decoratorBean.getBeanClass().getName())) {
                            // Locally enabled
                            builder.add(BEANS_XML, true);
                        }
                    }
                }
                Object priority = decoratorBean.getBeanClass().getAnnotation(annotationApi.PRIORITY_ANNOTATION_CLASS);
                if (priority != null) {
                    builder.add(PRIORITY, annotationApi.getPriority(priority));
                }
                if (builder.has(PRIORITY) && builder.has(BEANS_XML)) {
                    builder.add(CONFLICTS, true);
                }
                decorators.add(builder);
            }
        }
        enablementBuilder.add(DECORATORS, decorators);
        JsonArrayBuilder alternatives = Json.arrayBuilder();
        for (Class<?> clazz : Sets.union(enablement.getAlternativeClasses(), enablement.getGlobalAlternatives())) {
            Bean<?> alternativeBean = findAlternativeBean(clazz, probe);
            if (alternativeBean != null) {
                JsonObjectBuilder builder = createSimpleBeanJson(alternativeBean, probe);
                if (enablement.getAlternativeClasses().contains(clazz)) {
                    builder.add(BEANS_XML, true);
                }
                if (enablement.getGlobalAlternatives().contains(clazz)) {
                    Object priority = clazz.getAnnotation(annotationApi.PRIORITY_ANNOTATION_CLASS);
                    if (priority != null) {
                        builder.add(PRIORITY, annotationApi.getPriority(priority));
                    }
                }
                alternatives.add(builder);
            }
        }
        for (Class<? extends Annotation> stereotype : enablement.getAlternativeStereotypes()) {
            Set<Bean<?>> beans = findAlternativeStereotypeBeans(stereotype, probe);
            if (!beans.isEmpty()) {
                for (Bean<?> bean : beans) {
                    JsonObjectBuilder builder = createSimpleBeanJson(bean, probe);
                    builder.add(BEANS_XML, true);
                    alternatives.add(builder);
                }
            }
        }
        enablementBuilder.add(ALTERNATIVES, alternatives);
        bdaBuilder.add(ENABLEMENT, enablementBuilder);
        // Accessible BDAs
        BeanManagerImpl manager = beanDeploymentArchivesMap.get(bda);
        JsonArrayBuilder accesibleBdasBuilder = Json.arrayBuilder();
        for (BeanManagerImpl accesible : manager.getAccessibleManagers()) {
            accesibleBdasBuilder.add(Components.getId(accesible.getId()));
        }
        bdaBuilder.add(ACCESSIBLE_BDAS, accesibleBdasBuilder);
        bdaBuilder.add(BEANS, Components.getNumberOfEnabledBeans(manager));
        bdasBuilder.add(bdaBuilder);
    }
    deploymentBuilder.add(BDAS, bdasBuilder);
    // CONFIGURATION
    JsonArrayBuilder configBuilder = Json.arrayBuilder();
    WeldConfiguration configuration = beanManager.getServices().get(WeldConfiguration.class);
    for (ConfigurationKey key : Reports.getSortedConfigurationKeys()) {
        Object defaultValue = key.getDefaultValue();
        String desc = Reports.getDesc(key);
        if (desc == null) {
            // Don't show config options without description
            continue;
        }
        Object value = Reports.getValue(key, configuration);
        if (value == null) {
            // Unsupported property type
            continue;
        }
        configBuilder.add(Json.objectBuilder().add(NAME, key.get()).add(DEFAULT_VALUE, defaultValue.toString()).add(VALUE, value.toString()).add(DESCRIPTION, desc));
    }
    deploymentBuilder.add(CONFIGURATION, configBuilder);
    // INSPECTABLE CONTEXTS
    deploymentBuilder.add(CONTEXTS, createContextsJson(beanManager, probe));
    // DASHBOARD DATA
    JsonObjectBuilder dashboardBuilder = Json.objectBuilder();
    // Application
    JsonObjectBuilder appBuilder = Json.objectBuilder();
    appBuilder.add(BEANS, probe.getApplicationBeansCount());
    appBuilder.add(OBSERVERS, probe.getApplicationObserversCount());
    dashboardBuilder.add(APPLICATION, appBuilder);
    // Bootstrap
    dashboardBuilder.add(BOOSTRAP_STATS, createBootstrapStatsJson(probe));
    deploymentBuilder.add(DASHBOARD, dashboardBuilder);
    return deploymentBuilder.build();
}
Also used : AnnotationApiAbstraction(org.jboss.weld.util.AnnotationApiAbstraction) ModuleEnablement(org.jboss.weld.bootstrap.enablement.ModuleEnablement) ArrayList(java.util.ArrayList) SessionBean(org.jboss.weld.bean.SessionBean) AbstractClassBean(org.jboss.weld.bean.AbstractClassBean) AbstractBuiltInBean(org.jboss.weld.bean.builtin.AbstractBuiltInBean) AbstractProducerBean(org.jboss.weld.bean.AbstractProducerBean) Bean(javax.enterprise.inject.spi.Bean) ConfigurationKey(org.jboss.weld.config.ConfigurationKey) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) ProxyObject(org.jboss.weld.bean.proxy.ProxyObject) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder) WeldConfiguration(org.jboss.weld.config.WeldConfiguration) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 8 with WeldConfiguration

use of org.jboss.weld.config.WeldConfiguration in project core by weld.

the class ProbeExtension method beforeBeanDiscovery.

public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event, BeanManager beanManager) {
    ProbeLogger.LOG.developmentModeEnabled();
    BeanManagerImpl manager = BeanManagerProxy.unwrap(beanManager);
    manager.addValidationFailureCallback((exception, environment) -> {
        // Note that eventual problems are ignored during callback invocation
        probe.init(manager);
        Reports.generateValidationReport(probe, exception, environment, manager);
    });
    event.addAnnotatedType(VetoedSuppressedAnnotatedType.from(Monitored.class, beanManager), Monitored.class.getName());
    event.addAnnotatedType(VetoedSuppressedAnnotatedType.from(MonitoredComponent.class, beanManager), MonitoredComponent.class.getName());
    event.addAnnotatedType(VetoedSuppressedAnnotatedType.from(InvocationMonitor.class, beanManager), InvocationMonitor.class.getName());
    WeldConfiguration configuration = manager.getServices().get(WeldConfiguration.class);
    String exclude = configuration.getStringProperty(ConfigurationKey.PROBE_INVOCATION_MONITOR_EXCLUDE_TYPE);
    this.invocationMonitorExcludePattern = exclude.isEmpty() ? null : Pattern.compile(exclude);
    this.jsonDataProvider = new DefaultJsonDataProvider(probe, manager);
    this.eventMonitorContainerLifecycleEvents = configuration.getBooleanProperty(ConfigurationKey.PROBE_EVENT_MONITOR_CONTAINER_LIFECYCLE_EVENTS);
    addContainerLifecycleEvent(event, null, beanManager);
}
Also used : BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) WeldConfiguration(org.jboss.weld.config.WeldConfiguration)

Example 9 with WeldConfiguration

use of org.jboss.weld.config.WeldConfiguration in project core by weld.

the class ProbeFilter method init.

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    if (beanManager == null) {
        beanManager = BeanManagerProxy.tryUnwrap(filterConfig.getServletContext().getAttribute(WELD_SERVLET_BEAN_MANAGER_KEY));
        if (beanManager == null) {
            throw ProbeLogger.LOG.probeFilterUnableToOperate(BeanManagerImpl.class);
        }
    }
    ProbeExtension probeExtension = beanManager.getExtension(ProbeExtension.class);
    if (probeExtension == null) {
        throw ProbeLogger.LOG.probeFilterUnableToOperate(ProbeExtension.class);
    }
    probe = probeExtension.getProbe();
    if (!probe.isInitialized()) {
        throw ProbeLogger.LOG.probeNotInitialized();
    }
    jsonDataProvider = probeExtension.getJsonDataProvider();
    WeldConfiguration configuration = beanManager.getServices().get(WeldConfiguration.class);
    if (configuration.getBooleanProperty(ConfigurationKey.PROBE_EMBED_INFO_SNIPPET)) {
        snippetBase = initSnippetBase(filterConfig.getServletContext());
    }
    String exclude = configuration.getStringProperty(ConfigurationKey.PROBE_INVOCATION_MONITOR_EXCLUDE_TYPE);
    skipMonitoring = !exclude.isEmpty() && Pattern.compile(exclude).matcher(ProbeFilter.class.getName()).matches();
    String allowRemoteAddress = configuration.getStringProperty(ConfigurationKey.PROBE_ALLOW_REMOTE_ADDRESS);
    allowRemoteAddressPattern = allowRemoteAddress.isEmpty() ? null : Pattern.compile(allowRemoteAddress);
}
Also used : WeldConfiguration(org.jboss.weld.config.WeldConfiguration)

Example 10 with WeldConfiguration

use of org.jboss.weld.config.WeldConfiguration in project core by weld.

the class BootstrapAndExternalConfigurationConfigTest method testBootstrapConfiguration.

@Test
public void testBootstrapConfiguration() {
    WeldConfiguration configuration = manager.getServices().get(WeldConfiguration.class);
    // weld.properties has the highest priority
    assertTrue(configuration.getBooleanProperty(ConfigurationKey.CONCURRENT_DEPLOYMENT));
    // ExternalConfiguration has higher priority than BootstrapConfiguration
    assertEquals(Integer.valueOf(200), configuration.getIntegerProperty(ConfigurationKey.PRELOADER_THREAD_POOL_SIZE));
    // Test that MyBootstrapConfiguration is in game
    assertTrue(configuration.getBooleanProperty(ConfigurationKey.NON_PORTABLE_MODE));
}
Also used : WeldConfiguration(org.jboss.weld.config.WeldConfiguration) Test(org.junit.Test)

Aggregations

WeldConfiguration (org.jboss.weld.config.WeldConfiguration)15 Test (org.junit.Test)8 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)3 SimpleServiceRegistry (org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry)2 ConfigurationKey (org.jboss.weld.config.ConfigurationKey)2 GlobalObserverNotifierService (org.jboss.weld.event.GlobalObserverNotifierService)2 ResourceInjectionFactory (org.jboss.weld.injection.ResourceInjectionFactory)2 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)2 MetaAnnotationStore (org.jboss.weld.metadata.cache.MetaAnnotationStore)2 ClassTransformer (org.jboss.weld.resources.ClassTransformer)2 BeanIdentifierIndex (org.jboss.weld.serialization.BeanIdentifierIndex)2 ContextualStoreImpl (org.jboss.weld.serialization.ContextualStoreImpl)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ArrayList (java.util.ArrayList)1 Bean (javax.enterprise.inject.spi.Bean)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 SlimAnnotatedTypeStoreImpl (org.jboss.weld.annotated.slim.SlimAnnotatedTypeStoreImpl)1 AbstractClassBean (org.jboss.weld.bean.AbstractClassBean)1 AbstractProducerBean (org.jboss.weld.bean.AbstractProducerBean)1 SessionBean (org.jboss.weld.bean.SessionBean)1