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.

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