FrameworkUploader implements Runnable { @VisibleForTesting String expandEnvironmentVariables(String innerInput, Map<String, String> env) throws UploaderException { boolean found; do { found = false; Matcher matcher = VAR_SUBBER.matcher(innerInput); StringBuffer stringBuffer = new StringBuffer(); while (matcher.find()) { found = true; String var = matcher.group(1); String replace = env.get(var); if (replace == null) { throw new UploaderException("Environment variable does not exist " + var); } matcher.appendReplacement( stringBuffer, Matcher.quoteReplacement(replace)); } matcher.appendTail(stringBuffer); innerInput = stringBuffer.toString(); } while (found); return innerInput; }  void run(); static void main(String[] args);  }
@Test public void testEnvironmentReplacement() throws UploaderException { String input = "C/$A/B,$B,D"; Map<String, String> map = new HashMap<>(); map.put("A", "X"); map.put("B", "Y"); map.put("C", "Z"); FrameworkUploader uploader = new FrameworkUploader(); String output = uploader.expandEnvironmentVariables(input, map); Assert.assertEquals("Environment not expanded", "C/X/B,Y,D", output); }
@Test public void testRecursiveEnvironmentReplacement() throws UploaderException { String input = "C/$A/B,$B,D"; Map<String, String> map = new HashMap<>(); map.put("A", "X"); map.put("B", "$C"); map.put("C", "Y"); FrameworkUploader uploader = new FrameworkUploader(); String output = uploader.expandEnvironmentVariables(input, map); Assert.assertEquals("Environment not expanded", "C/X/B,Y,D", output); }