Skip to content

Commit bfffafe

Browse files
authored
Fix/minor binding fixes (#163)
* fix(mps-sync-plugin-lib): make the remove method calls in the MpsToModelixMap null-safe * feat(mps-sync-plugin): do not remove models and modules locally if we deactivate the bindings the reason for that is, the user may want to push these models/modules into other repositories too, after they disconnected from the previous model server / repository / branch.
1 parent 1e9c935 commit bfffafe

File tree

4 files changed

+5
-89
lines changed

4 files changed

+5
-89
lines changed

mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/bindings/ModelBinding.kt

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.modelix.mps.sync.bindings
1818

1919
import jetbrains.mps.extapi.model.SModelBase
20-
import jetbrains.mps.model.ModelDeleteHelper
2120
import mu.KotlinLogging
2221
import org.modelix.kotlin.utils.UnstableModelixFeature
2322
import org.modelix.model.api.IBranch
@@ -53,9 +52,6 @@ class ModelBinding(val model: SModelBase, branch: IBranch, serviceLocator: Servi
5352
@Volatile
5453
private var isActivated = false
5554

56-
@Volatile
57-
private var modelDeletedLocally = false
58-
5955
@Synchronized
6056
override fun activate(callback: Runnable?) {
6157
if (isDisposed || isActivated) {
@@ -101,30 +97,6 @@ class ModelBinding(val model: SModelBase, branch: IBranch, serviceLocator: Servi
10197
isActivated = false
10298
}
10399
}
104-
}.continueWith(linkedSetOf(SyncLock.MPS_WRITE), SyncDirection.MPS_TO_MODELIX) {
105-
synchronized(this) {
106-
try {
107-
// delete model
108-
if (!removeFromServer && !modelDeletedLocally) {
109-
/*
110-
* to delete the files locally, otherwise MPS takes care of calling
111-
* ModelDeleteHelper(model).delete() to delete the model (if removeFromServer is true)
112-
*/
113-
ModelDeleteHelper(model).delete()
114-
modelDeletedLocally = true
115-
}
116-
} catch (ex: Exception) {
117-
logger.error(ex) { "Exception occurred while deactivating ${name()}." }
118-
/*
119-
* if any error occurs, then we put the binding back to let the rest of the application know that
120-
* it exists
121-
*/
122-
bindingsRegistry.addModelBinding(this)
123-
activate()
124-
125-
throw ex
126-
}
127-
}
128100
}.continueWith(linkedSetOf(SyncLock.NONE), SyncDirection.NONE) {
129101
bindingsRegistry.removeModelBinding(model.module!!, this)
130102

mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/bindings/ModuleBinding.kt

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.modelix.mps.sync.bindings
1818

19-
import jetbrains.mps.module.ModuleDeleteHelper
2019
import jetbrains.mps.project.AbstractModule
2120
import mu.KotlinLogging
2221
import org.modelix.kotlin.utils.UnstableModelixFeature
@@ -44,7 +43,6 @@ class ModuleBinding(val module: AbstractModule, branch: IBranch, serviceLocator:
4443

4544
private val bindingsRegistry = serviceLocator.bindingsRegistry
4645
private val notifier = serviceLocator.wrappedNotifier
47-
private val mpsProject = serviceLocator.mpsProject
4846

4947
private val changeListener = ModuleChangeListener(branch, serviceLocator)
5048

@@ -54,9 +52,6 @@ class ModuleBinding(val module: AbstractModule, branch: IBranch, serviceLocator:
5452
@Volatile
5553
private var isActivated = false
5654

57-
@Volatile
58-
private var moduleDeletedLocally = false
59-
6055
@Synchronized
6156
override fun activate(callback: Runnable?) {
6257
if (isDisposed || isActivated) {
@@ -111,31 +106,6 @@ class ModuleBinding(val module: AbstractModule, branch: IBranch, serviceLocator:
111106
bindingsRegistry.removeModuleBinding(this)
112107
isActivated = false
113108
}
114-
}.continueWith(linkedSetOf(SyncLock.MPS_WRITE), SyncDirection.MPS_TO_MODELIX) {
115-
synchronized(this) {
116-
// delete module
117-
try {
118-
if (!removeFromServer && !moduleDeletedLocally) {
119-
/*
120-
* if we just delete it locally, then we have to call ModuleDeleteHelper manually.
121-
* otherwise, MPS will call us via the event-handler chain starting from
122-
* ModuleDeleteHelper.deleteModules --> RepositoryChangeListener -->
123-
* moduleListener.deactivate(removeFromServer = true)
124-
*/
125-
ModuleDeleteHelper(mpsProject).deleteModules(listOf(module), false, true)
126-
moduleDeletedLocally = true
127-
}
128-
} catch (ex: Exception) {
129-
logger.error(ex) { "Exception occurred while deactivating ${name()}." }
130-
/*
131-
* if any error occurs, then we put the binding back to let the rest of the application know that
132-
* it exists
133-
*/
134-
bindingsRegistry.addModuleBinding(this)
135-
activate()
136-
throw ex
137-
}
138-
}
139109
}.continueWith(linkedSetOf(SyncLock.NONE), SyncDirection.NONE) {
140110
nodeMap.remove(module)
141111

mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/transformation/cache/MpsToModelixMap.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,13 @@ class MpsToModelixMap : InjectableService {
174174

175175
modelixIdToModel.remove(modelixId)?.let {
176176
modelToModelixId.remove(it)
177-
178-
val model = it.resolve(mpsRepository)
179-
remove(model)
177+
it.resolve(mpsRepository)?.let { model -> remove(model) }
180178
}
181179

182180
modelixIdToModelWithOutgoingModelReference[modelixId]?.let { remove(it) }
183181
modelixIdToModelWithOutgoingModuleReference[modelixId]?.let { remove(it) }
184182

185-
modelixIdToModule.remove(modelixId)?.let {
186-
val module = it.resolve(mpsRepository)!!
187-
remove(module)
188-
}
183+
modelixIdToModule.remove(modelixId)?.let { it.resolve(mpsRepository)?.let { module -> remove(module) } }
189184
modelixIdToModuleWithOutgoingModuleReference[modelixId]?.let { remove(it) }
190185
}
191186

@@ -219,8 +214,7 @@ class MpsToModelixMap : InjectableService {
219214
val target = ModuleWithModuleReference(module, it)
220215
remove(target)
221216
} else if (it is SModelReference) {
222-
val model = it.resolve(mpsRepository)
223-
remove(model)
217+
it.resolve(mpsRepository)?.let { model -> remove(model) }
224218
}
225219
}
226220
}

mps-sync-plugin/src/main/kotlin/org/modelix/mps/sync/plugin/gui/ModelSyncGuiFactory.kt

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ class ModelSyncGuiFactory : ToolWindowFactory {
8181
companion object {
8282
private const val COMBOBOX_CHANGED_COMMAND = "comboBoxChanged"
8383
private const val TEXTFIELD_WIDTH = 20
84-
private const val DISCONNECT_REMOVES_LOCAL_COPIES =
85-
"By disconnecting, the synchronized modules and models will be removed locally."
8684
}
8785

8886
private val logger = KotlinLogging.logger {}
@@ -365,16 +363,7 @@ class ModelSyncGuiFactory : ToolWindowFactory {
365363
}
366364

367365
if (connectionsModel.size > 0) {
368-
if (bindingsModel.size == 0) {
369-
disconnectAction()
370-
return
371-
}
372-
373-
AlertNotifier(activeProject).warning(DISCONNECT_REMOVES_LOCAL_COPIES) { response ->
374-
if (UserResponse.USER_ACCEPTED == response) {
375-
disconnectAction()
376-
}
377-
}
366+
disconnectAction()
378367
}
379368
}
380369

@@ -392,16 +381,7 @@ class ModelSyncGuiFactory : ToolWindowFactory {
392381
}
393382

394383
if (activeBranch != null) {
395-
if (bindingsModel.size == 0) {
396-
disconnectAction()
397-
return
398-
}
399-
400-
AlertNotifier(activeProject).warning(DISCONNECT_REMOVES_LOCAL_COPIES) { response ->
401-
if (UserResponse.USER_ACCEPTED == response) {
402-
disconnectAction()
403-
}
404-
}
384+
disconnectAction()
405385
}
406386
}
407387

0 commit comments

Comments
 (0)