@Test public void testSetEnvFromInputString() { Map<String, String> environment = new HashMap<String, String>(); environment.put("JAVA_HOME", "/path/jdk"); String goodEnv = "a1=1,b_2=2,_c=3,d=4,e=,f_win=%JAVA_HOME%" + ",g_nix=$JAVA_HOME"; Apps.setEnvFromInputString(environment, goodEnv, File.pathSeparator); assertEquals("1", environment.get("a1")); assertEquals("2", environment.get("b_2")); assertEquals("3", environment.get("_c")); assertEquals("4", environment.get("d")); assertEquals("", environment.get("e")); if (Shell.WINDOWS) { assertEquals("$JAVA_HOME", environment.get("g_nix")); assertEquals("/path/jdk", environment.get("f_win")); } else { assertEquals("/path/jdk", environment.get("g_nix")); assertEquals("%JAVA_HOME%", environment.get("f_win")); } String badEnv = "1,,2=a=b,3=a=,4==,5==a,==,c-3=3,="; environment.clear(); Apps.setEnvFromInputString(environment, badEnv, File.pathSeparator); assertEquals(environment.size(), 0); environment.clear(); Apps.setEnvFromInputString(environment, "b1,e1==,e2=a1=a2,b2", File.pathSeparator); assertEquals("=", environment.get("e1")); assertEquals("a1=a2", environment.get("e2")); }
public static void setEnvFromInputString(Map<String, String> env, String envString, String classPathSeparator) { if (envString != null && envString.length() > 0) { Matcher varValMatcher = VARVAL_SPLITTER.matcher(envString); while (varValMatcher.find()) { String envVar = varValMatcher.group(1); String envVal = varValMatcher.group(2).replaceAll("^\"|\"$", ""); Matcher m = VAR_SUBBER.matcher(envVal); StringBuffer sb = new StringBuffer(); while (m.find()) { String var = m.group(1); String replace = env.get(var); if (replace == null) replace = System.getenv(var); if (replace == null) replace = ""; m.appendReplacement(sb, Matcher.quoteReplacement(replace)); } m.appendTail(sb); addToEnvironment(env, envVar, sb.toString(), classPathSeparator); } } }
Apps { public static void setEnvFromInputString(Map<String, String> env, String envString, String classPathSeparator) { if (envString != null && envString.length() > 0) { Matcher varValMatcher = VARVAL_SPLITTER.matcher(envString); while (varValMatcher.find()) { String envVar = varValMatcher.group(1); String envVal = varValMatcher.group(2).replaceAll("^\"|\"$", ""); Matcher m = VAR_SUBBER.matcher(envVal); StringBuffer sb = new StringBuffer(); while (m.find()) { String var = m.group(1); String replace = env.get(var); if (replace == null) replace = System.getenv(var); if (replace == null) replace = ""; m.appendReplacement(sb, Matcher.quoteReplacement(replace)); } m.appendTail(sb); addToEnvironment(env, envVar, sb.toString(), classPathSeparator); } } } }
Apps { public static void setEnvFromInputString(Map<String, String> env, String envString, String classPathSeparator) { if (envString != null && envString.length() > 0) { Matcher varValMatcher = VARVAL_SPLITTER.matcher(envString); while (varValMatcher.find()) { String envVar = varValMatcher.group(1); String envVal = varValMatcher.group(2).replaceAll("^\"|\"$", ""); Matcher m = VAR_SUBBER.matcher(envVal); StringBuffer sb = new StringBuffer(); while (m.find()) { String var = m.group(1); String replace = env.get(var); if (replace == null) replace = System.getenv(var); if (replace == null) replace = ""; m.appendReplacement(sb, Matcher.quoteReplacement(replace)); } m.appendTail(sb); addToEnvironment(env, envVar, sb.toString(), classPathSeparator); } } }  }
Apps { public static void setEnvFromInputString(Map<String, String> env, String envString, String classPathSeparator) { if (envString != null && envString.length() > 0) { Matcher varValMatcher = VARVAL_SPLITTER.matcher(envString); while (varValMatcher.find()) { String envVar = varValMatcher.group(1); String envVal = varValMatcher.group(2).replaceAll("^\"|\"$", ""); Matcher m = VAR_SUBBER.matcher(envVal); StringBuffer sb = new StringBuffer(); while (m.find()) { String var = m.group(1); String replace = env.get(var); if (replace == null) replace = System.getenv(var); if (replace == null) replace = ""; m.appendReplacement(sb, Matcher.quoteReplacement(replace)); } m.appendTail(sb); addToEnvironment(env, envVar, sb.toString(), classPathSeparator); } } }  static ApplicationId toAppID(String aid); static ApplicationId toAppID(String prefix, String s, Iterator<String> it); static void shouldHaveNext(String prefix, String s, Iterator<String> it); static void throwParseException(String name, String s); static void setEnvFromInputString(Map<String, String> env,
      String envString,  String classPathSeparator); @Deprecated static void setEnvFromInputString(Map<String, String> env,
      String envString); @Public @Unstable static void addToEnvironment(
      Map<String, String> environment,
      String variable, String value, String classPathSeparator); @Deprecated static void addToEnvironment(
      Map<String, String> environment,
      String variable, String value); static String crossPlatformify(String var); }
Apps { public static void setEnvFromInputString(Map<String, String> env, String envString, String classPathSeparator) { if (envString != null && envString.length() > 0) { Matcher varValMatcher = VARVAL_SPLITTER.matcher(envString); while (varValMatcher.find()) { String envVar = varValMatcher.group(1); String envVal = varValMatcher.group(2).replaceAll("^\"|\"$", ""); Matcher m = VAR_SUBBER.matcher(envVal); StringBuffer sb = new StringBuffer(); while (m.find()) { String var = m.group(1); String replace = env.get(var); if (replace == null) replace = System.getenv(var); if (replace == null) replace = ""; m.appendReplacement(sb, Matcher.quoteReplacement(replace)); } m.appendTail(sb); addToEnvironment(env, envVar, sb.toString(), classPathSeparator); } } }  static ApplicationId toAppID(String aid); static ApplicationId toAppID(String prefix, String s, Iterator<String> it); static void shouldHaveNext(String prefix, String s, Iterator<String> it); static void throwParseException(String name, String s); static void setEnvFromInputString(Map<String, String> env,
      String envString,  String classPathSeparator); @Deprecated static void setEnvFromInputString(Map<String, String> env,
      String envString); @Public @Unstable static void addToEnvironment(
      Map<String, String> environment,
      String variable, String value, String classPathSeparator); @Deprecated static void addToEnvironment(
      Map<String, String> environment,
      String variable, String value); static String crossPlatformify(String var); static final String APP; static final String ID; }