Skip to content

Commit

Permalink
fix(bulk-model-sync-mps): do not import modules one by one
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuster23 committed Feb 19, 2024
1 parent 79af3d3 commit b81e08d
Showing 1 changed file with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package org.modelix.mps.model.sync.bulk
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.ProjectManager
import jetbrains.mps.ide.project.ProjectHelper
import org.jetbrains.mps.openapi.module.SModule
import org.jetbrains.mps.openapi.module.SRepository
import org.modelix.model.mpsadapters.MPSModuleAsNode
import org.modelix.model.mpsadapters.MPSRepositoryAsNode
import org.modelix.model.sync.bulk.ModelExporter
import org.modelix.model.sync.bulk.ModelImporter
import org.modelix.model.sync.bulk.import
import org.modelix.model.sync.bulk.importFilesAsRootChildren
import org.modelix.model.sync.bulk.isModuleIncluded
import java.io.File
import java.util.concurrent.atomic.AtomicInteger
Expand Down Expand Up @@ -66,33 +66,29 @@ object MPSBulkSynchronizer {
val includedModuleNames = parseRawPropertySet(System.getProperty("modelix.mps.model.sync.bulk.input.modules"))
val includedModulePrefixes = parseRawPropertySet(System.getProperty("modelix.mps.model.sync.bulk.input.modules.prefixes"))
val inputPath = System.getProperty("modelix.mps.model.sync.bulk.input.path")
val access = repository.modelAccess
val jsonFiles = File(inputPath).listFiles()?.filter {
it.extension == "json" && isModuleIncluded(it.nameWithoutExtension, includedModuleNames, includedModulePrefixes)
}

access.runWriteInEDT {
val allModules = repository.modules
val includedModules: Iterable<SModule> = allModules.filter {
isModuleIncluded(it.moduleName!!, includedModuleNames, includedModulePrefixes)
}
val numIncludedModules = includedModules.count()
if (jsonFiles.isNullOrEmpty()) error("no json files found for included modules")

println("Found ${jsonFiles.size} modules to be imported")
val access = repository.modelAccess
access.runWriteInEDT {
access.executeCommand {
for ((index, module) in includedModules.withIndex()) {
println("Importing module ${index + 1} of $numIncludedModules: '${module.moduleName}'")
val moduleFile = File(inputPath + File.separator + module.moduleName + ".json")
if (moduleFile.exists()) {
val importer = ModelImporter(
MPSModuleAsNode(module),
)
importer.import(moduleFile)
}
}
val repoAsNode = MPSRepositoryAsNode(repository)
println("Importing modules...")
ModelImporter(repoAsNode).importFilesAsRootChildren(jsonFiles)
println("Import finished.")
}
}

ApplicationManager.getApplication().invokeAndWait {
println("Persisting changes...")
repository.modelAccess.runWriteAction {
repository.saveAll()
}
println("Changes persisted.")
}
}

Expand Down

0 comments on commit b81e08d

Please sign in to comment.