@@ -26,16 +26,13 @@ import org.gradle.api.tasks.Input
2626import org.gradle.api.tasks.Optional
2727import org.gradle.api.tasks.OutputDirectory
2828import org.gradle.api.tasks.TaskAction
29- import org.modelix.model.ModelFacade
3029import org.modelix.model.api.BuiltinLanguages
31- import org.modelix.model.api.IBranch
3230import org.modelix.model.api.INode
3331import org.modelix.model.api.PBranch
3432import org.modelix.model.api.getRootNode
35- import org.modelix.model.client2.IModelClientV2
3633import org.modelix.model.client2.ModelClientV2
3734import org.modelix.model.client2.ModelClientV2PlatformSpecificBuilder
38- import org.modelix.model.client2.getReplicatedModel
35+ import org.modelix.model.lazy.BranchReference
3936import org.modelix.model.lazy.RepositoryId
4037import org.modelix.model.sync.bulk.ModelExporter
4138import 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