Skip to content

Commit

Permalink
Merge pull request #265 from modelix/feature/bulk-sync-module-qol
Browse files Browse the repository at this point in the history
MODELIX-560 bulk-model-sync quality of life improvements
  • Loading branch information
mhuster23 authored Oct 9, 2023
2 parents d7b15d5 + cc1037e commit 01f9ed5
Show file tree
Hide file tree
Showing 7 changed files with 440 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class ModelSyncGradlePlugin : Plugin<Project> {
it.jsonDirPath.set(jsonDir.absolutePath)
it.exportFlag.set(true)
it.includedModules.set(syncDirection.includedModules)
it.includedModulePrefixes.set(syncDirection.includedModulePrefixes)
}

val exportFromMps = project.tasks.register("${syncDirection.name}ExportFromMps", ExportFromMps::class.java) {
Expand Down Expand Up @@ -198,7 +199,8 @@ class ModelSyncGradlePlugin : Plugin<Project> {
it.mpsDependenciesPath.set(getDependenciesDir(project).absolutePath)
it.jsonDirPath.set(jsonDir.absolutePath)
it.exportFlag.set(false)
it.includedModules.set(emptyList())
it.includedModules.set(syncDirection.includedModules)
it.includedModulePrefixes.set(syncDirection.includedModulePrefixes)
}

val importName = "${syncDirection.name}ImportIntoMps"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ data class SyncDirection(
internal var target: SyncEndpoint? = null,
internal val includedModules: Set<String> = mutableSetOf(),
internal val registeredLanguages: Set<ILanguage> = mutableSetOf(),
internal val includedModulePrefixes: Set<String> = mutableSetOf(),
) {
fun fromModelServer(action: Action<ServerSource>) {
val endpoint = ServerSource()
Expand Down Expand Up @@ -70,6 +71,10 @@ data class SyncDirection(
(includedModules as MutableSet).add(module)
}

fun includeModulesByPrefix(prefix: String) {
(includedModulePrefixes as MutableSet).add(prefix)
}

fun registerLanguage(language: ILanguage) {
(registeredLanguages as MutableSet).add(language)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ abstract class GenerateAntScriptForMps @Inject constructor(of: ObjectFactory) :
@Input
val includedModules: ListProperty<String> = of.listProperty(String::class.java)

@Input
val includedModulePrefixes: ListProperty<String> = of.listProperty(String::class.java)

@TaskAction
fun generate() {
val isExport = exportFlag.get()
Expand Down Expand Up @@ -99,6 +102,7 @@ abstract class GenerateAntScriptForMps @Inject constructor(of: ObjectFactory) :
<jvmargs>
<arg value="-Dmodelix.mps.model.sync.bulk.${if (isExport) "output" else "input"}.path=${jsonDirPath.get()}" />
<arg value="-Dmodelix.mps.model.sync.bulk.${if (isExport) "output" else "input"}.modules=${includedModules.get().joinToString(",")}" />
<arg value="-Dmodelix.mps.model.sync.bulk.${if (isExport) "output" else "input"}.modules.prefixes=${includedModulePrefixes.get().joinToString(",")}" />
<arg value="-Dmodelix.mps.model.sync.bulk.repo.path=${repositoryPath.get()}" />
<arg value="-Didea.config.path=${"$"}{build.mps.config.path}" />
<arg value="-Didea.system.path=${"$"}{build.mps.system.path}" />
Expand Down
1 change: 1 addition & 0 deletions bulk-model-sync-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ kotlin {
dependencies {
implementation(project(":model-api"))
implementation(libs.kotlin.serialization.json)
implementation(libs.kotlin.logging)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.modelix.model.sync.bulk

import mu.KotlinLogging
import org.modelix.model.api.ConceptReference
import org.modelix.model.api.INode
import org.modelix.model.api.INodeReference
Expand All @@ -41,6 +42,9 @@ class ModelImporter(private val root: INode) {
private val originalIdToExisting: MutableMap<String, INode> = mutableMapOf()
private val postponedReferences = ArrayList<() -> Unit>()
private val nodesToRemove = HashSet<INode>()
private var numExpectedNodes = 0
private var currentNodeProgress = 0
private val logger = KotlinLogging.logger {}

/**
* Incrementally updates this importers root based on the provided [ModelData] specification.
Expand All @@ -49,17 +53,34 @@ class ModelImporter(private val root: INode) {
*/
@JvmName("importData")
fun import(data: ModelData) {
logger.info { "Building indices for import..." }
originalIdToExisting.clear()
postponedReferences.clear()
nodesToRemove.clear()
numExpectedNodes = countExpectedNodes(data.root)
currentNodeProgress = 0
buildExistingIndex(root)

logger.info { "Importing nodes..." }
data.root.originalId()?.let { originalIdToExisting[it] = root }
syncNode(root, data.root)

logger.info { "Synchronizing references..." }
postponedReferences.forEach { it.invoke() }

logger.info { "Removing extra nodes..." }
nodesToRemove.forEach { it.remove() }

logger.info { "Synchronization finished." }
}

private fun countExpectedNodes(data: NodeData): Int =
1 + data.children.sumOf { countExpectedNodes(it) }

private fun syncNode(node: INode, data: NodeData) {
currentNodeProgress += 1
// print instead of log, so that the progress line can be overwritten by the carriage return
print("\r($currentNodeProgress / $numExpectedNodes) Synchronizing nodes... ")
syncProperties(node, data)
syncChildren(node, data)
syncReferences(node, data)
Expand Down
Loading

0 comments on commit 01f9ed5

Please sign in to comment.