-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sbt
404 lines (327 loc) · 15.3 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
import org.scalajs.core.tools.linker.backend.OutputMode._
import com.typesafe.sbt.license.{LicenseInfo, DepModuleInfo}
import com.typesafe.sbt.sbtghpages.GhpagesPlugin
import de.heikoseeberger.sbtheader.HeaderPlugin
import de.heikoseeberger.sbtheader.CommentStyle
import gov.nasa.jpl.imce.sbt._
val oml_license =
s"""|Copyright 2016 California Institute of Technology ("Caltech").
|U.S. Government sponsorship acknowledged.
|
|Licensed under the Apache License, Version 2.0 (the "License");
|you may not use this file except in compliance with the License.
|You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
|Unless required by applicable law or agreed to in writing, software
|distributed under the License is distributed on an "AS IS" BASIS,
|WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|See the License for the specific language governing permissions and
|limitations under the License.
|License Terms
|""".stripMargin
scalaVersion in ThisBuild := "2.11.11"
shellPrompt in ThisBuild := { state => Project.extract(state).currentRef.project + "> " }
val tablesLicenseSettings: Seq[Setting[_]] =
Seq(
licenses += "Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.html"),
startYear := Some(2016),
headerLicense := Some(HeaderLicense.ALv2("2016", oml_license)),
headerMappings := headerMappings.value +
(HeaderFileType.java -> CommentStyle.CStyleBlockComment) +
(HeaderFileType("js") -> CommentStyle.CStyleBlockComment) +
(HeaderFileType.scala -> CommentStyle.CStyleBlockComment),
licenseReportTitle := "LicenseReportOfAggregatedSBTPluginsAndLibraries",
licenseSelection += LicenseCategory("EPL", Seq("Eclipse Public License")),
// Add style rules to the report.
licenseReportStyleRules := Some("table, th, td {border: 1px solid black;}"),
// The ivy configurations we'd like to grab licenses for.
licenseConfigurations := Set("compile", "provided"),
// Override the license information from ivy, if it's non-existent or wrong
licenseOverrides := {
case DepModuleInfo("com.jsuereth", _, _) =>
LicenseInfo(LicenseCategory.BSD, "BSD-3-Clause", "http://opensource.org/licenses/BSD-3-Clause")
},
licenseReportTypes := Seq(Html)
)
val tablesPublishSettings: Seq[Setting[_]] = Seq(
PgpKeys.useGpg := true,
PgpKeys.useGpgAgent := true,
pgpSecretRing := file("local.secring.gpg"),
pgpPublicRing := file("local.pubring.gpg"),
git.baseVersion := Settings.version
) ++ versionWithGit
lazy val filter: ScopeFilter = ScopeFilter(inProjects(ThisProject), inConfigurations(Compile))
lazy val dependencySvgFile = settingKey[File]("Location of the dependency graph in SVG format")
val tablesGhPagesSettings: Seq[Setting[_]] =
Seq[Setting[_]](
preprocessVars in Preprocess := Map(
"CI" -> s"https://travis-ci.org/${Settings.organizationName.toLowerCase}/${Settings.name}",
"GIT" -> "github.com",
"REPO" -> Settings.name,
"VER" -> version.value,
"ORG" -> Settings.organizationName.toLowerCase,
"SUBJECT" -> Settings.organizationName,
"ORG_NAME" -> organizationName.value,
"DESC" -> description.value,
"PKG" -> moduleName.value,
"CONTRIBUTORS" -> {
val commit = Process("git rev-parse HEAD").lines.head
val p1 = Process(s"git shortlog -sne --no-merges $commit")
val p2 = Process(
Seq("sed",
"-e",
"""s|^\s*\([0-9][0-9]*\)\s*\(\w.*\w\)\s*<\([a-zA-Z].*\)>.*$|<tr><td align='right'>\1</td><td>\2</td><td>\3</td></tr>|"""))
val whoswho = p1 #| p2
whoswho.lines.mkString("\n")
},
"VERSION" -> {
git.gitCurrentTags.value match {
case Seq(tag) =>
s"""<a href="https://@GIT@/@ORG@/${moduleName.value}/tree/$tag">$tag</a>"""
case _ =>
val v = version.value
git.gitHeadCommit.value.fold[String](v) { sha =>
if (git.gitUncommittedChanges.value)
v
else
s"""<a href="https://@GIT@/@ORG@/${moduleName.value}/tree/$sha">$v</a>"""
}
}
}
)
) ++ Seq[Setting[_]](
dependencyDotFile := baseDirectory.value / "target" / "dependencies.dot",
dependencySvgFile := baseDirectory.value / "target" / "dependencies.svg",
dumpLicenseReport := {
val dotFile = dependencyDot.all(filter).value
val ok = Process(command = "dot", arguments = Seq[String]("-Tsvg", dotFile.head.getAbsolutePath, "-o" + dependencySvgFile.value.getAbsolutePath)).!
require(0 == ok, "dot2svg failed: $ok")
dumpLicenseReport.value
},
makeSite := {
val _ = dumpLicenseReport.value
makeSite.value
},
siteMappings := {
val _ = dumpLicenseReport.value
siteMappings.value
},
siteMappings += (licenseReportDir.value / "LicenseReportOfAggregatedSBTPluginsAndLibraries.html") -> "LicenseReportOfAggregatedSBTPluginsAndLibraries.html",
siteMappings += dependencySvgFile.value -> "dependencies.svg",
previewFixedPort := Some(4004),
previewLaunchBrowser := false
)
val Npm = config("npm")
pomIncludeRepository in Global := { _ => false }
resolvers in Global += Resolver.bintrayRepo(Settings.organizationName.toLowerCase, Settings.organization)
resolvers in Global += "Artima Maven Repository" at "http://repo.artima.com/releases"
lazy val tablesRoot = project.in(file("."))
.aggregate(tablesJS, tablesJVM)
.settings(publishArtifact := false)
// a special crossProject for configuring a JS/JVM/shared structure
lazy val tables = crossProject
.in(file("."))
.enablePlugins(IMCEGitPlugin)
.enablePlugins(GhpagesPlugin)
.settings(
IMCEKeys.licenseYearOrRange := "2016",
IMCEKeys.organizationInfo :=
OrganizationInfo(
Settings.organization,
Settings.organizationName,
Some(url(s"https://github.com/${Settings.organizationName}"))),
IMCEKeys.targetJDK := IMCEKeys.jdk18.value
)
.settings(tablesLicenseSettings : _*)
.settings(tablesPublishSettings : _*)
.settings(tablesGhPagesSettings : _*)
.settings(
name := Settings.name,
// https://github.com/typesafehub/sbteclipse/wiki/Using-sbteclipse#useprojectid
EclipseKeys.useProjectId := true,
// https://github.com/typesafehub/sbteclipse/wiki/Using-sbteclipse#skipparents
EclipseKeys.skipParents in ThisBuild := false,
// https://github.com/typesafehub/sbteclipse/wiki/Using-sbteclipse#withsource
EclipseKeys.withSource := true,
// https://github.com/typesafehub/sbteclipse/wiki/Using-sbteclipse#relativizelibs
EclipseKeys.relativizeLibs := true,
// https://github.com/typesafehub/sbteclipse/wiki/Using-sbteclipse#executionenvironment
EclipseKeys.executionEnvironment := Some(EclipseExecutionEnvironment.JavaSE18),
// https://github.com/typesafehub/sbteclipse/wiki/Using-sbteclipse#withbundledscalacontainers
EclipseKeys.withBundledScalaContainers := true,
git.baseVersion := Settings.version,
scalaVersion := Settings.versions.scala,
scalacOptions ++= Settings.scalacOptions,
// do not include all repositories in the POM
// (this is important for staging since artifacts published to a staging repository
// can be promoted (i.e. published) to another repository)
pomAllRepositories := false,
// make sure no repositories show up in the POM file
pomIncludeRepository := { _ => false },
// include *.zip artifacts in the POM dependency section
makePomConfiguration :=
makePomConfiguration.value.copy(includeTypes = Set(Artifact.DefaultType, Artifact.PomType, "zip")),
scalacOptions in (Compile, compile) += s"-P:artima-supersafe:config-file:${baseDirectory.value}/project/supersafe.cfg",
scalacOptions in (Test, compile) += s"-P:artima-supersafe:config-file:${baseDirectory.value}/project/supersafe.cfg",
scalacOptions in (Compile, doc) += "-Xplugin-disable:artima-supersafe",
scalacOptions in (Test, doc) += "-Xplugin-disable:artima-supersafe",
libraryDependencies ++= Settings.sharedDependencies.value,
// Avoid unresolvable dependencies from old versions of log4j
libraryDependencies ~= {
_ map {
case m if m.organization == "log4j" =>
m
.exclude("javax.jms", "jms")
.exclude("com.sun.jmx", "jmxri")
.exclude("com.sun.jdmk", "jmxtools")
case m => m
}
}
)
.jvmConfigure(_ enablePlugins HeaderPlugin)
.jvmConfigure(_ enablePlugins PreprocessPlugin)
.jvmConfigure(_ enablePlugins SiteScaladocPlugin)
.jvmSettings(
inConfig(Preprocess)(
sourceDirectory := baseDirectory.value / ".." / "shared" / "src" / "site-preprocess"
) : _*
)
.jvmSettings(
publishTo in Global := Some("JPL-IMCE" at s"https://api.bintray.com/content/jpl-imce/gov.nasa.jpl.imce/${Settings.name}/${version.value}"),
libraryDependencies ++= Settings.jvmDependencies.value,
dynamicScriptsResourceSettings(Settings.dashName),
scalacOptions in (Compile,doc) ++= Seq(
"-diagrams",
"-doc-title", name.value,
"-doc-root-content", baseDirectory.value + "/rootdoc.txt"),
autoAPIMappings := true,
apiURL := Some(url("https://jpl-imce.github.io/gov.nasa.jpl.imce.oml.tables/latest/api/index.html")),
dependencyOverrides += "com.fasterxml.jackson.module" % "jackson-module-paranamer" % Settings.versions.spark_jackson % "compile",
dependencyOverrides += "com.fasterxml.jackson.module" %% "jackson-module-scala" % Settings.versions.spark_jackson % "compile",
projectID := {
val previous = projectID.value
println(s"jvm: $previous")
previous.extra(
sbt.mavenint.SbtPomExtraProperties.POM_API_KEY -> "https://jpl-imce.github.io/gov.nasa.jpl.imce.oml.tables/latest/api/"
)
}
)
// set up settings specific to the JS project
.jsConfigure(_ enablePlugins HeaderPlugin)
.jsConfigure(_ enablePlugins PreprocessPlugin)
.jsConfigure(_ enablePlugins SiteScaladocPlugin)
.jsConfigure(_ enablePlugins ScalaJSPlugin)
.jsSettings(
inConfig(Npm)(
PreprocessPlugin.preprocessSettings(Npm) ++
Seq(
preprocessVars := Map(
"HYPHENATED_NAME" -> Settings.dashName,
"DESCRIPTION" -> description.value,
"VERSION" -> version.value,
"HOMEPAGE" -> (homepage in ThisBuild).value.get.toString,
"GIT" -> (git.remoteRepo in ThisBuild).value,
"ISSUES" -> s"${(scmInfo in ThisBuild).value.get.browseUrl.toString+"/issues"}",
"AUTHOR" -> {
val a = (developers in ThisBuild).value.head
s"""{ "name": "${a.name}", "email": "${a.email}", "url": "${a.url.toString}"}"""
},
"CONTRIBUTORS" -> {
val ds = (developers in ThisBuild).value.map { d =>
s"""{ "name": "${d.name}", "email": "${d.email}", "url": "${d.url.toString}"}"""
}
ds.mkString("[",",", "]")
}
),
sourceDirectory := baseDirectory.value / ".." / "shared" / "src" / "npm-preprocess",
preprocessIncludeFilter := "*.json",
includeFilter := AllPassFilter,
target := baseDirectory.value / ".."
)
) : _*)
.jsSettings(
inConfig(Preprocess)(
sourceDirectory := baseDirectory.value / ".." / "shared" / "src" / "site-preprocess"
) : _*
)
.jsSettings(
publishTo := Some("JPL-IMCE" at s"https://api.bintray.com/content/jpl-imce/gov.nasa.jpl.imce/${Settings.dashName}/${version.value}"),
// For easier debugging, disable JavaScript optimizations
// scalaJSLinkerConfig ~= { _.withOptimizer(false) },
// Disable if debugging.
scalaJSStage in Global := FullOptStage,
jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv,
libraryDependencies ++= Settings.scalajsDependencies.value,
//scalaJSOutputMode := ECMAScript51Global,
//scalaJSOutputMode := ECMAScript51Isolated,
scalaJSOutputMode := ECMAScript2015,
crossTarget in (Compile, fastOptJS) := baseDirectory.value / "..",
crossTarget in (Compile, fullOptJS) := baseDirectory.value / "..",
artifactPath in (Compile, fastOptJS) :=
(crossTarget in (Compile, fastOptJS)).value / s"${Settings.dashName}.js",
artifactPath in (Compile, fullOptJS) :=
(crossTarget in (Compile, fullOptJS)).value / s"${Settings.dashName}.js",
fastOptJS in Compile := {
val result = (fastOptJS in Compile).value
val p = (preprocess in config("npm")).value
streams.value.log.info("npm/preprocess: "+p)
val ok = Process(command=Seq[String]("npm", "pack"), cwd = baseDirectory.value / ".." ).!
require(0 == ok, "npm pack failed: " + ok)
result
},
fullOptJS in Compile := {
val result = (fullOptJS in Compile).value
val p = (preprocess in config("npm")).value
streams.value.log.info("npm/preprocess: "+p)
val ok = Process(command=Seq[String]("npm", "pack"), cwd = baseDirectory.value / ".." ).!
require(0 == ok, "npm pack failed: " + ok)
result
}
)
lazy val tablesJVM = tables.jvm
lazy val tablesJS = tables.js
def dynamicScriptsResourceSettings(projectName: String): Seq[Setting[_]] = {
import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport._
def addIfExists(f: File, name: String): Seq[(File, String)] =
if (!f.exists) Seq()
else Seq((f, name))
val QUALIFIED_NAME = "^[a-zA-Z][\\w_]*(\\.[a-zA-Z][\\w_]*)*$".r
Seq(
// the '*-resource.zip' archive will start from: 'dynamicScripts/<dynamicScriptsProjectName>'
com.typesafe.sbt.packager.Keys.topLevelDirectory in Universal := None,
// name the '*-resource.zip' in the same way as other artifacts
com.typesafe.sbt.packager.Keys.packageName in Universal :=
// normalizedName.value + "_" + scalaBinaryVersion.value + "-" + version.value + "-resource",
projectName + "_" + scalaBinaryVersion.value + "-" + version.value + "-resource",
// contents of the '*-resource.zip' to be produced by 'universal:packageBin'
mappings in Universal in packageBin ++= {
val dir = baseDirectory.value
val bin = (packageBin in Compile).value
val src = (packageSrc in Compile).value
val doc = (packageDoc in Compile).value
val binT = (packageBin in Test).value
val srcT = (packageSrc in Test).value
val docT = (packageDoc in Test).value
(dir * ".classpath").pair(rebase(dir, projectName)) ++
(dir * "*.md").pair(rebase(dir, projectName)) ++
(dir / "resources" ***).pair(rebase(dir, projectName)) ++
addIfExists(bin, projectName + "/lib/" + bin.name) ++
addIfExists(binT, projectName + "/lib/" + binT.name) ++
addIfExists(src, projectName + "/lib.sources/" + src.name) ++
addIfExists(srcT, projectName + "/lib.sources/" + srcT.name) ++
addIfExists(doc, projectName + "/lib.javadoc/" + doc.name) ++
addIfExists(docT, projectName + "/lib.javadoc/" + docT.name)
},
artifacts += {
val n = projectName // (name in Universal).value
Artifact(n, "zip", "zip", Some("resource"), Seq(), None, Map())
},
packagedArtifacts += {
val p = (packageBin in Universal).value
val n = projectName // (name in Universal).value
Artifact(n, "zip", "zip", Some("resource"), Seq(), None, Map()) -> p
}
)
}