@Test public void testGetConfigFilter() { // make sure no ConfigFilter is left over from previous tests ConfigResolver.getConfigProvider().releaseConfig(ClassUtils.getClassLoader(null)); List<ConfigFilter> configFilters = ConfigResolver.getConfigFilters(); Assert.assertNotNull(configFilters); Assert.assertEquals(1, configFilters.size()); Assert.assertEquals(SecretTestConfigFilter.class, configFilters.get(0).getClass()); }
/** * Resolve all values for the given key. * * @param key * * @return a List of all found property values, sorted by their ordinal in ascending order * * @see org.apache.deltaspike.core.spi.config.ConfigSource#getOrdinal() */ public static List<String> getAllPropertyValues(String key) { ConfigSource[] configSources = getConfigProvider().getConfig().getConfigSources(); List<String> result = new ArrayList<String>(); for (int i = configSources.length; i > 0; i--) { String value = configSources[i - 1].getPropertyValue(key); if (value != null) { value = filterConfigValue(key, value); if (!result.contains(value)) { result.add(value); } } } return result; }
@Test public void testDiffConfig() { ConfigResolver.ConfigHelper cfgHelper = ConfigResolver.getConfigProvider().getHelper(); Map<String, String> oldVal = new HashMap<>(); Map<String, String> newVal = new HashMap<>(); oldVal.put("a", "1"); newVal.put("b", "2"); newVal.put("a", "1"); assertAll(cfgHelper.diffConfig(null, newVal), "a", "b"); assertAll(cfgHelper.diffConfig(oldVal, null), "a"); assertAll(cfgHelper.diffConfig(oldVal, newVal), "b"); assertAll(cfgHelper.diffConfig(oldVal, oldVal)); assertAll(cfgHelper.diffConfig(newVal, newVal)); newVal.put("a", "5"); assertAll(cfgHelper.diffConfig(oldVal, newVal), "a", "b"); }
return getConfigProvider().getConfig().resolve(key) .withCurrentProjectStage(true) .parameterizedBy(property)
return getConfigProvider().getConfig().resolve(key) .withCurrentProjectStage(true) .parameterizedBy(property)
/** * Resolves the value configured for the given key in the current * {@link org.apache.deltaspike.core.api.projectstage.ProjectStage}. * * <p> * First, it will search for a value configured for the given key suffixed with the current ProjectStage (e.g. * 'myproject.myconfig.Production'), and in case this value is not found (null or empty), it will look up the given * key without any suffix.</p> * * <p> * <b>Attention</b> This method must only be used after all ConfigSources got registered and it also must not be * used to determine the ProjectStage itself.</p> * * @param key * * @return the value configured for {@code <given key>.<current project stage>}, or just the configured value of * {@code <given key>} if the project-stage-specific value is not found (null or empty) * */ public static String getProjectStageAwarePropertyValue(String key) { return getConfigProvider().getConfig().resolve(key) .withCurrentProjectStage(true) .evaluateVariables(true) .getValue(); } /**
/** * Resolves the value configured for the given key in the current * {@link org.apache.deltaspike.core.api.projectstage.ProjectStage}. * * <p> * First, it will search for a value configured for the given key suffixed with the current ProjectStage (e.g. * 'myproject.myconfig.Production'), and in case this value is not found (null or empty), it will look up the given * key without any suffix.</p> * * <p> * <b>Attention</b> This method must only be used after all ConfigSources got registered and it also must not be * used to determine the ProjectStage itself.</p> * * @param key * * @return the value configured for {@code <given key>.<current project stage>}, or just the configured value of * {@code <given key>} if the project-stage-specific value is not found (null or empty) * */ public static String getProjectStageAwarePropertyValue(String key) { return getConfigProvider().getConfig().resolve(key) .withCurrentProjectStage(true) .evaluateVariables(true) .getValue(); } /**
/** * Resolve all values for the given key. * * @param key * * @return a List of all found property values, sorted by their ordinal in ascending order * * @see org.apache.deltaspike.core.spi.config.ConfigSource#getOrdinal() */ public static List<String> getAllPropertyValues(String key) { ConfigSource[] configSources = getConfigProvider().getConfig().getConfigSources(); List<String> result = new ArrayList<String>(); for (int i = configSources.length; i > 0; i--) { String value = configSources[i - 1].getPropertyValue(key); if (value != null) { value = filterConfigValue(key, value); if (!result.contains(value)) { result.add(value); } } } return result; }
/** * {@link #getPropertyAwarePropertyValue(java.lang.String, java.lang.String)} which returns the provided default * value if no configured value can be found (<code>null</code> or empty). * * <p> * <b>Attention</b> This method must only be used after all ConfigSources got registered and it also must not be * used to determine the ProjectStage itself.</p> * * @param key * @param property the property to look up first and use as the parameter for the main lookup * @param defaultValue fallback value * * @return the configured value or if non found the defaultValue * */ public static String getPropertyAwarePropertyValue(String key, String property, String defaultValue) { return getConfigProvider().getConfig().resolve(key) .withCurrentProjectStage(true) .parameterizedBy(property) .withDefault(defaultValue) .evaluateVariables(true) .getValue(); }
/** * Returns a Map of all properties from all scannable config sources. The values of the properties reflect the * values that would be obtained by a call to {@link #getPropertyValue(java.lang.String)}, that is, the value of the * property from the ConfigSource with the highest ordinal. * * @see ConfigSource#isScannable() */ public static Map<String, String> getAllProperties() { ConfigSource[] configSources = getConfigProvider().getConfig().getConfigSources(); Map<String, String> result = new HashMap<String, String>(); for (int i = configSources.length; i > 0; i--) { ConfigSource configSource = configSources[i - 1]; if (configSource.isScannable()) { result.putAll(configSource.getProperties()); } } return Collections.unmodifiableMap(result); }
/** * {@link #getPropertyAwarePropertyValue(java.lang.String, java.lang.String)} which returns the provided default * value if no configured value can be found (<code>null</code> or empty). * * <p> * <b>Attention</b> This method must only be used after all ConfigSources got registered and it also must not be * used to determine the ProjectStage itself.</p> * * @param key * @param property the property to look up first and use as the parameter for the main lookup * @param defaultValue fallback value * * @return the configured value or if non found the defaultValue * */ public static String getPropertyAwarePropertyValue(String key, String property, String defaultValue) { return getConfigProvider().getConfig().resolve(key) .withCurrentProjectStage(true) .parameterizedBy(property) .withDefault(defaultValue) .evaluateVariables(true) .getValue(); }
/** * Returns a Map of all properties from all scannable config sources. The values of the properties reflect the * values that would be obtained by a call to {@link #getPropertyValue(java.lang.String)}, that is, the value of the * property from the ConfigSource with the highest ordinal. * * @see ConfigSource#isScannable() */ public static Map<String, String> getAllProperties() { ConfigSource[] configSources = getConfigProvider().getConfig().getConfigSources(); Map<String, String> result = new HashMap<String, String>(); for (int i = configSources.length; i > 0; i--) { ConfigSource configSource = configSources[i - 1]; if (configSource.isScannable()) { result.putAll(configSource.getProperties()); } } return Collections.unmodifiableMap(result); }
/** * {@link #getProjectStageAwarePropertyValue(String)} which returns the provided default value if no configured * value can be found (<code>null</code> or empty). * * @param key * @param defaultValue fallback value * * @return the configured value or if non found the defaultValue * */ public static String getProjectStageAwarePropertyValue(String key, String defaultValue) { return getConfigProvider().getConfig().resolve(key) .withCurrentProjectStage(true) .withDefault(defaultValue) .evaluateVariables(true) .getValue(); }
/** * {@link #getProjectStageAwarePropertyValue(String)} which returns the provided default value if no configured * value can be found (<code>null</code> or empty). * * @param key * @param defaultValue fallback value * * @return the configured value or if non found the defaultValue * */ public static String getProjectStageAwarePropertyValue(String key, String defaultValue) { return getConfigProvider().getConfig().resolve(key) .withCurrentProjectStage(true) .withDefault(defaultValue) .evaluateVariables(true) .getValue(); }
/** * Resolves the value configured for the given key. * * @param key the property key * @param evaluateVariables whether to evaluate any '${variablename}' variable expressions * * @return the configured property value from the {@link ConfigSource} with the highest ordinal or null if there is * no configured value for it */ public static String getPropertyValue(String key, boolean evaluateVariables) { return getConfigProvider().getConfig().resolve(key) .evaluateVariables(evaluateVariables) .withCurrentProjectStage(false) .getValue(); }
/** * Resolves the value configured for the given key. * * @param key the property key * * @return the configured property value from the {@link ConfigSource} with the highest ordinal or null if there is * no configured value for it */ public static String getPropertyValue(String key) { return getConfigProvider().getConfig().resolve(key) .evaluateVariables(true) .withCurrentProjectStage(false) .getValue(); }
/** * Resolves the value configured for the given key. * * @param key the property key * @param evaluateVariables whether to evaluate any '${variablename}' variable expressions * * @return the configured property value from the {@link ConfigSource} with the highest ordinal or null if there is * no configured value for it */ public static String getPropertyValue(String key, boolean evaluateVariables) { return getConfigProvider().getConfig().resolve(key) .evaluateVariables(evaluateVariables) .withCurrentProjectStage(false) .getValue(); }
/** * The entry point to the builder-based optionally typed configuration resolution mechanism. * * String is the default type for configuration entries and is not considered a 'type' by this resolver. Therefore * an UntypedResolver is returned by this method. To convert the configuration value to another type, call * {@link UntypedResolver#as(Class)}. * * @param name The property key to resolve * @return A builder for configuration resolution. */ public static UntypedResolver<String> resolve(String name) { return getConfigProvider().getConfig().resolve(name); }
/** * Resolves the value configured for the given key. * * @param key the property key * * @return the configured property value from the {@link ConfigSource} with the highest ordinal or null if there is * no configured value for it */ public static String getPropertyValue(String key) { return getConfigProvider().getConfig().resolve(key) .evaluateVariables(true) .withCurrentProjectStage(false) .getValue(); }
/** * The entry point to the builder-based optionally typed configuration resolution mechanism. * * String is the default type for configuration entries and is not considered a 'type' by this resolver. Therefore * an UntypedResolver is returned by this method. To convert the configuration value to another type, call * {@link UntypedResolver#as(Class)}. * * @param name The property key to resolve * @return A builder for configuration resolution. */ public static UntypedResolver<String> resolve(String name) { return getConfigProvider().getConfig().resolve(name); }