diff --git a/platform/configuration-store-impl/src/ApplicationStoreImpl.kt b/platform/configuration-store-impl/src/ApplicationStoreImpl.kt index 58e2e7e3c40c..2b77a1042f38 100644 --- a/platform/configuration-store-impl/src/ApplicationStoreImpl.kt +++ b/platform/configuration-store-impl/src/ApplicationStoreImpl.kt @@ -24,17 +24,18 @@ import com.intellij.openapi.components.StateStorageOperation import com.intellij.openapi.components.impl.BasePathMacroManager import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil import com.intellij.openapi.diagnostic.runAndLogException -import com.intellij.openapi.util.JDOMUtil import com.intellij.openapi.util.NamedJDOMExternalizable import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VfsUtil import com.intellij.util.io.delete import com.intellij.util.io.outputStream +import com.intellij.util.write import org.jdom.Element private class ApplicationPathMacroManager : BasePathMacroManager(null) const val APP_CONFIG = "\$APP_CONFIG$" +private val FILE_STORAGE_DIR = "options" class ApplicationStoreImpl(private val application: Application, pathMacroManager: PathMacroManager? = null) : ComponentStoreImpl() { override val storageManager = ApplicationStorageManager(application, pathMacroManager) @@ -45,7 +46,7 @@ class ApplicationStoreImpl(private val application: Application, pathMacroManage override fun setPath(path: String) { // app config must be first, because collapseMacros collapse from fist to last, so, at first we must replace APP_CONFIG because it overlaps ROOT_CONFIG value - storageManager.addMacro(APP_CONFIG, "$path/${ApplicationStorageManager.FILE_STORAGE_DIR}") + storageManager.addMacro(APP_CONFIG, "$path/${FILE_STORAGE_DIR}") storageManager.addMacro(ROOT_CONFIG, path) val configDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(path) @@ -54,7 +55,7 @@ class ApplicationStoreImpl(private val application: Application, pathMacroManage // not recursive, config directory contains various data - for example, ICS or shelf should not be refreshed, // but we refresh direct children to avoid refreshAndFindFile in SchemeManager (to find schemes directory) VfsUtil.markDirtyAndRefresh(false, false, true, configDir) - val optionsDir = configDir.findChild(ApplicationStorageManager.FILE_STORAGE_DIR) + val optionsDir = configDir.findChild(FILE_STORAGE_DIR) if (optionsDir != null) { // not recursive, options directory contains only files VfsUtil.markDirtyAndRefresh(false, false, true, optionsDir) @@ -68,7 +69,6 @@ class ApplicationStorageManager(application: Application, pathMacroManager: Path companion object { private val DEFAULT_STORAGE_SPEC = "${PathManager.DEFAULT_OPTIONS_FILE_NAME}${FileStorageCoreUtil.DEFAULT_EXT}" - val FILE_STORAGE_DIR = "options" } override fun getOldStorageSpec(component: Any, componentName: String, operation: StateStorageOperation): String? { @@ -96,7 +96,7 @@ class ApplicationStorageManager(application: Application, pathMacroManager: Path storage.file.delete() } else { - JDOMUtil.writeElement(element, storage.file.outputStream().writer(), "\n") + element.write(storage.file.outputStream()) } } } diff --git a/platform/configuration-store-impl/testSrc/xml/XmlSerializerWithDefaultJDOMExternalizerCompatibilityTest.java b/platform/configuration-store-impl/testSrc/xml/XmlSerializerWithDefaultJDOMExternalizerCompatibilityTest.java index b275f21bcefb..04ab5de4a758 100644 --- a/platform/configuration-store-impl/testSrc/xml/XmlSerializerWithDefaultJDOMExternalizerCompatibilityTest.java +++ b/platform/configuration-store-impl/testSrc/xml/XmlSerializerWithDefaultJDOMExternalizerCompatibilityTest.java @@ -21,9 +21,7 @@ public class XmlSerializerWithDefaultJDOMExternalizerCompatibilityTest extends T private static String serializeWithXmlSerializer(final Object data) throws Exception { Element element = serialize(data); - - String s = JDOMUtil.writeElement(element, "\n"); - return StringUtil.trimStart(s, "").trim(); + return StringUtil.trimStart(JDOMUtil.writeElement(element), "").trim(); } private static String serializeWithJDom(final Object data) throws Exception { diff --git a/platform/credential-store/src/kdbx/kdbx.kt b/platform/credential-store/src/kdbx/kdbx.kt index ecc98cdb41aa..ac7478d8232d 100644 --- a/platform/credential-store/src/kdbx/kdbx.kt +++ b/platform/credential-store/src/kdbx/kdbx.kt @@ -15,10 +15,10 @@ */ package com.intellij.credentialStore.kdbx -import com.intellij.openapi.util.JDOMUtil import com.intellij.util.SmartList import com.intellij.util.io.inputStreamIfExists import com.intellij.util.loadElement +import com.intellij.util.write import org.bouncycastle.crypto.engines.Salsa20Engine import org.bouncycastle.crypto.params.KeyParameter import org.bouncycastle.crypto.params.ParametersWithIV @@ -82,7 +82,7 @@ internal fun save(rootElement: Element, outputStream: OutputStream, encryption: } } } - JDOMUtil.writeElement(rootElement, outputStream.writer(), "\n") + rootElement.write(outputStream) } private fun load(inputStream: InputStream, encryption: KdbxEncryption): Element { diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java index 669e455aefdb..e92ae04de3cc 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -254,7 +254,7 @@ public class DefaultInspectionToolPresentation implements ProblemDescriptionsPro private synchronized void writeOutput(@NotNull final CommonProblemDescriptor[] descriptions, @NotNull RefEntity refElement) { final Element parentNode = new Element(InspectionsBundle.message("inspection.problems")); exportResults(descriptions, refElement, parentNode, d -> false); - final List list = parentNode.getChildren(); + final List list = parentNode.getChildren(); @NonNls final String ext = ".xml"; final String fileName = ourOutputPath + File.separator + myToolWrapper.getShortName() + ext; @@ -263,13 +263,12 @@ public class DefaultInspectionToolPresentation implements ProblemDescriptionsPro try { new File(ourOutputPath).mkdirs(); final File file = new File(fileName); - final CharArrayWriter writer = new CharArrayWriter(); + final StringWriter writer = new StringWriter(); if (!file.exists()) { writer.append("<").append(InspectionsBundle.message("inspection.problems")).append(" " + GlobalInspectionContextBase.LOCAL_TOOL_ATTRIBUTE + "=\"") .append(Boolean.toString(myToolWrapper instanceof LocalInspectionToolWrapper)).append("\">\n"); } - for (Object o : list) { - final Element element = (Element)o; + for (Element element : list) { pathMacroManager.collapsePaths(element); JDOMUtil.writeElement(element, writer, "\n"); } diff --git a/platform/projectModel-api/src/com/intellij/util/jdom.kt b/platform/projectModel-api/src/com/intellij/util/jdom.kt index 36d3ce53ba51..4aeb381180ef 100644 --- a/platform/projectModel-api/src/com/intellij/util/jdom.kt +++ b/platform/projectModel-api/src/com/intellij/util/jdom.kt @@ -62,8 +62,18 @@ private fun getSaxBuilder(): SAXBuilder { @JvmOverloads @Throws(IOException::class) fun Parent.write(file: Path, lineSeparator: String = "\n") { - BufferedOutputStream(file.outputStream()).use { - JDOMUtil.write(this, it, lineSeparator) + write(file.outputStream(), lineSeparator) +} + +@JvmOverloads +fun Parent.write(output: OutputStream, lineSeparator: String = "\n") { + output.bufferedWriter().use { writer -> + if (this is Document) { + JDOMUtil.writeDocument(this, writer, lineSeparator) + } + else { + JDOMUtil.writeElement(this as Element, writer, lineSeparator) + } } } diff --git a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/DefaultStateSerializer.java b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/DefaultStateSerializer.java index 9ee43a18b615..749eadb74f6d 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/DefaultStateSerializer.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/DefaultStateSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -41,7 +41,7 @@ public class DefaultStateSerializer { } else if (JDOMExternalizable.class.isAssignableFrom(stateClass)) { if (mergeInto != null) { - String elementText = JDOMUtil.writeElement(stateElement, "\n"); + String elementText = JDOMUtil.writeElement(stateElement); LOG.error("State is " + stateClass.getName() + ", merge into is " + mergeInto.toString() + ", state element text is " + elementText); } diff --git a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java index 747dc5ca5a39..f6b291297288 100644 --- a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java @@ -105,7 +105,7 @@ public abstract class UsefulTestCase extends TestCase { CodeInsightSettings defaultSettings = new CodeInsightSettings(); Element oldS = new Element("temp"); defaultSettings.writeExternal(oldS); - DEFAULT_SETTINGS_EXTERNALIZED = JDOMUtil.writeElement(oldS, "\n"); + DEFAULT_SETTINGS_EXTERNALIZED = JDOMUtil.writeElement(oldS); } catch (Exception e) { throw new RuntimeException(e); @@ -258,7 +258,7 @@ public abstract class UsefulTestCase extends TestCase { try { Element newS = new Element("temp"); settings.writeExternal(newS); - Assert.assertEquals("Code insight settings damaged", DEFAULT_SETTINGS_EXTERNALIZED, JDOMUtil.writeElement(newS, "\n")); + Assert.assertEquals("Code insight settings damaged", DEFAULT_SETTINGS_EXTERNALIZED, JDOMUtil.writeElement(newS)); } catch (AssertionError error) { CodeInsightSettings clean = new CodeInsightSettings(); @@ -808,8 +808,8 @@ public abstract class UsefulTestCase extends TestCase { Element newS = new Element("temp"); settings.writeExternal(newS); - String newString = JDOMUtil.writeElement(newS, "\n"); - String oldString = JDOMUtil.writeElement(oldS, "\n"); + String newString = JDOMUtil.writeElement(newS); + String oldString = JDOMUtil.writeElement(oldS); Assert.assertEquals("Code style settings damaged", oldString, newString); } diff --git a/plugins/devkit/src/actions/ShowSerializedXmlAction.java b/plugins/devkit/src/actions/ShowSerializedXmlAction.java index 2999f2a32d4f..e9cd9e9e0d55 100644 --- a/plugins/devkit/src/actions/ShowSerializedXmlAction.java +++ b/plugins/devkit/src/actions/ShowSerializedXmlAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -135,7 +135,7 @@ public class ShowSerializedXmlAction extends DumbAwareAction { Messages.showErrorDialog(project, e.getMessage() + (cause != null ? ": " + cause.getMessage() : ""), CommonBundle.getErrorTitle()); return; } - final String text = JDOMUtil.writeElement(element, "\n"); + final String text = JDOMUtil.writeElement(element); Messages.showIdeaMessageDialog(project, text, "Serialized XML for '" + className + "'", new String[]{CommonBundle.getOkButtonText()}, 0, Messages.getInformationIcon(), null); }