-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.sbt
executable file
·475 lines (422 loc) · 18.9 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
import Dependencies.deps
import NpmOpsPlugin.autoImport.npmDependencies
import sbt.File
import sbt.Keys.{libraryDependencies, mainClass, packageOptions, parallelExecution}
import sbtcrossproject.CrossPlugin.autoImport.crossProject
import org.scalajs.linker.interface.ESVersion
import scala.language.postfixOps
import scala.sys.process.Process
name := "api-language-server"
ThisBuild / scalaVersion := "2.12.20"
version := deps("version")
jsEnv := new org.scalajs.jsenv.nodejs.NodeJSEnv()
publish := {}
lazy val workspaceDirectory: File =
sys.props.get("sbt.mulesoft") match {
case Some(x) => file(x)
case _ => Path.userHome / "mulesoft"
}
val amfVersion = deps("amf")
val amfCustomValidatorJSVersion = deps("amf.custom-validator.js")
val amfCustomValidatorScalaJSVersion = deps("amf.custom-validator-scalajs")
val amfAntlrParsersVersion = deps("amf-antlr-parsers")
val scalaJSVersion = "1.1.0"
val commonNpmDependencies = List(
("ajv", "6.12.6"),
("@aml-org/amf-antlr-parsers", amfAntlrParsersVersion)
)
lazy val amfJVMRef = ProjectRef(workspaceDirectory / "amf", "graphqlJVM")
lazy val amfJSRef = ProjectRef(workspaceDirectory / "amf", "graphqlJS")
lazy val amfLibJVM = "com.github.amlorg" %% "amf-graphql" % amfVersion
lazy val amfLibJS = "com.github.amlorg" %% "amf-graphql_sjs1" % amfVersion
lazy val customValidatorWebJVMRef =
ProjectRef(workspaceDirectory / "amf-custom-validator-scalajs", "amfCustomValidatorWebJVM")
lazy val customValidatorWebJSRef =
ProjectRef(workspaceDirectory / "amf-custom-validator-scalajs", "amfCustomValidatorWebJS")
lazy val customValidatorWebLibJVM = "com.github.amlorg" %% "amf-custom-validator-web" % amfCustomValidatorScalaJSVersion excludeAll(
ExclusionRule(organization = "com.github.amlorg", name = "amf-api-contract_2.12"),
ExclusionRule(organization = "com.github.amlorg", name = "amf-aml_sjs1_2.12"),
ExclusionRule(organization = "com.github.amlorg", name = "amf-shapes_sjs1_2.12"),
ExclusionRule(organization = "com.github.amlorg", name = "amf-core_sjs1_2.12"),
)
lazy val customValidatorWebLibJS =
"com.github.amlorg" %% "amf-custom-validator-web_sjs1" % amfCustomValidatorScalaJSVersion excludeAll(
ExclusionRule(organization = "com.github.amlorg", name = "amf-api-contract_2.12"),
ExclusionRule(organization = "com.github.amlorg", name = "amf-aml_sjs1_2.12"),
ExclusionRule(organization = "com.github.amlorg", name = "amf-shapes_sjs1_2.12"),
ExclusionRule(organization = "com.github.amlorg", name = "amf-core_sjs1_2.12"),
)
lazy val customValidatorNodeJVMRef =
ProjectRef(workspaceDirectory / "amf-custom-validator-scalajs", "amfCustomValidatorNodeJVM")
lazy val customValidatorNodeJSRef =
ProjectRef(workspaceDirectory / "amf-custom-validator-scalajs", "amfCustomValidatorNodeJS")
lazy val customValidatorNodeLibJVM =
"com.github.amlorg" %% "amf-custom-validator-node" % amfCustomValidatorScalaJSVersion excludeAll(
ExclusionRule(organization = "com.github.amlorg", name = "amf-api-contract_2.12"),
ExclusionRule(organization = "com.github.amlorg", name = "amf-aml_sjs1_2.12"),
ExclusionRule(organization = "com.github.amlorg", name = "amf-shapes_sjs1_2.12"),
ExclusionRule(organization = "com.github.amlorg", name = "amf-core_sjs1_2.12"),
)
lazy val customValidatorNodeLibJS =
"com.github.amlorg" %% "amf-custom-validator-node_sjs1" % amfCustomValidatorScalaJSVersion excludeAll(
ExclusionRule(organization = "com.github.amlorg", name = "amf-api-contract_2.12"),
ExclusionRule(organization = "com.github.amlorg", name = "amf-aml_sjs1_2.12"),
ExclusionRule(organization = "com.github.amlorg", name = "amf-shapes_sjs1_2.12"),
ExclusionRule(organization = "com.github.amlorg", name = "amf-core_sjs1_2.12"),
)
lazy val npmDependencyAmfCustomValidatorWeb = s"@aml-org/amf-custom-validator-web@$amfCustomValidatorJSVersion"
lazy val npmDependencyAmfCustomValidator = s"@aml-org/amf-custom-validator@$amfCustomValidatorJSVersion"
lazy val npmDependencyAmfAntlr = s"@aml-org/amf-antlr-parsers@$amfAntlrParsersVersion"
lazy val airframeDependency = "org.wvlet.airframe" %% "airframe" % "23.5.3"
lazy val guavaDependency = "com.google.guava" % "guava" % "31.1-jre"
lazy val eclipseLsp4jDependency = "org.eclipse.lsp4j" % "org.eclipse.lsp4j" % "0.21.0"
lazy val eclipseXbaseRuntimeLibrary = "org.eclipse.xtext" % "org.eclipse.xtext.xbase.lib" % "2.32.0.M0"
lazy val eclipseGeneratorRuntimeLibrary = "org.eclipse.lsp4j" % "org.eclipse.lsp4j.generator" % "0.21.0"
////region SBT-Dependencies
lazy val scalaJS_DomDependency = ModuleID("org.scala-js", "scalajs-dom_sjs1_2.12" , "1.1.0")
lazy val upickle_Dependency = ModuleID("com.lihaoyi", "upickle_sjs1_2.12", "0.9.9")
lazy val scalaJS_NodeDependency = ModuleID("net.exoego", "scala-js-nodejs-v14_sjs1_2.12", "0.13.0")
////endregion
val orgSettings = Seq(
organization := "org.mule.als",
version := deps("version"),
resolvers ++= List(
Common.releases,
Common.snapshots,
Resolver.mavenLocal /*,
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")*/
),
resolvers += "jitpack" at "https://jitpack.io",
credentials ++= Common.credentials(),
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.3.3",
"org.scala-js" %% "scalajs-stubs" % scalaJSVersion % "provided",
"org.scalatest" %%% "scalatest" % "3.2.10" % Test,
upickle_Dependency
)
)
val settings = Common.settings ++ Common.publish ++ orgSettings
concurrentRestrictions in Global := Seq(Tags.limitAll(2))
////region ALS-COMMON
/** ALS common */
lazy val pathAlsCommon = "./als-common"
lazy val common = crossProject(JSPlatform, JVMPlatform)
.settings(
Seq(
name := "als-common"
)
)
.in(file(s"$pathAlsCommon"))
.dependsOn(lsp)
.settings(settings: _*)
.jsSettings(
installJsDependenciesWeb := {
Process(
s"npm install -E $npmDependencyAmfAntlr",
new File(s"$pathAlsCommon/js/")
) #&&
Process("npm install", new File(s"$pathAlsCommon/js/")) !
},
scalaJSLinkerConfig ~= { _
.withModuleKind(ModuleKind.CommonJSModule)
.withESFeatures(_.withESVersion(ESVersion.ES2018))
},
npmDependencies ++= commonNpmDependencies
// ,scalaJSLinkerOutputDirectory in (Compile, fastOptJS) := baseDirectory.value / "target" / "artifact" /"high-level.js"
)
.disablePlugins(SonarPlugin)
lazy val commonJVM = common.jvm
.in(file(s"$pathAlsCommon/jvm"))
.sourceDependency(amfJVMRef, amfLibJVM)
.sourceDependency(customValidatorWebJVMRef, customValidatorWebLibJVM)
lazy val commonJS = common.js
.in(file(s"$pathAlsCommon/js"))
.sourceDependency(amfJSRef, amfLibJS)
.sourceDependency(customValidatorWebJSRef, customValidatorWebLibJS)
.disablePlugins(SonarPlugin, ScoverageSbtPlugin)
////endregion
////region ALS-LSP
/** ALS LSP */
lazy val lsp = crossProject(JSPlatform, JVMPlatform)
.settings(
Seq(
name := "als-lsp"
)
)
.in(file("./als-lsp"))
.settings(settings: _*)
.jvmSettings(
libraryDependencies += guavaDependency,
libraryDependencies += eclipseLsp4jDependency,
libraryDependencies += eclipseXbaseRuntimeLibrary,
libraryDependencies += eclipseGeneratorRuntimeLibrary,
libraryDependencies += "org.scala-lang.modules" % "scala-java8-compat_2.12" % "1.0.2"
)
.jsSettings(
scalaJSLinkerConfig ~= { _
.withModuleKind(ModuleKind.CommonJSModule)
.withESFeatures(_.withESVersion(ESVersion.ES2018))
}
// scalaJSLinkerOutputDirectory in (Compile, fastOptJS) := baseDirectory.value / "target" / "artifact" /"high-level.js"
)
.disablePlugins(SonarPlugin)
lazy val lspJVM = lsp.jvm.in(file("./als-lsp/jvm"))
lazy val lspJS = lsp.js.in(file("./als-lsp/js")).disablePlugins(ScoverageSbtPlugin)
////endregion
////region ALS-SUGGESTIONS
/** ALS suggestions */
lazy val suggestions = crossProject(JSPlatform, JVMPlatform)
.settings(
Seq(
name := "als-suggestions"
)
)
.dependsOn(common % "compile->compile;test->test")
.in(file("./als-suggestions"))
.settings(settings: _*)
.jsSettings(
libraryDependencies += upickle_Dependency,
// packageJSDependencies / skip := false,
scalaJSLinkerConfig ~= { _
.withModuleKind(ModuleKind.CommonJSModule)
.withESFeatures(_.withESVersion(ESVersion.ES2018))
},
npmDependencies ++= commonNpmDependencies
)
.disablePlugins(SonarPlugin)
lazy val suggestionsJVM = suggestions.jvm.in(file("./als-suggestions/jvm"))
lazy val suggestionsJS = suggestions.js.in(file("./als-suggestions/js")).disablePlugins(SonarPlugin, ScoverageSbtPlugin)
////endregion
////region ALS-STRUCTURE
/** ALS structure */
lazy val pathAlsStructure = "./als-structure"
lazy val structure = crossProject(JSPlatform, JVMPlatform)
.settings(
Seq(
name := "als-structure"
)
)
.dependsOn(common % "compile->compile;test->test")
.in(file(s"$pathAlsStructure"))
.settings(settings: _*)
.jsSettings(
libraryDependencies ++= Seq(
scalaJS_DomDependency,
upickle_Dependency
),
scalaJSLinkerConfig ~= { _
.withModuleKind(ModuleKind.CommonJSModule)
.withESFeatures(_.withESVersion(ESVersion.ES2018))
},
npmDependencies ++= commonNpmDependencies
)
.disablePlugins(SonarPlugin)
lazy val structureJVM = structure.jvm.in(file(s"$pathAlsStructure/jvm"))
lazy val structureJS = structure.js.in(file(s"$pathAlsStructure/js")).disablePlugins(SonarPlugin, ScoverageSbtPlugin)
////endregion
////region ALS-ACTIONS
/** ALS actions */
lazy val pathAlsActions = "./als-actions"
lazy val actions = crossProject(JSPlatform, JVMPlatform)
.settings(name := "als-actions")
.settings(libraryDependencies += airframeDependency)
.dependsOn(common % "compile->compile;test->test")
.in(file(s"$pathAlsActions"))
.settings(settings: _*)
.jsSettings(
scalaJSLinkerConfig ~= { _
.withModuleKind(ModuleKind.CommonJSModule)
.withESFeatures(_.withESVersion(ESVersion.ES2018))
},
npmDependencies ++= commonNpmDependencies
)
.disablePlugins(SonarPlugin)
lazy val actionsJVM = actions.jvm.in(file(s"$pathAlsActions/jvm"))
lazy val actionsJS = actions.js.in(file(s"$pathAlsActions/js")).disablePlugins(SonarPlugin, ScoverageSbtPlugin)
////endregion
////region ALS-SERVER
/** ALS server */
val installJsDependenciesWeb = TaskKey[Unit]("installJsDependenciesWeb", "Runs npm i")
val installJsDependencies = TaskKey[Unit]("installJsDependencies", "Runs npm i but switches web for node dependency (tests only)")
lazy val server = crossProject(JSPlatform, JVMPlatform)
.settings(name := "als-server")
.settings(libraryDependencies += airframeDependency)
.dependsOn(actions, suggestions, structure % "compile->compile;test->test")
.in(file("./als-server"))
.settings(settings: _*)
.disablePlugins(SonarPlugin)
.jvmSettings(
// https://mvnrepository.com/artifact/org.eclipse.lsp4j/org.eclipse.lsp4j
Compile / packageBin / packageOptions += Package.ManifestAttributes("Automatic-Module-Name" → "org.mule.als"),
assembly / aggregate := true,
assembly / mainClass := Some("org.mulesoft.als.server.lsp4j.Main"),
Compile / mainClass := Some("org.mulesoft.als.server.lsp4j.Main"),
scalacOptions += "-Xmixin-force-forwarders:false",
assembly / assemblyMergeStrategy := {
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case x => MergeStrategy.first
}
)
.jsSettings(
installJsDependenciesWeb := {
Process(
s"npm uninstall @aml-org/amf-custom-validator",
new File("./als-server/js/node-package")
) #&&
Process(
s"npm install -E $npmDependencyAmfCustomValidatorWeb $npmDependencyAmfAntlr",
new File("./als-server/js/node-package")
) #&&
Process("npm install", new File("./als-server/js/node-package")) !
},
installJsDependencies := {
Process(
s"npm install -E $npmDependencyAmfCustomValidator $npmDependencyAmfCustomValidatorWeb $npmDependencyAmfAntlr",
new File("./als-server/js/node-package")
) #&&
Process("npm install", new File("./als-server/js/node-package")) !
},
Test / test := ((Test / test) dependsOn installJsDependencies).value,
Test / fastLinkJS / scalaJSLinkerOutputDirectory := baseDirectory.value / "node-package" / "tmp" / "als-server.js",
scalaJSLinkerConfig ~= { _
.withModuleKind(ModuleKind.CommonJSModule)
.withESFeatures(_.withESVersion(ESVersion.ES2018))
},
libraryDependencies ++= Seq(
scalaJS_NodeDependency,
scalaJS_DomDependency
),
Compile / fastLinkJS / scalaJSLinkerOutputDirectory := baseDirectory.value / "node-package" / "tmp" / "als-server.js",
Compile / fullLinkJS / scalaJSLinkerOutputDirectory := baseDirectory.value / "node-package" / "tmp" / "als-server.min.js"
)
lazy val serverJVM = server.jvm.in(file("./als-server/jvm"))
lazy val serverJS = server.js.in(file("./als-server/js"))
.disablePlugins(SonarPlugin, ScoverageSbtPlugin)
.sourceDependency(customValidatorNodeJSRef, customValidatorNodeLibJS)
////endregion
////region ALS-NODE-CLIENT
/** ALS node client */
val npmIClient = TaskKey[Unit]("npmIClient", "Install npm at node client")
lazy val nodeClient = project
.dependsOn(serverJS % "compile->compile;test->test")
.in(file("./als-node-client"))
.enablePlugins(ScalaJSPlugin)
.settings(settings: _*)
.disablePlugins(SonarPlugin, ScoverageSbtPlugin)
.settings(
settings ++ Seq(
name := "als-node-client",
scalaJSUseMainModuleInitializer := true,
scalaJSLinkerConfig ~= { _
.withModuleKind(ModuleKind.CommonJSModule)
.withESFeatures(_.withESVersion(ESVersion.ES2018))
},
libraryDependencies += scalaJS_NodeDependency,
Compile / mainClass := Some("org.mulesoft.als.nodeclient.Main"),
npmIClient := {
Process(
s"npm install -E $npmDependencyAmfCustomValidator $npmDependencyAmfCustomValidatorWeb $npmDependencyAmfAntlr",
new File("./als-node-client/node-package/")
) #&&
Process(
s"cp -r ../../als-server/js/node-package/typescript/als-server.d.ts ./typescript/als-node-client.d.ts",
new File("./als-node-client/node-package/")
) #&&
Process(
s"sed -i.bk s/@aml-org\\/als-server/@aml-org\\/als-node-client/ als-node-client.d.ts",
new File("./als-node-client/node-package/typescript/")
) #&&
Process(s"rm als-node-client.d.ts.bk", new File("./als-node-client/node-package/typescript/")) #&&
Process("npm i", new File("./als-node-client/node-package/")) !
},
Test / test := ((Test / test) dependsOn npmIClient).value,
Test / fastLinkJS / scalaJSLinkerOutputDirectory := baseDirectory.value / "node-package" / "tmp" / "als-node-client.js",
Compile / fullLinkJS / scalaJSLinkerOutputDirectory := baseDirectory.value / "node-package" / "tmp" / "als-node-client.min.js",
Compile / fastLinkJS / scalaJSLinkerOutputDirectory := baseDirectory.value / "node-package" / "tmp" / "als-node-client.js"
)
)
.sourceDependency(customValidatorNodeJSRef, customValidatorNodeLibJS)
////endregion
/** ALS build tasks */
// Server library
// in order to test using sbt (which runs on jsEnv node) we need to install the node package of custom-validator
// building the server library we package the -web version because it is meant to run in browser
// beware that this means the -web version is not tested and if there is any bug in this asset, it will be passed on runtime
val buildJsServerLibrary = TaskKey[Unit]("buildJsServerLibrary", "Build server library")
buildJsServerLibrary := {
(serverJS / installJsDependenciesWeb).value
(serverJS / Compile / fastLinkJS).value
(serverJS / Compile / fullLinkJS).value
val result = (Process(
"./scripts/build.sh",
new File("./als-server/js/node-package")
).!)
if (result != 0) throw new IllegalStateException("Node JS build.sh failed")
}
// Node client
val buildNodeJsClient = TaskKey[Unit]("buildNodeJsClient", "Build node client")
buildNodeJsClient := {
(nodeClient / Compile / fastLinkJS).value
(nodeClient / Compile / fullLinkJS).value
(nodeClient / npmIClient).value
val result = (Process(
"./scripts/build.sh",
new File("./als-node-client/node-package")
).!)
if (result != 0) throw new IllegalStateException("Node JS build.sh failed")
}
// ************** SONAR *******************************
lazy val token = sys.env.getOrElse("SONAR_SERVER_TOKEN", "Not found token.")
lazy val branch = sys.env.getOrElse("BRANCH_NAME", "devel")
sonarProperties ++= Map(
"sonar.login" -> token,
"sonar.projectKey" -> "mulesoft.als.gec",
"sonar.projectName" -> "ALS",
"sonar.projectVersion" -> "1.0.0",
"sonar.sourceEncoding" -> "UTF-8",
"sonar.github.repository" -> "aml-org/als",
"sonar.branch.name" -> branch,
"sonar.sources" -> "als-server/shared/src/main/scala,als-structure/shared/src/main/scala,als-suggestions/shared/src/main/scala",
"sonar.tests" -> "als-server/shared/src/test/scala,als-structure/shared/src/test/scala,als-suggestions/shared/src/test/scala"
)
//**************** ALIASES *********************************************************************************************
// run only one?
addCommandAlias(
"testJVM",
"; serverJVM/test; suggestionsJVM/test; structureJVM/test; commonJVM/test; actionsJVM/test; lspJVM/test; "
)
addCommandAlias(
"testJS",
"; serverJS/test; suggestionsJS/test; structureJS/test; commonJS/test; actionsJS/test; lspJS/test; "
)
assembly / assemblyMergeStrategy := {
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case x => MergeStrategy.first
}
//******* fat jar*****************************
lazy val fat = crossProject(JVMPlatform)
.settings(
Seq(
name := "api-language-server"
)
)
.dependsOn(suggestions, structure, server)
.disablePlugins(SonarPlugin)
.enablePlugins(AssemblyPlugin)
.in(file("./als-fat"))
.settings(settings: _*)
.jvmSettings(
Compile / packageBin / packageOptions += Package.ManifestAttributes("Automatic-Module-Name" → "org.mule.als"),
assembly / aggregate := true,
Compile / packageBin / publishArtifact := false,
addArtifact(Artifact("api-language-server", ""), assembly),
assembly / assemblyMergeStrategy := {
case x if x.toString.contains("commons/logging") => MergeStrategy.discard
case x if x.toString.endsWith("JS_DEPENDENCIES") => MergeStrategy.discard
case PathList(ps @ _*) if ps.last endsWith "JS_DEPENDENCIES" => MergeStrategy.discard
case PathList("META-INF", "MANIFEST.MF") => MergeStrategy.discard
case x => MergeStrategy.first
}
)
lazy val coreJVM = fat.jvm.in(file("./als-fat/jvm")).disablePlugins(SonarPlugin)