diff --git a/platform/configuration-store-impl/src/ExportSettingsAction.kt b/platform/configuration-store-impl/src/ExportSettingsAction.kt index d3e02082de94..0a30030bfa11 100644 --- a/platform/configuration-store-impl/src/ExportSettingsAction.kt +++ b/platform/configuration-store-impl/src/ExportSettingsAction.kt @@ -167,7 +167,6 @@ fun getExportableComponentsMap(onlyExisting: Boolean, } } - @Suppress("DEPRECATION") (ApplicationManager.getApplication() as ComponentManagerEx).getComponentInstancesOfType(ExportableApplicationComponent::class.java).forEach(processor) ServiceBean.loadServicesFromBeans(ExportableComponent.EXTENSION_POINT, ExportableComponent::class.java).forEach(processor) diff --git a/platform/configuration-store-impl/src/ProjectStoreImpl.kt b/platform/configuration-store-impl/src/ProjectStoreImpl.kt index e7a75bf87f87..69f51ce7e7ea 100644 --- a/platform/configuration-store-impl/src/ProjectStoreImpl.kt +++ b/platform/configuration-store-impl/src/ProjectStoreImpl.kt @@ -24,8 +24,11 @@ import com.intellij.openapi.application.invokeAndWaitIfNeed import com.intellij.openapi.application.runReadAction import com.intellij.openapi.components.* import com.intellij.openapi.components.StateStorage.SaveSession +import com.intellij.openapi.components.ex.ComponentManagerEx import com.intellij.openapi.components.impl.stores.IComponentStore import com.intellij.openapi.components.impl.stores.IProjectStore +import com.intellij.openapi.components.impl.stores.StoreUtil +import com.intellij.openapi.diagnostic.catchAndLog import com.intellij.openapi.module.Module import com.intellij.openapi.module.ModuleManager import com.intellij.openapi.project.Project @@ -40,8 +43,10 @@ import com.intellij.openapi.vfs.ReadonlyStatusHandler import com.intellij.openapi.vfs.VfsUtil import com.intellij.openapi.vfs.VirtualFile import com.intellij.util.* +import com.intellij.util.containers.forEachGuaranteed import com.intellij.util.containers.isNullOrEmpty import com.intellij.util.lang.CompoundRuntimeException +import org.jdom.Element import java.io.File import java.io.IOException import java.nio.file.Path @@ -90,10 +95,11 @@ abstract class ProjectStoreBase(override final val project: ProjectImpl) : Compo override final fun loadProjectFromTemplate(defaultProject: Project) { defaultProject.save() - val element = (defaultProject.stateStore as DefaultProjectStoreImpl).getStateCopy() - if (element != null) { - (storageManager.getOrCreateStorage(PROJECT_FILE) as XmlElementStorage).setDefaultState(element) + val element = (defaultProject.stateStore as DefaultProjectStoreImpl).getStateCopy() ?: return + LOG.catchAndLog { + removeWorkspaceComponentConfiguration(defaultProject, element) } + (storageManager.getOrCreateStorage(PROJECT_FILE) as XmlElementStorage).setDefaultState(element) } override final fun getProjectBasePath(): String { @@ -373,4 +379,34 @@ private fun useOldWorkspaceContent(filePath: String, ws: File) { catch (e: IOException) { LOG.error(e) } +} + +// public only to test +fun removeWorkspaceComponentConfiguration(defaultProject: Project, element: Element) { + val componentElements = element.getChildren("component") + if (componentElements.isEmpty()) { + return + } + + val projectComponents = (defaultProject as ComponentManagerEx).getComponentInstancesOfType(PersistentStateComponent::class.java) + projectComponents.forEachGuaranteed { + val stateAnnotation = StoreUtil.getStateSpec(it.javaClass) + if (stateAnnotation == null || stateAnnotation.name.isNullOrEmpty()) { + return@forEachGuaranteed + } + + val storage = stateAnnotation.storages.sortByDeprecated().firstOrNull() ?: return@forEachGuaranteed + if (storage.path != StoragePathMacros.WORKSPACE_FILE) { + return@forEachGuaranteed + } + + val iterator = componentElements.iterator() + for (componentElement in iterator) { + if (componentElement.getAttributeValue("name") == stateAnnotation.name) { + iterator.remove() + break + } + } + } + return } \ No newline at end of file diff --git a/platform/configuration-store-impl/testSrc/DefaultProjectStoreTest.kt b/platform/configuration-store-impl/testSrc/DefaultProjectStoreTest.kt index c7f023ac46a4..9468b817e5a3 100644 --- a/platform/configuration-store-impl/testSrc/DefaultProjectStoreTest.kt +++ b/platform/configuration-store-impl/testSrc/DefaultProjectStoreTest.kt @@ -10,10 +10,7 @@ import com.intellij.openapi.project.ProjectManager import com.intellij.openapi.util.JDOMUtil import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.testFramework.* -import com.intellij.util.delete -import com.intellij.util.loadElement -import com.intellij.util.refreshVfs -import com.intellij.util.systemIndependentPath +import com.intellij.util.* import org.assertj.core.api.Assertions.assertThat import org.jdom.Element import org.junit.ClassRule @@ -24,7 +21,8 @@ import java.nio.file.Paths internal class DefaultProjectStoreTest { companion object { @JvmField - @ClassRule val projectRule = ProjectRule() + @ClassRule + val projectRule = ProjectRule() internal const val TEST_COMPONENT_NAME = "Foo" @@ -100,4 +98,13 @@ internal class DefaultProjectStoreTest { stateStore.removeComponent(TEST_COMPONENT_NAME) } } + + @Test fun `new project from default - remove workspace component configuration`() { + val element = loadElement(""" + + + """) + removeWorkspaceComponentConfiguration(ProjectManager.getInstance().defaultProject, element) + assertThat(element.isEmpty()).isTrue() + } } \ No newline at end of file diff --git a/platform/core-impl/src/com/intellij/openapi/components/ex/ComponentManagerEx.java b/platform/core-impl/src/com/intellij/openapi/components/ex/ComponentManagerEx.java index a50c1810dcb6..ef6436d08561 100644 --- a/platform/core-impl/src/com/intellij/openapi/components/ex/ComponentManagerEx.java +++ b/platform/core-impl/src/com/intellij/openapi/components/ex/ComponentManagerEx.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -29,8 +29,7 @@ public interface ComponentManagerEx extends ComponentManager { /** * Gets all components whose implementation class is derived from baseClass. * - * @return array of components - * @deprecated use extension points instead + * Consider using extension points instead. */ @NotNull List getComponentInstancesOfType(@NotNull Class baseClass); diff --git a/platform/platform-resources/src/componentSets/VCS.xml b/platform/platform-resources/src/componentSets/VCS.xml index fb451366bb6e..f10fbf8dd992 100644 --- a/platform/platform-resources/src/componentSets/VCS.xml +++ b/platform/platform-resources/src/componentSets/VCS.xml @@ -17,7 +17,6 @@ com.intellij.openapi.vcs.ProjectLevelVcsManager com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl -