diff --git a/platform/configuration-store-impl/src/ProjectStoreImpl.kt b/platform/configuration-store-impl/src/ProjectStoreImpl.kt index f79c44a8e189..125706b89d3d 100644 --- a/platform/configuration-store-impl/src/ProjectStoreImpl.kt +++ b/platform/configuration-store-impl/src/ProjectStoreImpl.kt @@ -97,9 +97,7 @@ abstract class ProjectStoreBase(final override val project: Project) : Component normalizeDefaultProjectElement(defaultProject, element, Paths.get(storageManager.expandMacro(PROJECT_CONFIG_DIR))) } else { - LOG.runAndLogException { - moveComponentConfiguration(defaultProject, element) { if (it == "workspace.xml") Paths.get(workspaceFilePath) else Paths.get(projectFilePath) } - } + moveComponentConfiguration(defaultProject, element) { if (it == "workspace.xml") Paths.get(workspaceFilePath) else Paths.get(projectFilePath) } } } (storageManager.getOrCreateStorage(PROJECT_FILE) as XmlElementStorage).setDefaultState(element) diff --git a/platform/configuration-store-impl/src/defaultProjectElementNormalizer.kt b/platform/configuration-store-impl/src/defaultProjectElementNormalizer.kt index edae243866e8..e7404fe138e0 100644 --- a/platform/configuration-store-impl/src/defaultProjectElementNormalizer.kt +++ b/platform/configuration-store-impl/src/defaultProjectElementNormalizer.kt @@ -21,53 +21,54 @@ import java.nio.file.Path internal fun normalizeDefaultProjectElement(defaultProject: Project, element: Element, projectConfigDir: Path) { LOG.runAndLogException { - moveComponentConfiguration(defaultProject, element) { projectConfigDir.resolve(it)} + moveComponentConfiguration(defaultProject, element) { projectConfigDir.resolve(it) } } - LOG.runAndLogException { - val iterator = element.getChildren("component").iterator() - for (component in iterator) { - val componentName = component.getAttributeValue("name") + val iterator = element.getChildren("component").iterator() + for (component in iterator) { + val componentName = component.getAttributeValue("name") - fun writeProfileSettings(schemeDir: Path) { - component.removeAttribute("name") - if (!component.isEmpty()) { - val wrapper = Element("component").setAttribute("name", componentName) - component.name = "settings" - wrapper.addContent(component) - - val file = schemeDir.resolve("profiles_settings.xml") - if (file.fileSystem == FileSystems.getDefault()) { - // VFS must be used to write workspace.xml and misc.xml to ensure that project files will be not reloaded on external file change event - writeFile(file, fakeSaveSession, null, createDataWriterForElement(wrapper, "default project"), LineSeparator.LF, prependXmlProlog = false) - } - else { - file.outputStream().use { - wrapper.write(it) - } - } - } + fun writeProfileSettings(schemeDir: Path) { + component.removeAttribute("name") + if (component.isEmpty()) { + return } - when (componentName) { - "InspectionProjectProfileManager" -> { - iterator.remove() - val schemeDir = projectConfigDir.resolve("inspectionProfiles") - convertProfiles(component.getChildren("profile").iterator(), componentName, schemeDir) - component.removeChild("version") - writeProfileSettings(schemeDir) - } + val wrapper = Element("component").setAttribute("name", componentName) + component.name = "settings" + wrapper.addContent(component) - "CopyrightManager" -> { - iterator.remove() - val schemeDir = projectConfigDir.resolve("copyright") - convertProfiles(component.getChildren("copyright").iterator(), componentName, schemeDir) - writeProfileSettings(schemeDir) + val file = schemeDir.resolve("profiles_settings.xml") + if (file.fileSystem == FileSystems.getDefault()) { + // VFS must be used to write workspace.xml and misc.xml to ensure that project files will be not reloaded on external file change event + writeFile(file, fakeSaveSession, null, createDataWriterForElement(wrapper, "default project"), LineSeparator.LF, + prependXmlProlog = false) + } + else { + file.outputStream().use { + wrapper.write(it) } + } + } - ModuleManagerImpl.COMPONENT_NAME -> { - iterator.remove() - } + when (componentName) { + "InspectionProjectProfileManager" -> { + iterator.remove() + val schemeDir = projectConfigDir.resolve("inspectionProfiles") + convertProfiles(component.getChildren("profile").iterator(), componentName, schemeDir) + component.removeChild("version") + writeProfileSettings(schemeDir) + } + + "CopyrightManager" -> { + iterator.remove() + val schemeDir = projectConfigDir.resolve("copyright") + convertProfiles(component.getChildren("copyright").iterator(), componentName, schemeDir) + writeProfileSettings(schemeDir) + } + + ModuleManagerImpl.COMPONENT_NAME -> { + iterator.remove() } } } diff --git a/platform/projectModel-api/src/com/intellij/util/jdom.kt b/platform/projectModel-api/src/com/intellij/util/jdom.kt index 428eb881c82a..34c5b1c2247c 100644 --- a/platform/projectModel-api/src/com/intellij/util/jdom.kt +++ b/platform/projectModel-api/src/com/intellij/util/jdom.kt @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2019 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.util import com.intellij.openapi.util.JDOMUtil @@ -54,7 +54,7 @@ fun loadElement(stream: InputStream): Element = JDOMUtil.load(stream) @Throws(IOException::class, JDOMException::class) fun loadElement(path: Path): Element = JDOMUtil.load(path.inputStream()) -fun Element?.isEmpty(): Boolean = this == null || JDOMUtil.isEmpty(this) +fun Element?.isEmpty() = this == null || JDOMUtil.isEmpty(this) fun Element.getOrCreate(name: String): Element { var element = getChild(name)