String (@NotNull @NonNls String text) { int start = text.indexOf("${"); if (start < 0) return text; Map<String, String> macroMap = myMacroMap.getValue(); Matcher matcher = MACRO_PATTERN.matcher(text); StringBuilder sb = null; while (matcher.find(start)) { String value = macroMap.get(matcher.group(1)); if (value != null) { if (sb == null) sb = new StringBuilder(2 * text.length()).append(text, 0, matcher.start()); else sb.append(text, start, matcher.start()); sb.append(value); start = matcher.end(); } else { if (sb != null) sb.append(text, start, matcher.start() + 2); start = matcher.start() + 2; } } return sb == null ? text : sb.append(text, start, text.length()).toString(); } public void patchMacroWithEnvs(Map<String, String> envs) { myMacroMap.getValue().putAll(envs); } private static Map<String, String> ourTestMacros; @TestOnly public static void setTestMacros(@Nullable @NonNls Map<String, String> testMacros) { ourTestMacros = testMacros; } private static @NotNull Map<String, String> computeMacroMap() { // ApplicationManager.getApplication() will return null if executed in ParameterListTest Application application = ApplicationManager.getApplication(); if (application == null || application.isUnitTestMode() && ourTestMacros != null) { return ObjectUtils.notNull(ourTestMacros, Collections.emptyMap()); } Map<String, String> map = CollectionFactory.createCaseInsensitiveStringMap(); Map<String, String> pathMacros = PathMacros.getInstance().getUserMacros(); if (!pathMacros.isEmpty()) { for (String name : pathMacros.keySet()) { String value = pathMacros.get(name); if (value != null) { map.put(name, value); } } } for (Map.Entry<String, String> entry : EnvironmentUtil.getEnvironmentMap().entrySet()) { map.putIfAbsent(entry.getKey(), entry.getValue()); } return map; } @NonNls @Override public String toString() { return myParameters + (myGroups.isEmpty() ? "" : " and " + myGroups); } }