import com.intellij.conversion.ConversionService;
import com.intellij.ide.IdeBundle;
import com.intellij.openapi.application.PathMacros;
+import com.intellij.openapi.components.impl.stores.StorageUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.ModifiableModuleModel;
import com.intellij.openapi.module.Module;
}
final Document document = JDOMUtil.loadDocument(file);
final Element root = document.getRootElement();
- final Set<String> usedMacros = PathMacrosCollector.getMacroNames(root);
+ final Set<String> usedMacros = StorageUtil.getMacroNames(root);
final Set<String> definedMacros = PathMacros.getInstance().getAllMacroNames();
usedMacros.remove("$" + PathMacrosImpl.MODULE_DIR_MACRO_NAME + "$");
usedMacros.removeAll(definedMacros);
package com.intellij.application.options;
import com.intellij.openapi.components.PathMacroMap;
+import com.intellij.util.NotNullFunction;
import org.jdom.Element;
+import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.HashSet;
*/
public class PathMacrosCollector extends PathMacroMap {
private final Matcher myMatcher;
- private static final String FILE_PROTOCOL = "file://";
- private static final String JAR_PROTOCOL = "jar://";
private static final Set<String> ourSystemMacroNames = new HashSet<String>(
Arrays.asList(PathMacrosImpl.APPLICATION_HOME_MACRO_NAME, PathMacrosImpl.MODULE_DIR_MACRO_NAME, PathMacrosImpl.PROJECT_DIR_MACRO_NAME));
myMatcher = pattern.matcher("");
}
- public static Set<String> getMacroNames(Element root) {
+ public static Set<String> getMacroNames(Element root, @Nullable final NotNullFunction<Object, Boolean> filter) {
final PathMacrosCollector collector = new PathMacrosCollector();
- collector.substitute(root, true);
+ collector.substitute(root, true, false, filter);
final HashSet<String> result = new HashSet<String>(collector.myMacroMap.keySet());
result.removeAll(ourSystemMacroNames);
return result;
}
public String substitute(String text, boolean caseSensitive) {
- final String protocol;
- if (text.length() > 7 && text.charAt(0) == 'f') {
- protocol = FILE_PROTOCOL;
- } else if (text.length() > 6 && text.charAt(0) == 'j') {
- protocol = JAR_PROTOCOL;
- } else {
- return text;
- }
-
- for (int i = 0; i < protocol.length(); i++) {
- if (text.charAt(i) != protocol.charAt(i)) return text;
- }
-
myMatcher.reset(text);
while (myMatcher.find()) {
final String macroName = myMatcher.group(1);
package com.intellij.openapi.components;
import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.util.NotNullFunction;
import org.jdom.Attribute;
import org.jdom.Comment;
import org.jdom.Element;
import org.jdom.Text;
+import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.LinkedHashMap;
substitute(e, caseSensitive, false);
}
- public final void substitute(Element e, boolean caseSensitive, final boolean recursively) {
+ public final void substitute(Element e, boolean caseSensitive, final boolean recursively, @Nullable final NotNullFunction<Object, Boolean> filter) {
List content = e.getContent();
for (Object child : content) {
if (child instanceof Element) {
Element element = (Element)child;
- substitute(element, caseSensitive, recursively);
+ substitute(element, caseSensitive, recursively, filter);
}
else if (child instanceof Text) {
Text t = (Text)child;
- t.setText(recursively ? substituteRecursively(t.getText(), caseSensitive) : substitute(t.getText(), caseSensitive));
+ if (filter == null || filter.fun(t)) t.setText(recursively ? substituteRecursively(t.getText(), caseSensitive) : substitute(t.getText(), caseSensitive));
}
else if (child instanceof Comment) {
/*do not substitute in comments
List attributes = e.getAttributes();
for (final Object attribute1 : attributes) {
Attribute attribute = (Attribute)attribute1;
- final String value = recursively
- ? substituteRecursively(attribute.getValue(), caseSensitive)
- : substitute(attribute.getValue(), caseSensitive);
- attribute.setValue(value);
+ if (filter == null || filter.fun(attribute)) {
+ final String value = recursively
+ ? substituteRecursively(attribute.getValue(), caseSensitive)
+ : substitute(attribute.getValue(), caseSensitive);
+ attribute.setValue(value);
+ }
}
}
+ public final void substitute(Element e, boolean caseSensitive, final boolean recursively) {
+ substitute(e, caseSensitive, recursively, null);
+ }
+
public String substituteRecursively(String text, boolean caseSensitive) {
return substitute(text, caseSensitive);
}
if (myPathMacroSubstitutor != null) {
myPathMacroSubstitutor.expandPaths(element);
- final Set<String> unknownMacros = PathMacrosCollector.getMacroNames(element);
+ final Set<String> unknownMacros = StorageUtil.getMacroNames(element);
myPathMacroSubstitutor.addUnknownMacros(componentName, unknownMacros);
}
public boolean hasState(final Object component, final String componentName, final Class<?> aClass, final boolean reloadData) throws StateStorageException {
if (!myDir.exists()) return false;
+ if (reloadData) myStorageData = null;
return true;
}
*/
package com.intellij.openapi.components.impl.stores;
+import com.intellij.application.options.PathMacrosCollector;
import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.NotNullFunction;
import com.intellij.util.SystemProperties;
import com.intellij.util.UniqueFileNamesProvider;
import com.intellij.util.io.fs.FileSystem;
import com.intellij.util.io.fs.IFile;
+import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
}
}
+ @NotNull
+ public static Set<String> getMacroNames(@NotNull final Element e) {
+ return PathMacrosCollector.getMacroNames(e, new NotNullFunction<Object, Boolean>() {
+ @NotNull
+ public Boolean fun(Object o) {
+ if (o instanceof Attribute) {
+ final Attribute attribute = (Attribute)o;
+ final Element parent = attribute.getParent();
+ if (("value".equals(attribute.getName()) || "name".equals(attribute.getName())) && parent != null && "env".equals(parent.getName())) {
+ return false; // do not proceed environment variables from run configurations
+ }
+
+ // do not proceed macros in searchConfigurations (structural search)
+ if (parent != null && ("replaceConfiguration".equals(parent.getName())
+ || "searchConfiguration".equals(parent.getName()))) return false;
+ }
+
+ return true;
+ }
+ });
+ }
@Nullable
public static Document loadDocument(final byte[] bytes) {
public void checkUnknownMacros(TrackingPathMacroSubstitutor pathMacroSubstitutor) {
for (String componentName : myComponentStates.keySet()) {
- final Set<String> unknownMacros = PathMacrosCollector.getMacroNames(myComponentStates.get(componentName));
+ final Set<String> unknownMacros = StorageUtil.getMacroNames(myComponentStates.get(componentName));
if (!unknownMacros.isEmpty()) {
pathMacroSubstitutor.addUnknownMacros(componentName, unknownMacros);
}