@Test public void testSetEnvFromInputStringWithQuotes() { Map<String, String> environment = new HashMap<String, String>(); String envString = "YARN_CONTAINER_RUNTIME_TYPE=docker" + ",YARN_CONTAINER_RUNTIME_DOCKER_IMAGE=hadoop-docker" + ",YARN_CONTAINER_RUNTIME_DOCKER_LOCAL_RESOURCE_MOUNTS=\"/dir1:/targetdir1,/dir2:/targetdir2\"" + ",YARN_CONTAINER_RUNTIME_DOCKER_ENVIRONMENT_VARIABLES=\"HADOOP_CONF_DIR=$HADOOP_CONF_DIR,HADOOP_HDFS_HOME=/hadoop\"" ; Apps.setEnvFromInputString(environment, envString, File.pathSeparator); assertEquals("docker", environment.get("YARN_CONTAINER_RUNTIME_TYPE")); assertEquals("hadoop-docker", environment.get("YARN_CONTAINER_RUNTIME_DOCKER_IMAGE")); assertEquals("/dir1:/targetdir1,/dir2:/targetdir2", environment.get("YARN_CONTAINER_RUNTIME_DOCKER_LOCAL_RESOURCE_MOUNTS")); assertEquals("HADOOP_CONF_DIR=,HADOOP_HDFS_HOME=/hadoop", environment.get("YARN_CONTAINER_RUNTIME_DOCKER_ENVIRONMENT_VARIABLES")); environment.clear(); environment.put("HADOOP_CONF_DIR", "etc/hadoop"); Apps.setEnvFromInputString(environment, envString, File.pathSeparator); assertEquals("docker", environment.get("YARN_CONTAINER_RUNTIME_TYPE")); assertEquals("hadoop-docker", environment.get("YARN_CONTAINER_RUNTIME_DOCKER_IMAGE")); assertEquals("/dir1:/targetdir1,/dir2:/targetdir2", environment.get("YARN_CONTAINER_RUNTIME_DOCKER_LOCAL_RESOURCE_MOUNTS")); assertEquals("HADOOP_CONF_DIR=etc/hadoop,HADOOP_HDFS_HOME=/hadoop", environment.get("YARN_CONTAINER_RUNTIME_DOCKER_ENVIRONMENT_VARIABLES")); }
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; }