diff --git a/jps/model-serialization/src/com/intellij/openapi/application/PathMacroFilter.java b/jps/model-serialization/src/com/intellij/openapi/application/PathMacroFilter.java
index 7d463bee9dc6..9bb39b1d7293 100644
--- a/jps/model-serialization/src/com/intellij/openapi/application/PathMacroFilter.java
+++ b/jps/model-serialization/src/com/intellij/openapi/application/PathMacroFilter.java
@@ -1,9 +1,8 @@
-// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.application;
import org.jdom.Attribute;
import org.jdom.Element;
-import org.jdom.Text;
import org.jetbrains.annotations.NotNull;
/**
@@ -16,18 +15,10 @@ public abstract class PathMacroFilter {
return false;
}
- public boolean skipPathMacros(Text element) {
- return false;
- }
-
public boolean skipPathMacros(@NotNull Attribute attribute) {
return false;
}
- public boolean recursePathMacros(Text element) {
- return false;
- }
-
public boolean recursePathMacros(Attribute attribute) {
return false;
}
diff --git a/jps/model-serialization/src/com/intellij/openapi/components/PathMacroMap.java b/jps/model-serialization/src/com/intellij/openapi/components/PathMacroMap.java
index 30ba779e2390..a96fc324f2fe 100644
--- a/jps/model-serialization/src/com/intellij/openapi/components/PathMacroMap.java
+++ b/jps/model-serialization/src/com/intellij/openapi/components/PathMacroMap.java
@@ -1,18 +1,4 @@
-/*
- * Copyright 2000-2016 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.components;
import com.intellij.openapi.application.PathMacroFilter;
@@ -40,26 +26,22 @@ public abstract class PathMacroMap {
substitute(e, caseSensitive, false);
}
- public final void substitute(@NotNull Element e, boolean caseSensitive, boolean recursively, @Nullable PathMacroFilter filter) {
- if (filter != null && filter.skipPathMacros(e)) {
+ public final void substitute(@NotNull Element element, boolean caseSensitive, boolean recursively, @Nullable PathMacroFilter filter) {
+ if (filter != null && filter.skipPathMacros(element)) {
return;
}
- for (Content child : e.getContent()) {
+ for (Content child : element.getContent()) {
if (child instanceof Element) {
substitute((Element)child, caseSensitive, recursively, filter);
}
else if (child instanceof Text) {
Text t = (Text)child;
- if (filter == null || !filter.skipPathMacros(t)) {
- String oldText = t.getText();
- String newText = (recursively || (filter != null && filter.recursePathMacros(t)))
- ? substituteRecursively(oldText, caseSensitive)
- : substitute(oldText, caseSensitive);
- if (oldText != newText) {
- // it is faster to call 'setText' right away than perform additional 'equals' check
- t.setText(newText);
- }
+ String oldText = t.getText();
+ String newText = recursively ? substituteRecursively(oldText, caseSensitive) : substitute(oldText, caseSensitive);
+ if (oldText != newText) {
+ // it is faster to call 'setText' right away than perform additional 'equals' check
+ t.setText(newText);
}
}
else if (!(child instanceof Comment)) {
@@ -67,13 +49,14 @@ public abstract class PathMacroMap {
}
}
- for (Attribute attribute : e.getAttributes()) {
+ if (!element.hasAttributes()) {
+ return;
+ }
+
+ for (Attribute attribute : element.getAttributes()) {
if (filter == null || !filter.skipPathMacros(attribute)) {
- String oldValue = attribute.getValue();
- String newValue = (recursively || (filter != null && filter.recursePathMacros(attribute)))
- ? substituteRecursively(oldValue, caseSensitive)
- : substitute(oldValue, caseSensitive);
- if (oldValue != newValue) {
+ String newValue = getAttributeValue(attribute, filter, caseSensitive, recursively);
+ if (attribute.getValue() != newValue) {
// it is faster to call 'setValue' right away than perform additional 'equals' check
attribute.setValue(newValue);
}
@@ -81,6 +64,16 @@ public abstract class PathMacroMap {
}
}
+ public String getAttributeValue(@NotNull Attribute attribute, @Nullable PathMacroFilter filter, boolean caseSensitive, boolean recursively) {
+ String oldValue = attribute.getValue();
+ if (recursively || (filter != null && filter.recursePathMacros(attribute))) {
+ return substituteRecursively(oldValue, caseSensitive);
+ }
+ else {
+ return substitute(oldValue, caseSensitive);
+ }
+ }
+
public final void substitute(@NotNull Element e, boolean caseSensitive, final boolean recursively) {
substitute(e, caseSensitive, recursively, null);
}
diff --git a/platform/configuration-store-impl/src/JbXmlOutputter.java b/platform/configuration-store-impl/src/JbXmlOutputter.java
index 5fe6f3dc4823..f8bba4a6d8fb 100644
--- a/platform/configuration-store-impl/src/JbXmlOutputter.java
+++ b/platform/configuration-store-impl/src/JbXmlOutputter.java
@@ -52,7 +52,10 @@
*/
package com.intellij.configurationStore;
+import com.intellij.application.options.ReplacePathToMacroMap;
+import com.intellij.openapi.application.PathMacroFilter;
import com.intellij.openapi.util.JDOMUtil;
+import com.intellij.openapi.util.SystemInfoRt;
import com.intellij.openapi.util.text.StringUtil;
import org.jdom.*;
import org.jdom.output.Format;
@@ -65,7 +68,7 @@ import java.io.Writer;
import java.util.List;
@SuppressWarnings("Duplicates")
-class JbXmlOutputter {
+final class JbXmlOutputter {
private static final Format DEFAULT_FORMAT = JDOMUtil.createFormat("\n");
// For normal output
@@ -73,9 +76,19 @@ class JbXmlOutputter {
@Nullable
private final JDOMUtil.ElementOutputFilter elementFilter;
- public JbXmlOutputter(@NotNull String lineSeparator, @Nullable JDOMUtil.ElementOutputFilter elementFilter) {
+ @Nullable
+ private final ReplacePathToMacroMap macroMap;
+ @Nullable
+ private final PathMacroFilter macroFilter;
+
+ public JbXmlOutputter(@NotNull String lineSeparator,
+ @Nullable JDOMUtil.ElementOutputFilter elementFilter,
+ @Nullable ReplacePathToMacroMap macroMap,
+ @Nullable PathMacroFilter macroFilter) {
this.format = DEFAULT_FORMAT.getLineSeparator().equals(lineSeparator) ? DEFAULT_FORMAT : JDOMUtil.createFormat(lineSeparator);
this.elementFilter = elementFilter;
+ this.macroMap = macroMap;
+ this.macroFilter = macroFilter;
}
/**
@@ -169,7 +182,7 @@ class JbXmlOutputter {
* @param out Writer to use.
* @param encoding The encoding to add to the declaration
*/
- protected void printDeclaration(Writer out, String encoding) throws IOException {
+ private void printDeclaration(Writer out, String encoding) throws IOException {
// Only print the declaration if it's not being omitted
if (!format.getOmitDeclaration()) {
// Assume 1.0 version
@@ -192,7 +205,7 @@ class JbXmlOutputter {
* @param docType Document whose declaration to write.
* @param out Writer to use.
*/
- protected void printDocType(Writer out, DocType docType) throws IOException {
+ private void printDocType(Writer out, DocType docType) throws IOException {
String publicID = docType.getPublicID();
String systemID = docType.getSystemID();
@@ -230,7 +243,7 @@ class JbXmlOutputter {
* @param comment Comment to write.
* @param out Writer to use.
*/
- protected void printComment(Writer out, Comment comment)
+ private static void printComment(Writer out, Comment comment)
throws IOException {
out.write("