Skip to content

Commit 7009c7c

Browse files
author
Oleksandr Dzhychko
authored
Merge pull request #543 from modelix/fix/undiposed-ReplicatedModel-in-ExportFromModelServer
fix(bulk-model-sync): do not use undisposed replicated model
2 parents b226d94 + 92da0f6 commit 7009c7c

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

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

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@ import org.gradle.api.tasks.Input
2626
import org.gradle.api.tasks.Optional
2727
import org.gradle.api.tasks.OutputDirectory
2828
import org.gradle.api.tasks.TaskAction
29-
import org.modelix.model.ModelFacade
3029
import org.modelix.model.api.BuiltinLanguages
31-
import org.modelix.model.api.IBranch
3230
import org.modelix.model.api.INode
3331
import org.modelix.model.api.PBranch
3432
import org.modelix.model.api.getRootNode
35-
import org.modelix.model.client2.IModelClientV2
3633
import org.modelix.model.client2.ModelClientV2
3734
import org.modelix.model.client2.ModelClientV2PlatformSpecificBuilder
38-
import org.modelix.model.client2.getReplicatedModel
35+
import org.modelix.model.lazy.BranchReference
3936
import org.modelix.model.lazy.RepositoryId
4037
import org.modelix.model.sync.bulk.ModelExporter
4138
import org.modelix.model.sync.bulk.isModuleIncluded
@@ -71,21 +68,17 @@ abstract class ExportFromModelServer @Inject constructor(of: ObjectFactory) : De
7168
@Input
7269
val requestTimeoutSeconds: Property<Int> = of.property(Int::class.java)
7370

71+
private fun getBranchReference(): BranchReference = RepositoryId(repositoryId.get()).getBranchReference(branchName.get())
72+
7473
@TaskAction
75-
fun export() {
74+
fun export() = runBlocking {
7675
val modelClient = ModelClientV2PlatformSpecificBuilder()
7776
.url(url.get())
7877
.requestTimeout(requestTimeoutSeconds.get().seconds)
7978
.build()
8079
modelClient.use { client ->
81-
runBlocking { client.init() }
82-
83-
val branch = if (revision.isPresent) {
84-
getBranchByRevision(client)
85-
} else {
86-
getBranchByRepoIdAndBranch(client)
87-
}
88-
80+
client.init()
81+
val branch = loadDataAsBranch(client)
8982
branch.runRead {
9083
val root = branch.getRootNode()
9184
logger.info("Got root node: {}", root)
@@ -100,6 +93,16 @@ abstract class ExportFromModelServer @Inject constructor(of: ObjectFactory) : De
10093
}
10194
}
10295

96+
private suspend fun loadDataAsBranch(client: ModelClientV2): PBranch {
97+
val version = if (revision.isPresent) {
98+
client.loadVersion(revision.get(), null)
99+
} else {
100+
client.pull(getBranchReference(), null)
101+
}
102+
val branch = PBranch(version.getTree(), client.getIdGenerator())
103+
return branch
104+
}
105+
103106
private fun getIncludedModules(root: INode): Iterable<INode> {
104107
val nameRole = BuiltinLanguages.jetbrains_mps_lang_core.INamedConcept.name
105108

@@ -111,19 +114,4 @@ abstract class ExportFromModelServer @Inject constructor(of: ObjectFactory) : De
111114
isModule && isIncluded
112115
}
113116
}
114-
115-
private fun getBranchByRepoIdAndBranch(client: ModelClientV2): IBranch {
116-
val repoId = RepositoryId(repositoryId.get())
117-
val branchRef = ModelFacade.createBranchReference(repoId, branchName.get())
118-
119-
val branch = runBlocking {
120-
client.getReplicatedModel(branchRef).start()
121-
}
122-
return branch
123-
}
124-
125-
private fun getBranchByRevision(client: IModelClientV2): IBranch {
126-
val version = runBlocking { client.loadVersion(revision.get(), null) }
127-
return PBranch(version.getTree(), client.getIdGenerator())
128-
}
129117
}

0 commit comments

Comments
 (0)