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.

346 lines
13 KiB

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