@@ -26,16 +26,13 @@ import org.gradle.api.tasks.Input
26
26
import org.gradle.api.tasks.Optional
27
27
import org.gradle.api.tasks.OutputDirectory
28
28
import org.gradle.api.tasks.TaskAction
29
- import org.modelix.model.ModelFacade
30
29
import org.modelix.model.api.BuiltinLanguages
31
- import org.modelix.model.api.IBranch
32
30
import org.modelix.model.api.INode
33
31
import org.modelix.model.api.PBranch
34
32
import org.modelix.model.api.getRootNode
35
- import org.modelix.model.client2.IModelClientV2
36
33
import org.modelix.model.client2.ModelClientV2
37
34
import org.modelix.model.client2.ModelClientV2PlatformSpecificBuilder
38
- import org.modelix.model.client2.getReplicatedModel
35
+ import org.modelix.model.lazy.BranchReference
39
36
import org.modelix.model.lazy.RepositoryId
40
37
import org.modelix.model.sync.bulk.ModelExporter
41
38
import org.modelix.model.sync.bulk.isModuleIncluded
@@ -71,21 +68,17 @@ abstract class ExportFromModelServer @Inject constructor(of: ObjectFactory) : De
71
68
@Input
72
69
val requestTimeoutSeconds: Property <Int > = of.property(Int ::class .java)
73
70
71
+ private fun getBranchReference (): BranchReference = RepositoryId (repositoryId.get()).getBranchReference(branchName.get())
72
+
74
73
@TaskAction
75
- fun export () {
74
+ fun export () = runBlocking {
76
75
val modelClient = ModelClientV2PlatformSpecificBuilder ()
77
76
.url(url.get())
78
77
.requestTimeout(requestTimeoutSeconds.get().seconds)
79
78
.build()
80
79
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)
89
82
branch.runRead {
90
83
val root = branch.getRootNode()
91
84
logger.info(" Got root node: {}" , root)
@@ -100,6 +93,16 @@ abstract class ExportFromModelServer @Inject constructor(of: ObjectFactory) : De
100
93
}
101
94
}
102
95
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
+
103
106
private fun getIncludedModules (root : INode ): Iterable <INode > {
104
107
val nameRole = BuiltinLanguages .jetbrains_mps_lang_core.INamedConcept .name
105
108
@@ -111,19 +114,4 @@ abstract class ExportFromModelServer @Inject constructor(of: ObjectFactory) : De
111
114
isModule && isIncluded
112
115
}
113
116
}
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
- }
129
117
}
0 commit comments