-
Notifications
You must be signed in to change notification settings - Fork 185
/
ScalafixBuild.scala
310 lines (300 loc) · 9.96 KB
/
ScalafixBuild.scala
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
import Dependencies._
import sbt._
import sbt.Keys._
import sbt.plugins.JvmPlugin
import com.typesafe.tools.mima.plugin.MimaPlugin.autoImport._
import tut.TutPlugin.autoImport._
import microsites.MicrositesPlugin.autoImport._
import sbtunidoc.BaseUnidocPlugin.autoImport._
import sbtunidoc.ScalaUnidocPlugin.autoImport._
import com.typesafe.sbt.site.SitePlugin.autoImport._
import microsites.ConfigYml
import sbtbuildinfo.BuildInfoKey
import sbtbuildinfo.BuildInfoPlugin.autoImport._
import com.typesafe.sbt.sbtghpages.GhpagesKeys
import sbt.Def
import sbt.plugins.IvyPlugin
object ScalafixBuild extends AutoPlugin with GhpagesKeys {
override def trigger = allRequirements
override def requires = JvmPlugin && IvyPlugin
object autoImport {
lazy val stableVersion =
settingKey[String]("Version of latest release to Maven.")
lazy val noMima = Seq(
mimaReportBinaryIssues := {},
mimaPreviousArtifacts := Set.empty
)
lazy val noPublish = Seq(
skip in publish := true
) ++ noMima
lazy val supportedScalaVersions = List(scala211, scala212)
lazy val isFullCrossVersion = Seq(
crossVersion := CrossVersion.full
)
lazy val isScala213 = Def.setting { scalaVersion.value.startsWith("2.13") }
lazy val warnUnusedImports = Def.setting {
if (isScala213.value) "-Ywarn-unused:imports"
else "-Ywarn-unused-import"
}
lazy val scaladocOptions = Seq(
"-groups",
"-implicits"
)
lazy val compilerOptions = Def.setting(
Seq(
"-target:jvm-1.8",
warnUnusedImports.value,
"-encoding",
"UTF-8",
"-feature",
"-unchecked"
)
)
lazy val buildInfoSettings: Seq[Def.Setting[_]] = Seq(
buildInfoKeys := Seq[BuildInfoKey](
name,
version,
stableVersion,
"coursier" -> coursierV,
"nightly" -> version.value,
"scalameta" -> scalametaV,
scalaVersion,
"supportedScalaVersions" -> supportedScalaVersions,
"scala211" -> scala211,
"scala212" -> scala212,
"scala213" -> scala213,
sbtVersion
),
buildInfoPackage := "scalafix",
buildInfoObject := "Versions"
)
lazy val testsInputOutputSetting = Seq(
libraryDependencies ++= testsDeps
)
lazy val semanticdbSettings = Seq(
scalacOptions ++= List(
"-Yrangepos",
"-Xplugin-require:semanticdb",
"-P:semanticdb:synthetics:on"
),
addCompilerPlugin(
"org.scalameta" % "semanticdb-scalac" % scalametaV cross CrossVersion.full
)
)
// =======
// Website
// =======
lazy val docsMappingsAPIDir = settingKey[String](
"Name of subdirectory in site target directory for api docs"
)
lazy val unidocSettings = Seq(
autoAPIMappings := true,
apiURL := Some(url("https://scalacenter.github.io/docs/api/")),
docsMappingsAPIDir := "docs/api",
addMappingsToSiteDir(
mappings in (ScalaUnidoc, packageDoc),
docsMappingsAPIDir
),
scalacOptions in (ScalaUnidoc, unidoc) ++= Seq(
"-doc-source-url",
scmInfo.value.get.browseUrl + "/tree/master€{FILE_PATH}.scala",
"-sourcepath",
baseDirectory.in(LocalRootProject).value.getAbsolutePath,
"-skip-packages",
"ammonite:org:scala:scalafix.tests:scalafix.internal"
),
fork in (ScalaUnidoc, unidoc) := true
)
lazy val websiteSettings = Seq(
micrositeName := "scalafix",
micrositeDescription := "Rewrite and linting tool for Scala",
micrositeBaseUrl := "scalafix",
micrositeDocumentationUrl := "docs/users/installation",
micrositeHighlightTheme := "atom-one-light",
micrositeHomepage := "https://scalacenter.github.io/scalafix/",
micrositeOrganizationHomepage := "https://scala.epfl.ch/",
micrositeTwitterCreator := "@scala_lang",
micrositeGithubOwner := "scalacenter",
micrositeGithubRepo := "scalafix",
ghpagesNoJekyll := false,
micrositeGitterChannel := true,
micrositeFooterText := None,
micrositeFooterText := Some(
"""
|<p>© 2017 <a href="https://github.com/scalacenter/scalafix#team">The Scalafix Maintainers</a></p>
|<p style="font-size: 80%; margin-top: 10px">Website built with <a href="https://47deg.github.io/sbt-microsites/">sbt-microsites © 2016 47 Degrees</a></p>
|""".stripMargin
),
micrositePalette := Map(
"brand-primary" -> "#0D2B35",
"brand-secondary" -> "#203F4A",
"brand-tertiary" -> "#0D2B35",
"gray-dark" -> "#453E46",
"gray" -> "rgba(0,0,0,.8)",
"gray-light" -> "#E3E2E3",
"gray-lighter" -> "#F4F3F4",
"white-color" -> "#FFFFFF"
),
micrositeConfigYaml := ConfigYml(
yamlCustomProperties = Map(
"githubOwner" -> micrositeGithubOwner.value,
"githubRepo" -> micrositeGithubRepo.value,
"docsUrl" -> "docs",
"callToActionText" -> "Get started",
"callToActionUrl" -> micrositeDocumentationUrl.value,
"scala212" -> scala212,
"scala211" -> scala211,
"stableVersion" -> stableVersion.value,
"scalametaVersion" -> scalametaV,
"supportedScalaVersions" -> supportedScalaVersions,
"coursierVersion" -> coursierV
)
),
fork in tut := true
)
}
import autoImport._
// Custom settings to publish scalafix forks to alternative maven repo.
lazy val adhocRepoUri = sys.props("scalafix.repository.uri")
lazy val adhocRepoCredentials = sys.props("scalafix.repository.credentials")
lazy val isCustomRepository = adhocRepoUri != null && adhocRepoCredentials != null
override def globalSettings: Seq[Def.Setting[_]] = List(
stableVersion := version.in(ThisBuild).value.replaceFirst("\\+.*", ""),
libraryDependencies ++= List(
scalacheck % Test,
scalatest % Test
),
resolvers ++= List(
Resolver.sonatypeRepo("snapshots"),
Resolver.sonatypeRepo("public"),
Resolver.mavenLocal
),
testOptions in Test += Tests.Argument("-oD"),
updateOptions := updateOptions.value.withCachedResolution(true),
triggeredMessage in ThisBuild := Watched.clearWhenTriggered,
commands += Command.command("save-expect") { s =>
"unit/test:runMain scalafix.tests.util.SaveExpect" ::
s
},
commands += Command.command("ci-213") { s =>
s"++$scala213" ::
"unit/test" ::
s
},
commands += Command.command("ci-212") { s =>
s"++$scala212" ::
"unit/test" ::
"docs/run" ::
"interfaces/doc" ::
s
},
commands += Command.command("ci-211") { s =>
s"++$scala211" ::
"unit/test" ::
s
},
commands += Command.command("ci-212-windows") { s =>
s"++$scala212" ::
s"unit/testOnly -- -l scalafix.internal.tests.utils.SkipWindows" ::
s
},
commands += Command.command("mima") { s =>
// Disabled until v0.6.0 stable
// "scalafix/mimaReportBinaryIssues" ::
// "scalafix211/mimaReportBinaryIssues" ::
s
},
// There is flakyness in CliGitDiffTests and CliSemanticTests
parallelExecution.in(Test) := false,
credentials ++= {
val credentialsFile = {
if (adhocRepoCredentials != null) new File(adhocRepoCredentials)
else null
}
if (credentialsFile != null) List(new FileCredentials(credentialsFile))
else Nil
},
publishArtifact.in(Test) := false,
licenses := Seq(
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")
),
homepage := Some(url("https://github.com/scalacenter/scalafix")),
autoAPIMappings := true,
apiURL := Some(url("https://scalacenter.github.io/scalafix/")),
organization := "ch.epfl.scala",
developers ++= List(
Developer(
"xeno-by",
"Eugene Burmako",
url("http://xeno.by")
),
Developer(
"gabro",
"Gabriele Petronella",
url("https://buildo.io")
),
Developer(
"MasseGuillaume",
"Guillaume Massé",
url("https://github.com/MasseGuillaume")
),
Developer(
"olafurpg",
"Ólafur Páll Geirsson",
url("https://geirsson.com")
),
Developer(
"marcelocenerine",
"Marcelo Cenerino",
url("https://github.com/marcelocenerine")
),
Developer(
"ShaneDelmore",
"Shane Delmore",
url("https://github.com/shanedelmore")
)
)
)
private val PreviousScalaVersion = Map(
"2.11.12" -> "2.11.11",
"2.12.4" -> "2.12.3",
"2.12.8" -> "2.12.7",
"2.12.10" -> "2.12.8"
)
override def projectSettings: Seq[Def.Setting[_]] = List(
scalacOptions ++= compilerOptions.value,
scalacOptions.in(Compile, console) :=
compilerOptions.value :+ "-Yrepl-class-based",
scalacOptions.in(Compile, doc) ++= scaladocOptions,
publishTo := Some {
if (isCustomRepository) "adhoc" at adhocRepoUri
else if (isSnapshot.value) Opts.resolver.sonatypeSnapshots
else Opts.resolver.sonatypeStaging
},
scmInfo := Some(
ScmInfo(
url("https://github.com/scalacenter/scalafix"),
"scm:git:[email protected]:scalacenter/scalafix.git"
)
),
mimaPreviousArtifacts := {
val previousArtifactVersion = "0.9.6"
// NOTE(olafur) shudder, can't figure out simpler way to do the same.
val binaryVersion =
if (crossVersion.value.isInstanceOf[CrossVersion.Full]) {
val version = scalaVersion.value
PreviousScalaVersion.getOrElse(version, version)
} else scalaBinaryVersion.value
Set(
organization.value % s"${moduleName.value}_$binaryVersion" % previousArtifactVersion
)
},
mimaBinaryIssueFilters ++= Mima.ignoredABIProblems
)
}