Skip to content

Commit 01f9ed5

Browse files
authored
Merge pull request #265 from modelix/feature/bulk-sync-module-qol
MODELIX-560 bulk-model-sync quality of life improvements
2 parents d7b15d5 + cc1037e commit 01f9ed5

File tree

7 files changed

+440
-106
lines changed

7 files changed

+440
-106
lines changed

bulk-model-sync-gradle/src/main/kotlin/org/modelix/model/sync/bulk/gradle/ModelSyncGradlePlugin.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class ModelSyncGradlePlugin : Plugin<Project> {
134134
it.jsonDirPath.set(jsonDir.absolutePath)
135135
it.exportFlag.set(true)
136136
it.includedModules.set(syncDirection.includedModules)
137+
it.includedModulePrefixes.set(syncDirection.includedModulePrefixes)
137138
}
138139

139140
val exportFromMps = project.tasks.register("${syncDirection.name}ExportFromMps", ExportFromMps::class.java) {
@@ -198,7 +199,8 @@ class ModelSyncGradlePlugin : Plugin<Project> {
198199
it.mpsDependenciesPath.set(getDependenciesDir(project).absolutePath)
199200
it.jsonDirPath.set(jsonDir.absolutePath)
200201
it.exportFlag.set(false)
201-
it.includedModules.set(emptyList())
202+
it.includedModules.set(syncDirection.includedModules)
203+
it.includedModulePrefixes.set(syncDirection.includedModulePrefixes)
202204
}
203205

204206
val importName = "${syncDirection.name}ImportIntoMps"

bulk-model-sync-gradle/src/main/kotlin/org/modelix/model/sync/bulk/gradle/config/ModelSyncGradleSettings.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ data class SyncDirection(
4141
internal var target: SyncEndpoint? = null,
4242
internal val includedModules: Set<String> = mutableSetOf(),
4343
internal val registeredLanguages: Set<ILanguage> = mutableSetOf(),
44+
internal val includedModulePrefixes: Set<String> = mutableSetOf(),
4445
) {
4546
fun fromModelServer(action: Action<ServerSource>) {
4647
val endpoint = ServerSource()
@@ -70,6 +71,10 @@ data class SyncDirection(
7071
(includedModules as MutableSet).add(module)
7172
}
7273

74+
fun includeModulesByPrefix(prefix: String) {
75+
(includedModulePrefixes as MutableSet).add(prefix)
76+
}
77+
7378
fun registerLanguage(language: ILanguage) {
7479
(registeredLanguages as MutableSet).add(language)
7580
}

bulk-model-sync-gradle/src/main/kotlin/org/modelix/model/sync/bulk/gradle/tasks/GenerateAntScriptForMps.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ abstract class GenerateAntScriptForMps @Inject constructor(of: ObjectFactory) :
5656
@Input
5757
val includedModules: ListProperty<String> = of.listProperty(String::class.java)
5858

59+
@Input
60+
val includedModulePrefixes: ListProperty<String> = of.listProperty(String::class.java)
61+
5962
@TaskAction
6063
fun generate() {
6164
val isExport = exportFlag.get()
@@ -99,6 +102,7 @@ abstract class GenerateAntScriptForMps @Inject constructor(of: ObjectFactory) :
99102
<jvmargs>
100103
<arg value="-Dmodelix.mps.model.sync.bulk.${if (isExport) "output" else "input"}.path=${jsonDirPath.get()}" />
101104
<arg value="-Dmodelix.mps.model.sync.bulk.${if (isExport) "output" else "input"}.modules=${includedModules.get().joinToString(",")}" />
105+
<arg value="-Dmodelix.mps.model.sync.bulk.${if (isExport) "output" else "input"}.modules.prefixes=${includedModulePrefixes.get().joinToString(",")}" />
102106
<arg value="-Dmodelix.mps.model.sync.bulk.repo.path=${repositoryPath.get()}" />
103107
<arg value="-Didea.config.path=${"$"}{build.mps.config.path}" />
104108
<arg value="-Didea.system.path=${"$"}{build.mps.system.path}" />

bulk-model-sync-lib/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ kotlin {
2222
dependencies {
2323
implementation(project(":model-api"))
2424
implementation(libs.kotlin.serialization.json)
25+
implementation(libs.kotlin.logging)
2526
}
2627
}
2728

bulk-model-sync-lib/src/commonMain/kotlin/org/modelix/model/sync/bulk/ModelImporter.kt

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

1717
package org.modelix.model.sync.bulk
1818

19+
import mu.KotlinLogging
1920
import org.modelix.model.api.ConceptReference
2021
import org.modelix.model.api.INode
2122
import org.modelix.model.api.INodeReference
@@ -41,6 +42,9 @@ class ModelImporter(private val root: INode) {
4142
private val originalIdToExisting: MutableMap<String, INode> = mutableMapOf()
4243
private val postponedReferences = ArrayList<() -> Unit>()
4344
private val nodesToRemove = HashSet<INode>()
45+
private var numExpectedNodes = 0
46+
private var currentNodeProgress = 0
47+
private val logger = KotlinLogging.logger {}
4448

4549
/**
4650
* Incrementally updates this importers root based on the provided [ModelData] specification.
@@ -49,17 +53,34 @@ class ModelImporter(private val root: INode) {
4953
*/
5054
@JvmName("importData")
5155
fun import(data: ModelData) {
56+
logger.info { "Building indices for import..." }
5257
originalIdToExisting.clear()
5358
postponedReferences.clear()
5459
nodesToRemove.clear()
60+
numExpectedNodes = countExpectedNodes(data.root)
61+
currentNodeProgress = 0
5562
buildExistingIndex(root)
63+
64+
logger.info { "Importing nodes..." }
5665
data.root.originalId()?.let { originalIdToExisting[it] = root }
5766
syncNode(root, data.root)
67+
68+
logger.info { "Synchronizing references..." }
5869
postponedReferences.forEach { it.invoke() }
70+
71+
logger.info { "Removing extra nodes..." }
5972
nodesToRemove.forEach { it.remove() }
73+
74+
logger.info { "Synchronization finished." }
6075
}
6176

77+
private fun countExpectedNodes(data: NodeData): Int =
78+
1 + data.children.sumOf { countExpectedNodes(it) }
79+
6280
private fun syncNode(node: INode, data: NodeData) {
81+
currentNodeProgress += 1
82+
// print instead of log, so that the progress line can be overwritten by the carriage return
83+
print("\r($currentNodeProgress / $numExpectedNodes) Synchronizing nodes... ")
6384
syncProperties(node, data)
6485
syncChildren(node, data)
6586
syncReferences(node, data)

0 commit comments

Comments
 (0)