External project storage — ensure that we remove external system attributes from module options if enabled

This commit is contained in:
Vladimir Krivosheev
2017-06-30 15:31:16 +02:00
parent 7b4228ac44
commit 56aacfeb3e
2 changed files with 23 additions and 2 deletions
@@ -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<ExternalOptionStateComponent>, ProjectModelElement {
class ExternalSystemModulePropertyManager(private val module: Module) : PersistentStateComponent<ExternalOptionStateComponent>, 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
@@ -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();
}
}