@Test public void resolveEnvVars() throws Exception { environmentVariables.set("VARNAME1", "varvalue1"); environmentVariables.set("VARNAME2", "varvalue2"); String resolved = EnvVarResolverProperties .resolveEnvVars("padding ${VARNAME1} ${VARNAME2} padding"); Assert.assertEquals("padding varvalue1 varvalue2 padding", resolved); }
protected static String resolveEnvVars(String input) { Preconditions.checkNotNull(input); Pattern p = Pattern.compile("\\$\\{(\\w+)\\}"); Matcher m = p.matcher(input); StringBuffer sb = new StringBuffer(); while (m.find()) { String envVarName = m.group(1); String envVarValue = System.getenv(envVarName); m.appendReplacement(sb, null == envVarValue ? "" : envVarValue); } m.appendTail(sb); return sb.toString(); }
EnvVarResolverProperties extends Properties { protected static String resolveEnvVars(String input) { Preconditions.checkNotNull(input); Pattern p = Pattern.compile("\\$\\{(\\w+)\\}"); Matcher m = p.matcher(input); StringBuffer sb = new StringBuffer(); while (m.find()) { String envVarName = m.group(1); String envVarValue = System.getenv(envVarName); m.appendReplacement(sb, null == envVarValue ? "" : envVarValue); } m.appendTail(sb); return sb.toString(); } }
EnvVarResolverProperties extends Properties { protected static String resolveEnvVars(String input) { Preconditions.checkNotNull(input); Pattern p = Pattern.compile("\\$\\{(\\w+)\\}"); Matcher m = p.matcher(input); StringBuffer sb = new StringBuffer(); while (m.find()) { String envVarName = m.group(1); String envVarValue = System.getenv(envVarName); m.appendReplacement(sb, null == envVarValue ? "" : envVarValue); } m.appendTail(sb); return sb.toString(); }  }
EnvVarResolverProperties extends Properties { protected static String resolveEnvVars(String input) { Preconditions.checkNotNull(input); Pattern p = Pattern.compile("\\$\\{(\\w+)\\}"); Matcher m = p.matcher(input); StringBuffer sb = new StringBuffer(); while (m.find()) { String envVarName = m.group(1); String envVarValue = System.getenv(envVarName); m.appendReplacement(sb, null == envVarValue ? "" : envVarValue); } m.appendTail(sb); return sb.toString(); }  @Override String getProperty(String key); }
EnvVarResolverProperties extends Properties { protected static String resolveEnvVars(String input) { Preconditions.checkNotNull(input); Pattern p = Pattern.compile("\\$\\{(\\w+)\\}"); Matcher m = p.matcher(input); StringBuffer sb = new StringBuffer(); while (m.find()) { String envVarName = m.group(1); String envVarValue = System.getenv(envVarName); m.appendReplacement(sb, null == envVarValue ? "" : envVarValue); } m.appendTail(sb); return sb.toString(); }  @Override String getProperty(String key);  }