You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

343 lines
12 KiB

9 years ago
9 years ago
9 years ago
  1. import sbt._
  2. import Keys._
  3. import com.typesafe.sbt.SbtSite.site
  4. import sbtrelease.ReleasePlugin._
  5. import scala.util.Properties.envOrNone
  6. import com.typesafe.sbteclipse.plugin.EclipsePlugin._
  7. import Helpers._
  8. sealed trait Basics {
  9. final val buildOrganization = "org.gerweck.scala"
  10. final val buildScalaVersion = "2.11.7"
  11. final val extraScalaVersions = Seq.empty
  12. final val buildJavaVersion = "1.8"
  13. lazy val defaultOptimize = true
  14. final val projectMainClass = None
  15. lazy val parallelBuild = false
  16. lazy val cachedResolution = false
  17. /* Metadata definitions */
  18. lazy val buildMetadata = Vector(
  19. licenses := Seq("Apache License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")),
  20. homepage := Some(url("https://github.com/sarahgerweck/scalafx-utils")),
  21. description := "ScalaFX Utilities",
  22. startYear := Some(2015),
  23. scmInfo := Some(ScmInfo(url("https://github.com/sarahgerweck/scalafx-utils"), "scm:git:git@github.com:sarahgerweck/scalafx-utils.git"))
  24. )
  25. }
  26. object BuildSettings extends Basics {
  27. /* Overridable flags */
  28. lazy val optimize = boolFlag("OPTIMIZE") orElse boolFlag("OPTIMISE") getOrElse defaultOptimize
  29. lazy val deprecation = boolFlag("NO_DEPRECATION") map (!_) getOrElse true
  30. lazy val inlineWarn = boolFlag("INLINE_WARNINGS") getOrElse false
  31. lazy val debug = boolFlag("DEBUGGER") getOrElse false
  32. lazy val debugPort = envOrNone("DEBUGGER_PORT") map { _.toInt } getOrElse 5050
  33. lazy val debugSuspend = boolFlag("DEBUGGER_SUSPEND") getOrElse true
  34. lazy val unusedWarn = boolFlag("UNUSED_WARNINGS") getOrElse false
  35. lazy val importWarn = boolFlag("IMPORT_WARNINGS") getOrElse false
  36. /* Scala build setup */
  37. lazy val buildScalaVersions = buildScalaVersion +: extraScalaVersions
  38. val buildScalacOptions = Seq (
  39. "-unchecked",
  40. "-feature",
  41. "-target:jvm-" + buildJavaVersion
  42. ) ++ (
  43. if (deprecation) Seq("-deprecation") else Seq.empty
  44. ) ++ (
  45. if (optimize) Seq("-optimize") else Seq.empty
  46. ) ++ (
  47. if (inlineWarn) Seq("-Yinline-warnings") else Seq.empty
  48. ) ++ (
  49. if (unusedWarn) Seq("-Ywarn-unused") else Seq.empty
  50. ) ++ (
  51. if (importWarn) Seq("-Ywarn-unused-import") else Seq.empty
  52. )
  53. /* Java build setup */
  54. val buildJavacOptions = Seq(
  55. "-target", buildJavaVersion,
  56. "-source", buildJavaVersion
  57. ) ++ (
  58. if (deprecation) Seq("-Xlint:deprecation") else Seq.empty
  59. )
  60. /* Site setup */
  61. lazy val siteSettings = site.settings ++ site.includeScaladoc()
  62. val buildSettings = buildMetadata ++
  63. siteSettings ++
  64. projectMainClass.toSeq.map(mainClass := Some(_)) ++
  65. Seq (
  66. organization := buildOrganization,
  67. scalaVersion := buildScalaVersion,
  68. crossScalaVersions := buildScalaVersions,
  69. scalacOptions ++= buildScalacOptions,
  70. javacOptions ++= buildJavacOptions,
  71. autoAPIMappings := true,
  72. updateOptions := updateOptions.value.withCachedResolution(cachedResolution),
  73. parallelExecution := parallelBuild,
  74. evictionWarningOptions in update :=
  75. EvictionWarningOptions.default.withWarnTransitiveEvictions(false).withWarnDirectEvictions(false).withWarnScalaVersionEviction(false)
  76. )
  77. }
  78. object Helpers {
  79. def getProp(name: String): Option[String] = sys.props.get(name) orElse sys.env.get(name)
  80. def parseBool(str: String): Boolean = Set("yes", "y", "true", "t", "1") contains str.trim.toLowerCase
  81. def boolFlag(name: String): Option[Boolean] = getProp(name) map { parseBool _ }
  82. def boolFlag(name: String, default: Boolean): Boolean = boolFlag(name) getOrElse default
  83. def opts(names: String*): Option[String] = names.view.map(getProp _).foldLeft(None: Option[String]) { _ orElse _ }
  84. import scala.xml._
  85. def excludePomDeps(exclude: (String, String) => Boolean): Node => Node = { node: Node =>
  86. val rewriteRule = new transform.RewriteRule {
  87. override def transform(n: Node): NodeSeq = {
  88. if ((n.label == "dependency") && exclude((n \ "groupId").text, (n \ "artifactId").text))
  89. NodeSeq.Empty
  90. else
  91. n
  92. }
  93. }
  94. val transformer = new transform.RuleTransformer(rewriteRule)
  95. transformer.transform(node)(0)
  96. }
  97. }
  98. object Resolvers {
  99. val sonatypeSnaps = Resolver.sonatypeRepo("snapshots")
  100. val sonatypeRelease = Resolver.sonatypeRepo("releases")
  101. val sonatypeStaging = Resolver.sonatypeRepo("staging")
  102. }
  103. object PublishSettings {
  104. import BuildSettings._
  105. import Resolvers._
  106. import Helpers._
  107. val sonaCreds = (
  108. for {
  109. user <- getProp("SONATYPE_USER")
  110. pass <- getProp("SONATYPE_PASS")
  111. } yield {
  112. credentials +=
  113. Credentials("Sonatype Nexus Repository Manager",
  114. "oss.sonatype.org",
  115. user, pass)
  116. }
  117. ).toSeq
  118. val publishSettings = sonaCreds ++ Seq (
  119. publishMavenStyle := true,
  120. pomIncludeRepository := { _ => false },
  121. publishArtifact in Test := false,
  122. publishTo := {
  123. if (version.value.trim endsWith "SNAPSHOT")
  124. Some(sonatypeSnaps)
  125. else
  126. Some(sonatypeStaging)
  127. },
  128. pomExtra := (
  129. <developers>
  130. <developer>
  131. <id>sarah</id>
  132. <name>Sarah Gerweck</name>
  133. <email>sarah.a180@gmail.com</email>
  134. <url>https://github.com/sarahgerweck</url>
  135. <timezone>America/Los_Angeles</timezone>
  136. </developer>
  137. </developers>
  138. )
  139. )
  140. /** Use this if you don't want to publish a certain module.
  141. * (SBT's release plugin doesn't handle this well.)
  142. */
  143. val falsePublishSettings = publishSettings ++ Seq (
  144. publishArtifact in Compile := false,
  145. publishArtifact in Test := false,
  146. publishTo := Some(Resolver.file("phony-repo", file("target/repo")))
  147. )
  148. }
  149. object Release {
  150. import sbtrelease._
  151. import ReleaseStateTransformations._
  152. import ReleasePlugin._
  153. import ReleaseKeys._
  154. import Utilities._
  155. import com.typesafe.sbt.SbtPgp.PgpKeys._
  156. val settings = releaseSettings ++ Seq (
  157. ReleaseKeys.crossBuild := true,
  158. ReleaseKeys.releaseProcess := Seq[ReleaseStep](
  159. checkSnapshotDependencies,
  160. inquireVersions,
  161. runTest,
  162. setReleaseVersion,
  163. commitReleaseVersion,
  164. tagRelease,
  165. publishArtifacts.copy(action = publishSignedAction),
  166. setNextVersion,
  167. commitNextVersion,
  168. pushChanges
  169. )
  170. )
  171. lazy val publishSignedAction = { st: State =>
  172. val extracted = st.extract
  173. val ref = extracted.get(thisProjectRef)
  174. extracted.runAggregated(publishSigned in Global in ref, st)
  175. }
  176. }
  177. object Eclipse {
  178. import com.typesafe.sbteclipse.plugin.EclipsePlugin._
  179. val settings = Seq (
  180. EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.Resource,
  181. EclipseKeys.projectFlavor := EclipseProjectFlavor.Scala,
  182. EclipseKeys.executionEnvironment := Some(EclipseExecutionEnvironment.JavaSE18),
  183. EclipseKeys.withSource := true,
  184. EclipseKeys.eclipseOutput := Some("target/scala-2.11/classes")
  185. )
  186. }
  187. object Dependencies {
  188. /* ********************************************************************** */
  189. /* Utility Dependencies */
  190. /* ********************************************************************** */
  191. final val slf4jVersion = "1.7.12"
  192. final val log4sVersion = "1.1.5"
  193. final val logbackVersion = "1.1.3"
  194. final val threeTenVersion = "1.3"
  195. final val commonsVfsVersion = "2.0"
  196. final val commonsIoVersion = "2.4"
  197. final val spireVersion = "0.9.1"
  198. final val groovyVersion = "2.4.4"
  199. final val scalaParserVersion = "1.0.4"
  200. final val scalaXmlVersion = "1.0.5"
  201. final val gerweckUtilVersion = "1.3.15"
  202. final val scalazVersion = "7.1.3"
  203. final val shapelessVersion = "2.2.5"
  204. final val scallopVersion = "0.9.5"
  205. val log4s = "org.log4s" %% "log4s" % log4sVersion
  206. val slf4j = "org.slf4j" % "slf4j-api" % slf4jVersion
  207. val jclBridge = "org.slf4j" % "jcl-over-slf4j" % slf4jVersion
  208. val log4jBridge = "org.slf4j" % "log4j-over-slf4j" % slf4jVersion
  209. val logback = "ch.qos.logback" % "logback-classic" % logbackVersion
  210. val threeTen = "org.threeten" % "threetenbp" % threeTenVersion
  211. val spire = "org.spire-math" %% "spire" % spireVersion
  212. val commonsIo = "commons-io" % "commons-io" % commonsIoVersion
  213. val groovy = "org.codehaus.groovy" % "groovy-all" % groovyVersion
  214. val gerweckUtil = "org.gerweck.scala" %% "gerweck-utils" % gerweckUtilVersion
  215. val scalaz = "org.scalaz" %% "scalaz-core" % scalazVersion
  216. val shapeless = "com.chuusai" %% "shapeless" % shapelessVersion
  217. val scallop = "org.rogach" %% "scallop" % scallopVersion
  218. val commonsVfs = {
  219. val base = "org.apache.commons" % "commons-vfs2" % commonsVfsVersion
  220. base.exclude("commons-logging", "commons-logging")
  221. .exclude("org.apache.maven.scm", "maven-scm-provider-svnexe")
  222. .exclude("org.apache.maven.scm", "maven-scm-api")
  223. base
  224. }
  225. /* Use like this: libraryDependencies <++= (scalaBinaryVersion) (scalaParser) */
  226. def scalaParser(optional: Boolean): String => Seq[ModuleID] = { scalaBinaryVersion: String =>
  227. optionalize(optional) {
  228. scalaBinaryVersion match {
  229. case "2.11" => Seq("org.scala-lang.modules" %% "scala-parser-combinators" % scalaParserVersion % "optional")
  230. case _ => Seq.empty
  231. }
  232. }
  233. }
  234. def scalaXml(optional: Boolean)(scalaBinaryVersion: String): String => Seq[ModuleID] = { scalaBinaryVersion: String =>
  235. optionalize(optional) {
  236. scalaBinaryVersion match {
  237. case "2.11" => Seq("org.scala-lang.modules" %% "scala-xml" % scalaXmlVersion % "optional")
  238. case _ => Seq.empty
  239. }
  240. }
  241. }
  242. /* ********************************************************************** */
  243. /* Testing Dependencies */
  244. /* ********************************************************************** */
  245. final val scalaCheckVersion = "1.12.2"
  246. final val scalaTestVersion = "2.2.4"
  247. val scalaCheck = "org.scalacheck" %% "scalacheck" % scalaCheckVersion
  248. val scalaTest = "org.scalatest" %% "scalatest" % scalaTestVersion
  249. /* ********************************************************************** */
  250. /* ScalaFX */
  251. /* ********************************************************************** */
  252. final val scalaFxVersion = "8.0.20-R6"
  253. val scalaFx = "org.scalafx" %% "scalafx" % scalaFxVersion
  254. /* ********************************************************************** */
  255. /* Helpers */
  256. /* ********************************************************************** */
  257. private[this] def optionalize(optional: Boolean)(f: => Seq[ModuleID]): Seq[ModuleID] = {
  258. if (optional) {
  259. f map { _ % "optional" }
  260. } else {
  261. f
  262. }
  263. }
  264. private[this] def noCL(m: ModuleID) = (
  265. m exclude("commons-logging", "commons-logging")
  266. exclude("commons-logging", "commons-logging-api")
  267. )
  268. }
  269. object UtilsBuild extends Build {
  270. build =>
  271. import BuildSettings._
  272. import Resolvers._
  273. import Dependencies._
  274. import PublishSettings._
  275. import Helpers._
  276. lazy val root = (project in file ("."))
  277. .settings(buildSettings: _*)
  278. .settings(Eclipse.settings: _*)
  279. .settings(publishSettings: _*)
  280. .settings(Release.settings: _*)
  281. .settings(resolvers += sonatypeRelease)
  282. .settings(
  283. name := "ScalaFX Utils",
  284. libraryDependencies ++= Seq (
  285. log4s,
  286. slf4j,
  287. jclBridge % "runtime,optional",
  288. log4jBridge % "runtime,optional",
  289. logback % "runtime,optional",
  290. gerweckUtil,
  291. scalaFx,
  292. scalaz,
  293. shapeless
  294. ),
  295. unmanagedJars in Compile += Attributed.blank(file(System.getenv("JAVA_HOME") + "/jre/lib/ext/jfxrt.jar"))
  296. )
  297. }