@@ -35,7 +35,6 @@ import kotlinx.serialization.json.Json
35
35
import kotlinx.serialization.json.decodeFromStream
36
36
import org.jetbrains.annotations.VisibleForTesting
37
37
import org.jetbrains.mps.openapi.model.EditableSModel
38
- import org.jetbrains.mps.openapi.module.ModelAccess
39
38
import org.jetbrains.mps.openapi.module.SModule
40
39
import org.jetbrains.mps.openapi.module.SRepository
41
40
import org.modelix.model.api.INode
@@ -195,40 +194,34 @@ object MPSBulkSynchronizer {
195
194
continueOnError : Boolean ,
196
195
getModulesToImport : () -> Sequence <ExistingAndExpectedNode >,
197
196
) {
198
- val access = repository.modelAccess
199
- ThreadUtils .runInUIThreadAndWait {
200
- access.executeCommand {
201
- println (" Importing modules..." )
202
- try {
203
- println (" Importing modules..." )
204
- // `modulesToImport` lazily produces modules to import
205
- // so that loaded model data can be garbage collected.
206
- val modulesToImport = getModulesToImport()
207
- ModelImporter (rootOfImport, continueOnError).importIntoNodes(modulesToImport)
208
- println (" Import finished." )
209
- } catch (ex: Exception ) {
210
- // Exceptions are only visible in the MPS log file by default
211
- ex.printStackTrace()
212
- }
213
- println (" Import finished." )
214
- }
197
+ executeCommandWithExceptionHandling(repository) {
198
+ println (" Importing modules..." )
199
+ // `modulesToImport` lazily produces modules to import
200
+ // so that loaded model data can be garbage collected.
201
+ val modulesToImport = getModulesToImport()
202
+ ModelImporter (rootOfImport, continueOnError).importIntoNodes(modulesToImport)
203
+ println (" Import finished." )
215
204
}
216
205
217
- persistChanges(access, repository)
206
+ persistChanges(repository)
218
207
}
219
208
220
- private fun persistChanges (
221
- access : ModelAccess ,
222
- repository : SRepository ,
223
- ) {
224
- ThreadUtils .runInUIThreadAndWait {
225
- println (" Persisting changes..." )
226
- access.executeCommand {
227
- enableWorkaroundForFilePerRootPersistence(repository)
228
- updateUnsetResolveInfo(repository)
229
- repository.saveAll()
209
+ private fun persistChanges (repository : SRepository ) = executeCommandWithExceptionHandling(repository) {
210
+ println (" Persisting changes..." )
211
+ enableWorkaroundForFilePerRootPersistence(repository)
212
+ updateUnsetResolveInfo(repository)
213
+ repository.saveAll()
214
+ println (" Changes persisted." )
215
+ }
216
+
217
+ private fun executeCommandWithExceptionHandling (repository : SRepository , block : () -> Unit ) {
218
+ val exception = ThreadUtils .runInUIThreadAndWait {
219
+ repository.modelAccess.executeCommand {
220
+ block()
230
221
}
231
- println (" Changes persisted." )
222
+ }
223
+ if (exception != null ) {
224
+ throw exception
232
225
}
233
226
}
234
227
@@ -242,7 +235,6 @@ object MPSBulkSynchronizer {
242
235
243
236
val includedModuleNames = parseRawPropertySet(System .getProperty(" modelix.mps.model.sync.bulk.input.modules" ))
244
237
val includedModulePrefixes = parseRawPropertySet(System .getProperty(" modelix.mps.model.sync.bulk.input.modules.prefixes" ))
245
- val continueOnError = System .getProperty(" modelix.mps.model.sync.bulk.input.continueOnError" , " false" ).toBoolean()
246
238
247
239
val includedModulesFilter = IncludedModulesFilter (includedModuleNames, includedModulePrefixes)
248
240
@@ -261,8 +253,7 @@ object MPSBulkSynchronizer {
261
253
}
262
254
println (" Loading version ${version.getContentHash()} " )
263
255
264
- val access = repository.modelAccess
265
- access.executeCommandInEDT {
256
+ executeCommandWithExceptionHandling(repository) {
266
257
val invalidationTree = InvalidationTree (1_000_000 )
267
258
val newTree = version.getTree()
268
259
newTree.visitChanges(
@@ -277,17 +268,11 @@ object MPSBulkSynchronizer {
277
268
MPSRepositoryAsNode (repository),
278
269
NodeAssociationToMps (MPSArea (repository)),
279
270
)
280
- try {
281
- synchronizer.synchronize()
282
- } catch (e: Exception ) {
283
- // Exceptions are only visible in the MPS log file by default
284
- e.printStackTrace()
285
- throw e
286
- }
271
+ synchronizer.synchronize()
287
272
}
288
273
}
289
274
println (" Import finished." )
290
- persistChanges(access, repository)
275
+ persistChanges(repository)
291
276
}
292
277
293
278
/* *
0 commit comments