cleanup — do not pass lineSeparator explicitly (defaults to \n)

This commit is contained in:
Vladimir Krivosheev
2017-05-19 17:32:59 +02:00
parent 8ed8a21668
commit 644960f8b8
8 changed files with 32 additions and 25 deletions
@@ -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())
}
}
}
@@ -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, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>").trim();
return StringUtil.trimStart(JDOMUtil.writeElement(element), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>").trim();
}
private static String serializeWithJDom(final Object data) throws Exception {
+2 -2
View File
@@ -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 {
@@ -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<Element> 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");
}
@@ -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)
}
}
}
@@ -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);
}
@@ -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);
}
@@ -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);
}