/*
 * Copyright (c) 2000-2004 by JetBrains s.r.o. All Rights Reserved.
 * Use is subject to license terms.
 */
package com.intellij.application.options;

import com.intellij.openapi.components.PathMacroMap;
import org.jdom.Element;

import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Eugene Zhuravlev
 *         Date: Dec 6, 2004
 */
public class PathMacrosCollector extends PathMacroMap {
  private final Matcher myMatcher;

  private PathMacrosCollector() {
    Pattern pattern = Pattern.compile("\\$(.*?)\\$");
    myMatcher = pattern.matcher("");
  }

  public static Set<String> getMacroNames(Element root) {
    final PathMacrosCollector collector = new PathMacrosCollector();
    collector.substitute(root, true);
    return new HashSet<String>(collector.myMacroMap.keySet());
  }

  public String substitute(String text, boolean caseSensitive) {
    myMatcher.reset(text);
    while (myMatcher.find()) {
      final String macroName = myMatcher.group(1);
      myMacroMap.put(macroName, null);

    }
    return text;
  }

}

@@ -494,16 +494,128 @@
 Matcher;
+%0A  private static final String FILE_PROTOCOL = %22file://%22;%0A  private static final String JAR_PROTOCOL = %22jar://%22;
 %0A%0A  priv
@@ -1032,24 +1032,386 @@
 ensitive) %7B%0A
+    final String protocol;%0A    if (text.length() %3E 7 && text.charAt(0) == 'f') %7B%0A      protocol = FILE_PROTOCOL;%0A    %7D else if (text.length() %3E 6 && text.charAt(0) == 'j') %7B%0A      protocol = JAR_PROTOCOL;%0A    %7D else %7B%0A      return text;%0A    %7D%0A%0A    for (int i = 0; i %3C protocol.length(); i++) %7B%0A      if (text.charAt(i) != protocol.charAt(i)) return text;%0A    %7D%0A%0A
     myMatche

fix PathMacroCollector to search for PathVariables only if text starts with file or jar protocol