private void installBootstrapConfigurationService(WeldDeployment deployment, DeploymentUnit parentDeploymentUnit) { final boolean nonPortableMode = parentDeploymentUnit.getAttachment(WeldConfiguration.ATTACHMENT_KEY).isNonPortableMode(); final ExternalConfiguration configuration = new ExternalConfigurationBuilder() .add(ConfigurationKey.NON_PORTABLE_MODE.get(), nonPortableMode) .add(ConfigurationKey.ALLOW_OPTIMIZED_CLEANUP.get(), true) .build(); deployment.getServices().add(ExternalConfiguration.class, configuration); }
@SuppressWarnings("unchecked") private <T> T initSystemProperty(ConfigurationKey key, Class<T> requiredType) { checkRequiredType(key, requiredType); String property = getSystemProperty(key.get()); return (T) (property != null ? key.convertValue(property) : key.getDefaultValue()); }
/** * * @param key * @param requiredType * @throws IllegalStateException If the configuration property type does not match the required type */ static void checkRequiredType(ConfigurationKey key, Class<?> requiredType) { if (!key.isValidValueType(requiredType)) { throw ConfigurationLogger.LOG.configurationPropertyTypeMismatch(key.getDefaultValue().getClass(), requiredType, key.get()); } }
AnnotationApiAbstraction annotationApi = beanManager.getServices().get(AnnotationApiAbstraction.class); JsonObjectBuilder deploymentBuilder = Json.objectBuilder(); deploymentBuilder.add(CONTEXT_ID, beanManager.getContextId()); ModuleEnablement enablement = beanDeploymentArchivesMap.get(bda).getEnabled(); JsonArrayBuilder interceptors = Json.arrayBuilder(); for (Class<?> interceptor : Components.getSortedProbeComponetCandidates(enablement.getInterceptors())) { WeldConfiguration configuration = beanManager.getServices().get(WeldConfiguration.class); for (ConfigurationKey key : Reports.getSortedConfigurationKeys()) { Object defaultValue = key.getDefaultValue(); String desc = Reports.getDesc(key); if (desc == null) { Json.objectBuilder().add(NAME, key.get()).add(DEFAULT_VALUE, defaultValue.toString()).add(VALUE, value.toString()).add(DESCRIPTION, desc));
private static void addConfiguration(HtmlTag body, BeanManagerImpl manager) { body.add(HtmlTag.aname(CONFIG)); body.add(HtmlTag.h2(TITLE_CONFIG)); HtmlTag table = HtmlTag.stripedTable().appendTo(HtmlTag.div(CONFIG).appendTo(body)); HtmlTag.tr().add(HtmlTag.th(""), HtmlTag.th("Key"), HtmlTag.th("Default Value"), HtmlTag.th("Value"), HtmlTag.th("Description")).appendTo(table); int idx = 0; WeldConfiguration configuration = manager.getServices().get(WeldConfiguration.class); for (ConfigurationKey key : getSortedConfigurationKeys()) { Object defaultValue = key.getDefaultValue(); Object value = getValue(key, configuration); if (value == null) { // Unsupported property type continue; } if (!defaultValue.equals(value)) { String desc = getDesc(key); table.add(HtmlTag.tr().add(HtmlTag.td(++idx + "."), HtmlTag.td(key.get()), HtmlTag.td(defaultValue.toString()), HtmlTag.td(value.toString()), HtmlTag.td().add(desc != null ? SafeString.of(desc) : ""))); } } }
if (manager != null) { isBootstrapNeeded = false; String contextId = BeanManagerProxy.unwrap(manager).getContextId(); context.setInitParameter(org.jboss.weld.Container.CONTEXT_ID_KEY, contextId); } else { final CDI11Deployment deployment = createDeployment(context, bootstrap); deployment.getServices().add(ExternalConfiguration.class, new ExternalConfigurationBuilder().add(BEAN_IDENTIFIER_INDEX_OPTIMIZATION.get(), Boolean.FALSE.toString()).build()); try { for (BeanDeploymentArchive archive : deployment.getBeanDeploymentArchives()) { archive.getServices().add(ResourceInjectionServices.class, resourceInjectionServices);
/** * * @param services * @param deployment */ public WeldConfiguration(ServiceRegistry services, Deployment deployment) { Preconditions.checkArgumentNotNull(deployment, "deployment"); this.properties = init(services, deployment); this.proxyDumpFilePath = initProxyDumpFilePath(); this.proxyIgnoreFinalMethodsPattern = initProxyIgnoreFinalMethodsPattern(); StringJoiner logOutputBuilder = new StringJoiner(", ", "{", "}"); for (Entry<ConfigurationKey, Object> entry : properties.entrySet()) { logOutputBuilder.add(entry.getKey().get() + "=" + entry.getValue()); } ConfigurationLogger.LOG.configurationInitialized(logOutputBuilder.toString()); }
/** * Process the given key and value. First validate the value and check if there's no different value for the same key in the same source - invalid and * different values are treated as a deployment problem. * * @param properties * @param key * @param value */ private void processKeyValue(Map<ConfigurationKey, Object> properties, ConfigurationKey key, Object value) { if (value instanceof String) { value = key.convertValue((String) value); } if (key.isValidValue(value)) { Object previous = properties.put(key, value); if (previous != null && !previous.equals(value)) { throw ConfigurationLogger.LOG.configurationKeyHasDifferentValues(key.get(), previous, value); } } else { throw ConfigurationLogger.LOG.invalidConfigurationPropertyValue(value, key.get()); } }
private void processKeyValue(Map<ConfigurationKey, Object> properties, String stringKey, Object value, boolean integratorSource) { ConfigurationKey key = ConfigurationKey.fromString(stringKey); if (key != null) { if (key.isIntegratorOnly() && !integratorSource) { ConfigurationLogger.LOG.cannotSetIntegratorOnlyConfigurationProperty(stringKey, value); } else { processKeyValue(properties, key, value); } } else { ConfigurationLogger.LOG.unsupportedConfigurationKeyFound(stringKey); } }
/** * Iterate through the {@link ConfigurationKey#values()} and try to get a system property for every key. The value is automatically converted - a runtime * exception may be thrown during conversion. * * @return all the properties set as system properties */ private Map<ConfigurationKey, Object> getSystemProperties() { Map<ConfigurationKey, Object> found = new EnumMap<ConfigurationKey, Object>(ConfigurationKey.class); for (ConfigurationKey key : ConfigurationKey.values()) { String property = getSystemProperty(key.get()); if (property != null) { processKeyValue(found, key, property); } } return found; }
/** * Try to get a system property for obsolete keys. The value is automatically converted - a runtime exception may be thrown during conversion. * * @return all the properties whose system property keys were different in previous versions */ private Map<ConfigurationKey, Object> getObsoleteSystemProperties() { Map<ConfigurationKey, Object> found = new EnumMap<ConfigurationKey, Object>(ConfigurationKey.class); String concurrentDeployment = getSystemProperty("org.jboss.weld.bootstrap.properties.concurrentDeployment"); if (concurrentDeployment != null) { processKeyValue(found, ConfigurationKey.CONCURRENT_DEPLOYMENT, concurrentDeployment); found.put(ConfigurationKey.CONCURRENT_DEPLOYMENT, ConfigurationKey.CONCURRENT_DEPLOYMENT.convertValue(concurrentDeployment)); } String preloaderThreadPoolSize = getSystemProperty("org.jboss.weld.bootstrap.properties.preloaderThreadPoolSize"); if (preloaderThreadPoolSize != null) { found.put(ConfigurationKey.PRELOADER_THREAD_POOL_SIZE, ConfigurationKey.PRELOADER_THREAD_POOL_SIZE.convertValue(preloaderThreadPoolSize)); } return found; }
@SuppressWarnings("unchecked") private <T> T getProperty(ConfigurationKey key, Class<T> requiredType) { checkRequiredType(key, requiredType); Object property = properties.get(key); return (T) (property != null ? property : key.getDefaultValue()); }
/** * Process the given string key and value. First try to convert the <code>stringKey</code> - unsupported keys are ignored. Then delegate to * {@link #processKeyValue(Map, ConfigurationKey, Object)}. * * @param properties * @param stringKey * @param value */ private void processKeyValue(Map<ConfigurationKey, Object> properties, String stringKey, Object value) { ConfigurationKey key = ConfigurationKey.fromString(stringKey); if (key != null) { processKeyValue(properties, key, value); } else { ConfigurationLogger.LOG.unsupportedConfigurationKeyFound(stringKey); } }
@PreDestroy public void unsetProperties() { Properties props = load(PROPERTIES_FILE_NAME); if (props != null) { for (Map.Entry<Object, Object> entry : props.entrySet()) { if (ConfigurationKey.fromString(entry.getKey().toString()) != null) { System.setProperty(entry.getKey().toString(), ConfigurationKey.fromString(entry.getKey().toString()).getDefaultValue().toString()); } else { System.clearProperty(entry.getKey().toString()); } } } }
static List<ConfigurationKey> getSortedConfigurationKeys() { List<ConfigurationKey> configurationKeys = new ArrayList<>(); Collections.addAll(configurationKeys, ConfigurationKey.values()); Collections.sort(configurationKeys, new Comparator<ConfigurationKey>() { @Override public int compare(ConfigurationKey o1, ConfigurationKey o2) { return o1.get().compareTo(o2.get()); } }); return configurationKeys; }
static String getDesc(ConfigurationKey key) { try { Field field = ConfigurationKey.class.getDeclaredField(key.toString()); if (field != null && field.isEnumConstant()) { Description description = field.getAnnotation(Description.class); if (description == null) { // Don't show config options without description return null; } return description.value(); } } catch (NoSuchFieldException | SecurityException | NullPointerException ignored) { } return null; }
/** * * @param value * @return <code>true</code> if the given value corresponds to the type of the default value, <code>false</code> otherwise */ public boolean isValidValue(Object value) { return isValidValueType(value.getClass()); }
/** * * @param key The string representation of the key * @param defaultValue The default value */ ConfigurationKey(String key, Object defaultValue) { this.key = key; // Fail fast if a new key with unsupported value type is introduced if (!isValueTypeSupported(defaultValue.getClass())) { throw new IllegalArgumentException("Unsupported value type: " + defaultValue); } this.defaultValue = defaultValue; }