-
Notifications
You must be signed in to change notification settings - Fork 225
Expand file tree
/
Copy pathbuild.sbt
More file actions
316 lines (297 loc) · 9.45 KB
/
build.sbt
File metadata and controls
316 lines (297 loc) · 9.45 KB
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
import Dependencies._
import scala.sys.process.ProcessLogger
val g8version = "0.18.0-SNAPSHOT"
val javaVmArgs: List[String] = {
import scala.collection.JavaConverters._
java.lang.management.ManagementFactory.getRuntimeMXBean.getInputArguments.asScala.toList
}
val coursierBootstrap = taskKey[File]("create bootstrap jar")
val coursierBootstrapBatch = taskKey[File]("create bootstrap jar")
val coursierBootstrapTest = taskKey[Unit]("test bootstrap jar")
val sbtLauncherVersion = settingKey[String]("")
ThisBuild / organization := "org.foundweekends.giter8"
ThisBuild / version := g8version
ThisBuild / scalaVersion := scala212
ThisBuild / organizationName := "foundweekends"
ThisBuild / organizationHomepage := Some(url("https://foundweekends.org/"))
ThisBuild / Compile / packageBin / publishArtifact := true
ThisBuild / homepage := Some(url("https://www.foundweekends.org/giter8/"))
ThisBuild / publishMavenStyle := true
ThisBuild / Test / publishArtifact := false
ThisBuild / Test / parallelExecution := false
ThisBuild / licenses := Seq("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt"))
ThisBuild / developers := List(
Developer("n8han", "Nathan Hamblen", "@n8han", url("https://github.com/n8han")),
Developer("eed3si9n", "Eugene Yokota", "@eed3si9n", url("https://github.com/eed3si9n"))
)
ThisBuild / scmInfo := Some(
ScmInfo(url("https://github.com/foundweekends/giter8"), "git@github.com:foundweekends/giter8.git")
)
lazy val commonSettings = Def.settings(
scalacOptions ++= Seq("-deprecation"),
scalacOptions ++= {
scalaBinaryVersion.value match {
case "3" =>
Nil
case _ =>
Seq("-Xlint")
}
},
scalacOptions ++= {
scalaBinaryVersion.value match {
case "3" =>
Nil
case "2.13" =>
Seq("-Xsource:3-cross")
case _ =>
Seq("-Xsource:3", "-Xfuture")
}
}
)
lazy val root = (project in file("."))
.enablePlugins(G8SitePlugin, NoPublish)
.aggregate(
Seq(
app,
bootstrap,
lib,
scaffold,
plugin,
gitsupport,
launcher
).flatMap(_.projectRefs) *
)
.settings(
commonSettings,
crossScalaVersions := Nil,
publish / skip := true,
customCommands
)
lazy val app = (projectMatrix in file("app"))
.enablePlugins(SonatypePublish)
.defaultAxes(VirtualAxis.jvm)
.dependsOn(lib, gitsupport)
.settings(
commonSettings,
description := "Command line tool to apply templates defined on GitHub",
name := "giter8",
csRun / sourceDirectory := {
(baseDirectory).value.getParentFile / "src" / "main" / "conscript"
},
libraryDependencies ++= List(
launcherIntf,
slf4jsimple
)
)
.jvmPlatform(
scalaVersions = Seq(scala212, scala213, scala3)
)
lazy val crossSbt = Seq(
pluginCrossBuild / sbtVersion := {
scalaBinaryVersion.value match {
case "2.12" => sbt1
case _ => "2.0.0-RC8"
}
}
)
lazy val scaffold = (projectMatrix in file("scaffold"))
.enablePlugins(SbtPlugin, SonatypePublish)
.defaultAxes(VirtualAxis.jvm)
.dependsOn(lib)
.settings(crossSbt)
.settings(
commonSettings,
name := "sbt-giter8-scaffold",
description := "sbt plugin for scaffolding giter8 templates",
sbtPlugin := true,
scriptedLaunchOpts ++= javaVmArgs.filter(a => Seq("-Xmx", "-Xms", "-XX").exists(a.startsWith)),
scriptedBufferLog := false,
scriptedLaunchOpts += ("-Dplugin.version=" + version.value)
)
.jvmPlatform(
scalaVersions = Seq(scala212, scala3)
)
lazy val plugin = (projectMatrix in file("plugin"))
.enablePlugins(SbtPlugin, SonatypePublish)
.defaultAxes(VirtualAxis.jvm)
.dependsOn(lib)
.settings(crossSbt)
.settings(
commonSettings,
name := "sbt-giter8",
description := "sbt plugin for testing giter8 templates",
sbtPlugin := true,
scriptedLaunchOpts ++= javaVmArgs.filter(a => Seq("-Xmx", "-Xms", "-XX").exists(a.startsWith)),
scriptedBufferLog := false,
scriptedLaunchOpts += ("-Dplugin.version=" + version.value)
)
.jvmPlatform(
scalaVersions = Seq(scala212, scala3)
)
lazy val gitsupport = (projectMatrix in file("cli-git"))
.enablePlugins(BuildInfoPlugin, SonatypePublish)
.defaultAxes(VirtualAxis.jvm)
.settings(
commonSettings,
description := "cli and git support library for Giter8",
name := "giter8-cli-git",
sbtLauncherVersion := launcherIntf.revision,
libraryDependencies ++= Seq(
scopt,
jgit,
jgitSshApache,
commonsIo,
scalamock % Test
),
libraryDependencies ++= scalatest,
run / fork := true,
buildInfoKeys := Seq(name, version, scalaVersion, sbtVersion, scalaBinaryVersion, sbtLauncherVersion),
buildInfoPackage := "giter8"
)
.jvmPlatform(
scalaVersions = Seq(scala212, scala213, scala3)
)
lazy val lib = (projectMatrix in file("library"))
.enablePlugins(SonatypePublish)
.defaultAxes(VirtualAxis.jvm)
.dependsOn(gitsupport)
.settings(crossSbt)
.settings(
commonSettings,
name := "giter8-lib",
description := "shared library for app and plugin",
libraryDependencies ++= scalatest,
libraryDependencies ++= Seq(
stringTemplate,
jgit,
slf4jsimple,
commonsIo,
scalaXml,
parserCombinator(scalaVersion.value),
scalacheck % Test,
sbtIo % Test,
scalamock % Test
),
Test / testOptions += Tests.Argument(TestFrameworks.ScalaCheck, "-minSuccessfulTests", "1000", "-workers", "10")
)
.jvmPlatform(
scalaVersions = Seq(scala212, scala213, scala3)
)
lazy val launcher = (projectMatrix in file("launcher"))
.enablePlugins(SonatypePublish)
.enablePlugins(ConscriptPlugin)
.defaultAxes(VirtualAxis.jvm)
.dependsOn(gitsupport)
.settings(
commonSettings,
description := "Command line tool to apply templates defined on GitHub",
name := "giter8-launcher",
libraryDependencies ++= Seq(
coursier,
slf4jsimple,
verify % Test,
sbtIo % Test
),
testFrameworks += new TestFramework("verify.runner.Framework"),
run / fork := true,
Test / fork := true,
Test / javaOptions ++= Seq(s"""-DG8_HOME=${target.value / "home"}""")
// assemblyMergeStrategy in assembly := {
// case "plugin.properties" => MergeStrategy.concat
// case "module-info.class" => MergeStrategy.discard
// case x =>
// val oldStrategy = (assemblyMergeStrategy in assembly).value
// oldStrategy(x)
// },
)
.jvmPlatform(
scalaVersions = Seq(scala212, scala213, scala3)
)
lazy val bootstrap = (projectMatrix in file("bootstrap"))
.enablePlugins(SonatypePublish)
.defaultAxes(VirtualAxis.jvm)
.settings(
commonSettings,
description := "Bootstrap script for Giter8 launcher",
name := "giter8-bootstrap",
libraryDependencies += Dependencies.coursierCli % Test,
coursierBootstrap := Def.taskDyn {
val t = target.value / "g8"
val v = version.value
(Test / runMain)
.toTask(
Seq(
"coursier.cli.Coursier",
"bootstrap",
s"org.foundweekends.giter8:giter8-launcher_3:$v",
"--main",
"giter8.LauncherMain",
"-o",
t.getAbsolutePath,
"--bat",
"-f"
).mkString(" ", " ", "")
)
.map((_: Unit) => t)
}.value,
coursierBootstrap := coursierBootstrap
.dependsOn(Def.task {
(launcher.jvm(Dependencies.scala3) / publishLocal).value
(gitsupport.jvm(Dependencies.scala3) / publishLocal).value
})
.value,
coursierBootstrapBatch := {
val _ = coursierBootstrap.value
target.value / "g8.bat"
},
coursierBootstrap / artifact := {
val o = (coursierBootstrap / artifact).value
o.withExtension("sh")
},
coursierBootstrapBatch / artifact := {
val o = (coursierBootstrapBatch / artifact).value
o.withExtension("bat")
},
coursierBootstrapTest := {
case class Res(out: Seq[String], err: Seq[String], exitCoce: Int)
def runWithLog(p: sys.process.ProcessBuilder): Res = {
val outLog = List.newBuilder[String]
val errLog = List.newBuilder[String]
val res = p
.!(new ProcessLogger {
override def out(s: => String): Unit = outLog += s
override def err(s: => String): Unit = errLog += s
override def buffer[T](f: => T) = f
})
Res(outLog.result(), errLog.result(), res)
}
val binary = Def.taskIf {
if (scala.util.Properties.isWin) {
coursierBootstrapBatch.value.getAbsolutePath
} else {
coursierBootstrap.value.getAbsolutePath
}
}.value
val res1 = runWithLog(sys.process.Process(binary))
assert(res1.exitCoce == 1)
assert(res1.err.contains("Error: Missing argument <template>"), res1.err)
assert(res1.err.contains("Try --help for more information."), res1.err)
val res2 = runWithLog(sys.process.Process(binary, Seq("--help")))
assert(res2.exitCoce == 0)
assert(res2.out.contains("Usage: g8 [options] <template>"))
},
Test / test := {
coursierBootstrapTest.value
(Test / test).value
},
addArtifact(coursierBootstrap / artifact, coursierBootstrap),
addArtifact(coursierBootstrapBatch / artifact, coursierBootstrapBatch)
)
.jvmPlatform(
scalaVersions = Seq(scala3)
)
def customCommands: Seq[Setting[?]] = Seq(
commands += Command.command("release") { state =>
"clean" :: "publishSigned" :: "sonaRelease" :: "reload" :: state
}
)