forked from guardrail-dev/guardrail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
307 lines (279 loc) · 13.4 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
val projectName = "guardrail-root"
name := projectName
organization in ThisBuild := "com.twilio"
licenses in ThisBuild += ("MIT", url("http://opensource.org/licenses/MIT"))
// Project version is determined by sbt-git based on the most recent tag
// Publishing information is defined in `bintray.sbt`
enablePlugins(GitVersioning)
git.useGitDescribe := true
crossScalaVersions := Seq("2.11.12", "2.12.3")
scalaVersion in ThisBuild := crossScalaVersions.value.last
val akkaVersion = "10.0.14"
val catsVersion = "1.4.0"
val catsEffectVersion = "1.0.0"
val circeVersion = "0.10.1"
val http4sVersion = "0.19.0"
val scalatestVersion = "3.0.7"
val javaparserVersion = "3.7.1"
val endpointsVersion = "0.8.0"
val ahcVersion = "2.8.1"
val dropwizardVersion = "1.3.9"
val jerseyVersion = "2.25.1"
mainClass in assembly := Some("com.twilio.guardrail.CLI")
// (filename, prefix, tracing)
def sampleResource(name: String): java.io.File = file(s"modules/sample/src/main/resources/${name}")
val exampleCases: List[(java.io.File, String, Boolean, List[String])] = List(
(sampleResource("alias.yaml"), "alias", false, List.empty),
(sampleResource("contentType-textPlain.yaml"), "tests.contentTypes.textPlain", false, List.empty),
(sampleResource("custom-header-type.yaml"), "tests.customTypes.customHeader", false, List.empty),
(sampleResource("edgecases/defaults.yaml"), "edgecases.defaults", false, List.empty),
(sampleResource("formData.yaml"), "form", false, List.empty),
(sampleResource("issues/issue121.yaml"), "issues.issue121", false, List.empty),
(sampleResource("issues/issue127.yaml"), "issues.issue127", false, List.empty),
(sampleResource("issues/issue143.yaml"), "issues.issue143", false, List.empty),
(sampleResource("issues/issue148.yaml"), "issues.issue148", false, List.empty),
(sampleResource("issues/issue164.yaml"), "issues.issue164", false, List.empty),
(sampleResource("issues/issue215.yaml"), "issues.issue215", false, List.empty),
(sampleResource("issues/issue218.yaml"), "issues.issue218", false, List.empty),
(sampleResource("petstore.json"), "examples", false, List("--import", "support.PositiveLong")),
(sampleResource("plain.json"), "tests.dtos", false, List.empty),
(sampleResource("polymorphism.yaml"), "polymorphism", false, List.empty),
(sampleResource("raw-response.yaml"), "raw", false, List.empty),
(sampleResource("server1.yaml"), "tracer", true, List.empty),
(sampleResource("server2.yaml"), "tracer", true, List.empty),
(sampleResource("pathological-parameters.yaml"), "pathological", false, List.empty)
)
val exampleFrameworkSuites = Map(
"scala" -> List(
("akka-http", "akkaHttp", List("client", "server")),
("endpoints", "endpoints", List("client")),
("http4s", "http4s", List("client", "server"))
),
"java" -> List(
("dropwizard", "dropwizard", List("client", "server"))
)
)
def exampleArgs(language: String): List[List[String]] = exampleCases
.foldLeft(List[List[String]](List(language)))({
case (acc, (path, prefix, tracing, extra)) =>
acc ++ (for {
frameworkSuite <- exampleFrameworkSuites(language)
(frameworkName, frameworkPackage, kinds) = frameworkSuite
kind <- kinds
tracingFlag = if (tracing && language != "java") Option("--tracing") else Option.empty[String]
} yield
(
List(s"--${kind}") ++
List("--specPath", path.toString()) ++
List("--outputPath", s"modules/sample-${frameworkPackage}/target/generated") ++
List("--packageName", s"${prefix}.${kind}.${frameworkPackage}") ++
List("--framework", frameworkName)
) ++ tracingFlag ++ extra)
})
lazy val runJavaExample: TaskKey[Unit] = taskKey[Unit]("Run scala generator with example args")
fullRunTask(
runJavaExample,
Test,
"com.twilio.guardrail.CLI",
exampleArgs("java").flatten.filter(_.nonEmpty): _*
)
lazy val runScalaExample: TaskKey[Unit] = taskKey[Unit]("Run scala generator with example args")
fullRunTask(
runScalaExample,
Test,
"com.twilio.guardrail.CLI",
exampleArgs("scala").flatten.filter(_.nonEmpty): _*
)
artifact in (Compile, assembly) := {
(artifact in (Compile, assembly)).value
.withClassifier(Option("assembly"))
}
addArtifact(artifact in (Compile, assembly), assembly)
val resetSample = TaskKey[Unit]("resetSample", "Reset sample module")
val scalaFrameworks = exampleFrameworkSuites("scala").map(_._2)
val javaFrameworks = exampleFrameworkSuites("java").map(_._2)
resetSample := {
import scala.sys.process._
(List("sample") ++ (scalaFrameworks ++ javaFrameworks).map(x => s"sample-${x}"))
.foreach(sampleName => s"git clean -fdx modules/${sampleName}/target/generated" !)
}
// Deprecated command
addCommandAlias("example", "runtimeSuite")
addCommandAlias("cli", "runMain com.twilio.guardrail.CLI")
addCommandAlias("runtimeScalaSuite", "; resetSample ; runScalaExample ; " + scalaFrameworks.map(x => s"${x}Sample/test").mkString("; "))
addCommandAlias("runtimeJavaSuite", "; resetSample ; runJavaExample ; " + javaFrameworks.map(x => s"${x}Sample/test").mkString("; "))
addCommandAlias("runtimeSuite", "; runtimeScalaSuite ; runtimeJavaSuite")
addCommandAlias("scalaTestSuite", "; codegen/test ; runtimeScalaSuite")
addCommandAlias("javaTestSuite", "; codegen/test ; runtimeJavaSuite")
addCommandAlias("format", "; codegen/scalafmt ; codegen/test:scalafmt ; " + scalaFrameworks.map(x => s"${x}Sample/scalafmt ; ${x}Sample/test:scalafmt").mkString("; "))
addCommandAlias("checkFormatting", "; codegen/scalafmtCheck ; " + scalaFrameworks.map(x => s"${x}Sample/scalafmtCheck ; ${x}Sample/test:scalafmtCheck").mkString("; "))
addCommandAlias("testSuite", "; scalaTestSuite ; javaTestSuite")
addCommandAlias(
"publishBintray",
"; set publishTo in codegen := (publishTo in bintray in codegen).value; codegen/publishSigned"
)
addCommandAlias(
"publishSonatype",
"; set publishTo in codegen := (sonatypePublishTo in codegen).value; codegen/publishSigned"
)
resolvers += Resolver.sonatypeRepo("releases")
addCompilerPlugin("org.spire-math" % "kind-projector" % "0.9.10" cross CrossVersion.binary)
publishMavenStyle := true
val testDependencies = Seq(
"org.scalatest" %% "scalatest" % scalatestVersion % Test
)
val excludedWarts = Set(Wart.DefaultArguments, Wart.Product, Wart.Serializable, Wart.Any)
val codegenSettings = Seq(
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.10"),
wartremoverWarnings in Compile ++= Warts.unsafe.filterNot(w => excludedWarts.exists(_.clazz == w.clazz)),
wartremoverWarnings in Test := List.empty,
scalacOptions in ThisBuild ++= Seq(
"-Ypartial-unification",
"-Ydelambdafy:method",
"-feature",
"-unchecked",
"-deprecation",
"-encoding",
"utf8"
) ++ (if (scalaVersion.value.startsWith("2.11.")) {
List("-Xexperimental", "-Xlint:_")
} else {
List("-Xlint:-unused,_")
}),
parallelExecution in Test := true
)
lazy val root = (project in file("."))
.settings(
libraryDependencies ++= testDependencies,
skip in publish := true
)
.dependsOn(codegen)
lazy val codegen = (project in file("modules/codegen"))
.settings(
(name := "guardrail") +:
codegenSettings,
libraryDependencies ++= testDependencies ++ Seq(
"org.scalameta" %% "scalameta" % "4.1.0",
"com.github.javaparser" % "javaparser-symbol-solver-core" % javaparserVersion,
"com.google.googlejavaformat" % "google-java-format" % "1.6",
"io.swagger.parser.v3" % "swagger-parser" % "2.0.8",
"org.tpolecat" %% "atto-core" % "0.6.3",
"org.typelevel" %% "cats-core" % catsVersion,
"org.typelevel" %% "cats-kernel" % catsVersion,
"org.typelevel" %% "cats-macros" % catsVersion,
"org.typelevel" %% "cats-free" % catsVersion,
"org.scala-lang.modules" %% "scala-java8-compat" % "0.9.0",
),
scalacOptions += "-language:higherKinds",
bintrayRepository := {
if (isSnapshot.value) "snapshots"
else "releases"
},
bintrayPackageLabels := Seq(
"codegen",
"openapi",
"swagger"
),
description := "Principled code generation for Scala services from OpenAPI specifications",
homepage := Some(url("https://github.com/twilio/guardrail")),
scmInfo := Some(
ScmInfo(
url("https://github.com/twilio/guardrail"),
"scm:[email protected]:twilio/guardrail.git"
)
),
developers := List(
Developer(
id = "blast_hardcheese",
name = "Devon Stewart",
email = "[email protected]",
url = url("http://hardchee.se/")
)
)
)
lazy val akkaHttpSample = (project in file("modules/sample-akkaHttp"))
.settings(
codegenSettings,
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % akkaVersion,
"com.typesafe.akka" %% "akka-http-testkit" % akkaVersion,
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-generic" % circeVersion,
"io.circe" %% "circe-java8" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
"org.typelevel" %% "cats-core" % catsVersion
),
unmanagedSourceDirectories in Compile += baseDirectory.value / "target" / "generated",
skip in publish := true,
scalafmtOnCompile := false
)
lazy val http4sSample = (project in file("modules/sample-http4s"))
.settings(
codegenSettings,
libraryDependencies ++= Seq(
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-generic" % circeVersion,
"io.circe" %% "circe-java8" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
"org.http4s" %% "http4s-blaze-client" % http4sVersion,
"org.http4s" %% "http4s-blaze-server" % http4sVersion,
"org.http4s" %% "http4s-circe" % http4sVersion,
"org.http4s" %% "http4s-dsl" % http4sVersion,
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
"org.typelevel" %% "cats-core" % catsVersion,
"org.typelevel" %% "cats-effect" % catsEffectVersion
),
unmanagedSourceDirectories in Compile += baseDirectory.value / "target" / "generated",
skip in publish := true,
scalafmtOnCompile := false
)
lazy val endpointsSample = (project in file("modules/sample-endpoints"))
.enablePlugins(ScalaJSPlugin)
.settings(
codegenSettings,
libraryDependencies ++= Seq(
"io.circe" %%% "circe-core" % circeVersion,
"io.circe" %%% "circe-generic" % circeVersion,
"io.circe" %%% "circe-java8" % circeVersion,
"io.circe" %%% "circe-parser" % circeVersion,
"io.github.cquiroz" %%% "scala-java-time" % "2.0.0-M13",
"org.julienrf" %%% "endpoints-algebra" % endpointsVersion,
"org.julienrf" %%% "endpoints-json-schema-generic" % endpointsVersion,
"org.julienrf" %%% "endpoints-xhr-client" % endpointsVersion,
"org.julienrf" %%% "endpoints-xhr-client-circe" % endpointsVersion,
"org.julienrf" %%% "endpoints-xhr-client-faithful" % endpointsVersion,
"org.scalatest" %%% "scalatest" % scalatestVersion % Test,
"org.typelevel" %%% "cats-core" % catsVersion
),
unmanagedSourceDirectories in Compile += baseDirectory.value / "target" / "generated",
skip in publish := true,
scalafmtOnCompile := false
)
lazy val dropwizardSample = (project in file("modules/sample-dropwizard"))
.settings(
codegenSettings,
javacOptions ++= Seq(
"-Xlint:all"
),
testOptions in Test += Tests.Argument(TestFrameworks.JUnit, "-a", "-v"),
libraryDependencies ++= Seq(
"io.dropwizard" % "dropwizard-core" % dropwizardVersion,
"org.glassfish.jersey.media" % "jersey-media-multipart" % jerseyVersion,
"org.asynchttpclient" % "async-http-client" % ahcVersion,
"org.scala-lang.modules" %% "scala-java8-compat" % "0.9.0" % Test,
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
"junit" % "junit" % "4.12" % Test,
"com.novocode" % "junit-interface" % "0.11" % Test,
"org.mockito" %% "mockito-scala" % "1.2.0" % Test,
"io.dropwizard" % "dropwizard-testing" % dropwizardVersion % Test,
"org.glassfish.jersey.test-framework.providers" % "jersey-test-framework-provider-grizzly2" % jerseyVersion % Test
),
unmanagedSourceDirectories in Compile += baseDirectory.value / "target" / "generated",
crossPaths := false, // strangely needed to get the JUnit tests to run at all
skip in publish := true,
scalafmtOnCompile := false
)
watchSources ++= (baseDirectory.value / "modules/sample/src/test" ** "*.scala").get
watchSources ++= (baseDirectory.value / "modules/sample/src/test" ** "*.java").get
logBuffered in Test := false