@Test public void should_expand_variables_without_braces() { System.setProperty(MY_PROP1, "XXX"); System.setProperty(MY_PROP2, "YYY"); String userVariableName; if (System.getProperty("os.name").startsWith(("Windows"))) { userVariableName = "$USERNAME"; } else { userVariableName = "$USER"; } Properties props = new Properties(); props.setProperty(MY_PROP1, "XXX_from_props"); props.setProperty(MY_PROP3, "ZZZ"); String actual = expandVariables( props, userVariableName + " $" + MY_PROP1 + " foo $" + MY_PROP2 + " bar $" + MY_PROP3 + "${user.name}baz"); assertThat( actual, is( System.getProperty("user.name") + " XXX foo YYY bar ZZZ" + System.getProperty("user.name") + "baz")); }
Optional<String> expandVariables(Properties props, String key, String defaultValue) { String value = System.getProperty(getSystemPropertyName(key)); if (value == null) { value = System.getenv(getEnvVarName(key)); } if (value == null) { value = props.getProperty(key, defaultValue); } return value == null || value.trim().isEmpty() ? Optional.empty() : Optional.of(expandVariables(props, value)); }
ConfigUtils { Optional<String> expandVariables(Properties props, String key, String defaultValue) { String value = System.getProperty(getSystemPropertyName(key)); if (value == null) { value = System.getenv(getEnvVarName(key)); } if (value == null) { value = props.getProperty(key, defaultValue); } return value == null || value.trim().isEmpty() ? Optional.empty() : Optional.of(expandVariables(props, value)); } }
ConfigUtils { Optional<String> expandVariables(Properties props, String key, String defaultValue) { String value = System.getProperty(getSystemPropertyName(key)); if (value == null) { value = System.getenv(getEnvVarName(key)); } if (value == null) { value = props.getProperty(key, defaultValue); } return value == null || value.trim().isEmpty() ? Optional.empty() : Optional.of(expandVariables(props, value)); }  }
ConfigUtils { Optional<String> expandVariables(Properties props, String key, String defaultValue) { String value = System.getProperty(getSystemPropertyName(key)); if (value == null) { value = System.getenv(getEnvVarName(key)); } if (value == null) { value = props.getProperty(key, defaultValue); } return value == null || value.trim().isEmpty() ? Optional.empty() : Optional.of(expandVariables(props, value)); }  List<String> getNormalizedPackages(String packages); String getStringValue(Properties props, String propertyName, String defaultValue); String getStringValue2(
      Properties props, String propertyName1, String propertyName2, String defaultValue); Optional<String> getStringValue(Properties props, String propertyName); boolean getBooleanValue(Properties props, String key, boolean defaultValue); int getIntValue(Properties props, String key, int defaultValue); String getEnvVarName(String propertyName); String getSystemPropertyName(String key); List<File> getCommaSeparatedFileValues(String uriValues); }
ConfigUtils { Optional<String> expandVariables(Properties props, String key, String defaultValue) { String value = System.getProperty(getSystemPropertyName(key)); if (value == null) { value = System.getenv(getEnvVarName(key)); } if (value == null) { value = props.getProperty(key, defaultValue); } return value == null || value.trim().isEmpty() ? Optional.empty() : Optional.of(expandVariables(props, value)); }  List<String> getNormalizedPackages(String packages); String getStringValue(Properties props, String propertyName, String defaultValue); String getStringValue2(
      Properties props, String propertyName1, String propertyName2, String defaultValue); Optional<String> getStringValue(Properties props, String propertyName); boolean getBooleanValue(Properties props, String key, boolean defaultValue); int getIntValue(Properties props, String key, int defaultValue); String getEnvVarName(String propertyName); String getSystemPropertyName(String key); List<File> getCommaSeparatedFileValues(String uriValues);  }