From 56aacfeb3ec34198437f87ededd16b5b359c2520 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 30 Jun 2017 15:20:12 +0200 Subject: [PATCH] =?UTF-8?q?External=20project=20storage=20=E2=80=94=20ensu?= =?UTF-8?q?re=20that=20we=20remove=20external=20system=20attributes=20from?= =?UTF-8?q?=20module=20options=20if=20enabled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExternalSystemModulePropertyManager.kt | 23 +++++++++++++++++-- .../manage/ExternalProjectsManagerImpl.java | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/ExternalSystemModulePropertyManager.kt b/platform/external-system-api/src/com/intellij/openapi/externalSystem/ExternalSystemModulePropertyManager.kt index 20405cf42062..8679bce98384 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/ExternalSystemModulePropertyManager.kt +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/ExternalSystemModulePropertyManager.kt @@ -30,14 +30,16 @@ import com.intellij.util.xmlb.annotations.Transient import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty +val EMPTY_STATE = ExternalOptionStateComponent() + @Suppress("DEPRECATION") @State(name = "ExternalSystem") -class ExternalSystemModulePropertyManager(module: Module) : PersistentStateComponent, ProjectModelElement { +class ExternalSystemModulePropertyManager(private val module: Module) : PersistentStateComponent, ProjectModelElement { override fun getExternalSource() = store.externalSystem?.let { ExternalProjectSystemRegistry.getInstance().getSourceById(it) } private var store = if (module.project.isExternalStorageEnabled) ExternalOptionStateComponent() else ExternalOptionStateModule(module) - override fun getState() = store as? ExternalOptionStateComponent + override fun getState() = store as? ExternalOptionStateComponent ?: EMPTY_STATE override fun loadState(state: ExternalOptionStateComponent) { store = state @@ -77,6 +79,23 @@ class ExternalSystemModulePropertyManager(module: Module) : PersistentStateCompo store.isMavenized = mavenized } + fun swapStore() { + val oldStore = store + if (oldStore is ExternalOptionStateModule) { + store = ExternalOptionStateComponent() + } + else { + store = ExternalOptionStateModule(module) + } + + store.externalSystem = oldStore.externalSystem + store.linkedProjectId = oldStore.linkedProjectId + store.linkedProjectPath = oldStore.linkedProjectPath + store.rootProjectPath = oldStore.rootProjectPath + store.externalSystemModuleGroup = oldStore.externalSystemModuleGroup + store.externalSystemModuleVersion = oldStore.externalSystemModuleVersion + } + fun unlinkExternalOptions() { store.externalSystem = null store.linkedProjectId = null diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsManagerImpl.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsManagerImpl.java index 993995985eb7..68ca6e395976 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsManagerImpl.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsManagerImpl.java @@ -20,6 +20,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.externalSystem.ExternalSystemManager; +import com.intellij.openapi.externalSystem.ExternalSystemModulePropertyManager; import com.intellij.openapi.externalSystem.importing.ImportSpec; import com.intellij.openapi.externalSystem.model.DataNode; import com.intellij.openapi.externalSystem.model.ExternalProjectInfo; @@ -102,6 +103,7 @@ public class ExternalProjectsManagerImpl implements ExternalProjectsManager, Per try { for (Module module : ModuleManager.getInstance(myProject).getModules()) { if (!module.isDisposed()) { + ExternalSystemModulePropertyManager.getInstance(module).swapStore(); ((ModuleRootManagerImpl)ModuleRootManager.getInstance(module)).stateChanged(); } }