Skip to content

Commit

Permalink
chore(bulk-model-sync): fix detekt warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuster23 committed Jun 25, 2024
1 parent a57d64d commit 78d0bf5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import org.modelix.model.api.ITree
import org.modelix.model.api.ITreeChangeVisitorEx
import org.modelix.model.data.NodeData

/**
* Visitor that visits a [tree] and stores the invalidation information in an [invalidationTree].
*/
class InvalidatingVisitor(val tree: ITree, val invalidationTree: InvalidationTree) : ITreeChangeVisitorEx {

private fun invalidateNode(nodeId: Long) = invalidationTree.invalidate(tree, nodeId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ class ModelSynchronizerWithInvalidationTreeTest : AbstractModelSyncTest() {
val rootNode = sourceBranch.getRootNode()
rootNode.setPropertyValue(IProperty.fromName(ID_PROPERTY_KEY), rootNode.reference.serialize())
val grower = RandomModelChangeGenerator(rootNode, rand).growingOperationsOnly()
for (i in 1..100) {
repeat(100) {
grower.applyRandomChange()
}

val changer = RandomModelChangeGenerator(rootNode, rand)
for (i in 1..numChanges) {
repeat(numChanges) {
changer.applyRandomChange()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import org.modelix.model.api.INode
import org.modelix.model.sync.bulk.ModelSynchronizer

/**
* A filter that skips nodes, which represent MPS modules and do not match the included module names or prefixes.
* A filter that skips nodes, which represent MPS modules and do not match
* the included module names ([includedModules]) or prefixes ([includedModulePrefixes]).
*
* Note: This is currently not meant to be used standalone.
* It should be used with other filters in a [CompositeFilter].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ object MPSBulkSynchronizer {
}
}

/**
* Import from model-server via [INode]-based [ModelSynchronizer].
* Requires a specified baseVersion.
*/
@JvmStatic
fun importRepositoryFromModelServer() {
val repository = getRepository()
Expand All @@ -220,22 +224,18 @@ object MPSBulkSynchronizer {
val branchName = System.getProperty("modelix.mps.model.sync.bulk.server.branch")
val branchRef = repositoryId.getBranchReference(branchName)
val versionHash: String? = System.getProperty("modelix.mps.model.sync.bulk.server.version.hash")
val baseVersionHash: String? = System.getProperty("modelix.mps.model.sync.bulk.server.version.base.hash")
val baseVersionHash = requireNotNull(System.getProperty("modelix.mps.model.sync.bulk.server.version.base.hash")) { "modelix.mps.model.sync.bulk.server.version.base.hash not specified" }
val client = ModelClientV2.builder().url(modelServerUrl).build()
val version = runBlocking {
if (versionHash == null) client.lazyLoadVersion(branchRef) else client.lazyLoadVersion(repositoryId, versionHash)
}
val baseVersion = baseVersionHash?.let {
runBlocking {
client.lazyLoadVersion(repositoryId, it)
}
val baseVersion = runBlocking {
client.lazyLoadVersion(repositoryId, baseVersionHash)
}
println("Loading version ${version.getContentHash()}")

val access = repository.modelAccess
access.executeCommandInEDT {
if (baseVersion == null) return@executeCommandInEDT

val invalidationTree = InvalidationTree(1_000_000)

Check warning

Code scanning / detekt

This expression contains a magic number. Consider defining it to a well named constant. Warning

This expression contains a magic number. Consider defining it to a well named constant.
val newTree = version.getTree()
newTree.visitChanges(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.modelix.model.data.NodeData
import org.modelix.model.mpsadapters.MPSArea
import org.modelix.model.sync.bulk.INodeAssociation

class NodeAssociationToModelServer(val branch: IBranch) : INodeAssociation {
internal class NodeAssociationToModelServer(val branch: IBranch) : INodeAssociation {

private val modelIndex
get() = ModelIndex.get(branch.transaction, NodeData.ID_PROPERTY_KEY)
Expand All @@ -42,7 +42,7 @@ class NodeAssociationToModelServer(val branch: IBranch) : INodeAssociation {
}
}

class NodeAssociationToMps(val mpsArea: MPSArea) : INodeAssociation {
internal class NodeAssociationToMps(val mpsArea: MPSArea) : INodeAssociation {

private val serverToMps: TLongObjectMap<INode> = TLongObjectHashMap()

Expand Down

0 comments on commit 78d0bf5

Please sign in to comment.