From 07cd22a64d5bde83f34760b7c95c696ef21dc4b8 Mon Sep 17 00:00:00 2001 From: Sarah Gerweck Date: Sat, 24 Sep 2016 21:06:36 -0700 Subject: [PATCH] Refactor the build into SBT 1.0 style --- build.sbt | 36 ++++ project/BasicSettings.scala | 107 +++++++++++ project/Build.scala | 346 ------------------------------------ project/Dependencies.scala | 106 +++++++++++ project/Eclipse.scala | 14 ++ project/Helpers.scala | 60 +++++++ project/Publish.scala | 45 +++++ project/Release.scala | 11 ++ project/Resolvers.scala | 8 + project/build.properties | 2 +- 10 files changed, 388 insertions(+), 347 deletions(-) create mode 100644 build.sbt create mode 100644 project/BasicSettings.scala delete mode 100644 project/Build.scala create mode 100644 project/Dependencies.scala create mode 100644 project/Eclipse.scala create mode 100644 project/Helpers.scala create mode 100644 project/Publish.scala create mode 100644 project/Release.scala create mode 100644 project/Resolvers.scala diff --git a/build.sbt b/build.sbt new file mode 100644 index 0000000..3150e30 --- /dev/null +++ b/build.sbt @@ -0,0 +1,36 @@ +import Dependencies._ +import Helpers._ +import Resolvers._ + +lazy val root = (project in file (".")) + .enablePlugins(BasicSettings) + .settings(Eclipse.settings: _*) + .settings(Publish.settings: _*) + .settings(Release.settings: _*) + .settings(resolvers += sonatypeRelease) + .settings( + name := "ScalaFX Utils", + + libraryDependencies ++= Seq ( + log4s, + slf4j, + jclBridge % "runtime,optional", + log4jBridge % "runtime,optional", + logback % "runtime,optional", + gerweckUtil, + scalaJava8, + scalaFx, + scalaz, + shapeless + ), + + /* Akka dependencies */ + libraryDependencies ++= Seq ( + akkaActor % "optional", + akkaStream % "optional", + akkaAgent % "optional", + gerweckUtilAkka % "optional" + ), + + unmanagedJars in Compile += Attributed.blank(file(System.getenv("JAVA_HOME") + "/jre/lib/ext/jfxrt.jar")) + ) diff --git a/project/BasicSettings.scala b/project/BasicSettings.scala new file mode 100644 index 0000000..0370e12 --- /dev/null +++ b/project/BasicSettings.scala @@ -0,0 +1,107 @@ +import sbt._ +import Keys._ + +import scala.util.Properties.envOrNone + +import com.typesafe.sbt.site._ + +import Helpers._ + +sealed trait Basics { + final val buildOrganization = "org.gerweck.scalafx" + final val buildOrganizationName = "Sarah Gerweck" + final val buildOrganizationUrl = Some("https://github.com/sarahgerweck") + + final val buildScalaVersion = "2.11.8" + final val extraScalaVersions = Seq.empty + final val minimumJavaVersion = "1.8" + lazy val defaultOptimize = false + final val projectMainClass = None + + lazy val parallelBuild = false + lazy val cachedResolution = true + + /* Metadata definitions */ + lazy val buildMetadata = Vector( + licenses := Seq("Apache License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")), + homepage := Some(url("https://github.com/sarahgerweck/scalafx-utils")), + description := "ScalaFX Utilities", + startYear := Some(2015), + scmInfo := Some(ScmInfo(url("https://github.com/sarahgerweck/scalafx-utils"), "scm:git:git@github.com:sarahgerweck/scalafx-utils.git")) + ) + + lazy val developerInfo = { + + + sarah + Sarah Gerweck + sarah.a180@gmail.com + https://github.com/sarahgerweck + America/Los_Angeles + + + } +} + +object BasicSettings extends AutoPlugin with Basics { + override def requires = SiteScaladocPlugin + + override lazy val projectSettings = ( + buildMetadata ++ + projectMainClass.toSeq.map(mainClass := Some(_)) ++ + Seq ( + organization := buildOrganization, + organizationName := buildOrganizationName, + organizationHomepage := buildOrganizationUrl map { url _ }, + + scalaVersion := buildScalaVersion, + crossScalaVersions := buildScalaVersions, + + scalacOptions ++= buildScalacOptions, + javacOptions ++= buildJavacOptions, + autoAPIMappings := true, + + updateOptions := updateOptions.value.withCachedResolution(cachedResolution), + parallelExecution := parallelBuild, + + evictionWarningOptions in update := + EvictionWarningOptions.default.withWarnTransitiveEvictions(false).withWarnDirectEvictions(false).withWarnScalaVersionEviction(false) + ) + ) + + /* Overridable flags */ + lazy val optimize = boolFlag("OPTIMIZE") orElse boolFlag("OPTIMISE") getOrElse defaultOptimize + lazy val deprecation = boolFlag("NO_DEPRECATION") map (!_) getOrElse true + lazy val inlineWarn = boolFlag("INLINE_WARNINGS") getOrElse false + lazy val debug = boolFlag("DEBUGGER") getOrElse false + lazy val debugPort = envOrNone("DEBUGGER_PORT") map { _.toInt } getOrElse 5050 + lazy val debugSuspend = boolFlag("DEBUGGER_SUSPEND") getOrElse true + lazy val unusedWarn = boolFlag("UNUSED_WARNINGS") getOrElse false + lazy val importWarn = boolFlag("IMPORT_WARNINGS") getOrElse false + + lazy val buildScalaVersions = buildScalaVersion +: extraScalaVersions + val buildScalacOptions = Seq ( + "-unchecked", + "-feature", + "-target:jvm-" + minimumJavaVersion + ) ++ ( + if (deprecation) Seq("-deprecation") else Seq.empty + ) ++ ( + if (optimize) Seq("-optimize") else Seq.empty + ) ++ ( + if (inlineWarn) Seq("-Yinline-warnings") else Seq.empty + ) ++ ( + if (unusedWarn) Seq("-Ywarn-unused") else Seq.empty + ) ++ ( + if (importWarn) Seq("-Ywarn-unused-import") else Seq.empty + ) + + /* Java build setup */ + val buildJavacOptions = Seq( + "-target", minimumJavaVersion, + "-source", minimumJavaVersion + ) ++ ( + if (deprecation) Seq("-Xlint:deprecation") else Seq.empty + ) +} + diff --git a/project/Build.scala b/project/Build.scala deleted file mode 100644 index b939adc..0000000 --- a/project/Build.scala +++ /dev/null @@ -1,346 +0,0 @@ -import sbt._ -import Keys._ - -import com.typesafe.sbt.site._ -import sbtrelease.ReleasePlugin.autoImport._ -import com.typesafe.sbt.SbtPgp.autoImport._ - -import scala.util.Properties.envOrNone -import com.typesafe.sbteclipse.plugin.EclipsePlugin._ - -import Helpers._ - -sealed trait Basics { - final val buildOrganization = "org.gerweck.scalafx" - final val buildOrganizationName = "Sarah Gerweck" - final val buildOrganizationUrl = Some("https://github.com/sarahgerweck") - - final val buildScalaVersion = "2.11.8" - final val extraScalaVersions = Seq.empty - final val minimumJavaVersion = "1.8" - lazy val defaultOptimize = false - final val projectMainClass = None - - lazy val parallelBuild = false - lazy val cachedResolution = true - - /* Metadata definitions */ - lazy val buildMetadata = Vector( - licenses := Seq("Apache License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")), - homepage := Some(url("https://github.com/sarahgerweck/scalafx-utils")), - description := "ScalaFX Utilities", - startYear := Some(2015), - scmInfo := Some(ScmInfo(url("https://github.com/sarahgerweck/scalafx-utils"), "scm:git:git@github.com:sarahgerweck/scalafx-utils.git")) - ) - - lazy val developerInfo = { - - - sarah - Sarah Gerweck - sarah.a180@gmail.com - https://github.com/sarahgerweck - America/Los_Angeles - - - } -} - -object BuildSettings extends Basics { - /* Overridable flags */ - lazy val optimize = boolFlag("OPTIMIZE") orElse boolFlag("OPTIMISE") getOrElse defaultOptimize - lazy val deprecation = boolFlag("NO_DEPRECATION") map (!_) getOrElse true - lazy val inlineWarn = boolFlag("INLINE_WARNINGS") getOrElse false - lazy val debug = boolFlag("DEBUGGER") getOrElse false - lazy val debugPort = envOrNone("DEBUGGER_PORT") map { _.toInt } getOrElse 5050 - lazy val debugSuspend = boolFlag("DEBUGGER_SUSPEND") getOrElse true - lazy val unusedWarn = boolFlag("UNUSED_WARNINGS") getOrElse false - lazy val importWarn = boolFlag("IMPORT_WARNINGS") getOrElse false - - lazy val buildScalaVersions = buildScalaVersion +: extraScalaVersions - val buildScalacOptions = Seq ( - "-unchecked", - "-feature", - "-target:jvm-" + minimumJavaVersion - ) ++ ( - if (deprecation) Seq("-deprecation") else Seq.empty - ) ++ ( - if (optimize) Seq("-optimize") else Seq.empty - ) ++ ( - if (inlineWarn) Seq("-Yinline-warnings") else Seq.empty - ) ++ ( - if (unusedWarn) Seq("-Ywarn-unused") else Seq.empty - ) ++ ( - if (importWarn) Seq("-Ywarn-unused-import") else Seq.empty - ) - - /* Java build setup */ - val buildJavacOptions = Seq( - "-target", minimumJavaVersion, - "-source", minimumJavaVersion - ) ++ ( - if (deprecation) Seq("-Xlint:deprecation") else Seq.empty - ) - - /** A wrapper so we can call `commonSettings()` on a project. */ - implicit class ProjectSettingsHelper(p: Project) { - def commonSettings() = siteSettings(p).settings(buildSettings: _*) - - private[this] def siteSettings(p: Project) = p.enablePlugins(SiteScaladocPlugin) - - private[this] val buildSettings = buildMetadata ++ - projectMainClass.toSeq.map(mainClass := Some(_)) ++ - Seq ( - organization := buildOrganization, - organizationName := buildOrganizationName, - organizationHomepage := buildOrganizationUrl map { url _ }, - - scalaVersion := buildScalaVersion, - crossScalaVersions := buildScalaVersions, - - scalacOptions ++= buildScalacOptions, - javacOptions ++= buildJavacOptions, - autoAPIMappings := true, - - updateOptions := updateOptions.value.withCachedResolution(cachedResolution), - parallelExecution := parallelBuild, - - evictionWarningOptions in update := - EvictionWarningOptions.default.withWarnTransitiveEvictions(false).withWarnDirectEvictions(false).withWarnScalaVersionEviction(false) - ) - } -} - -object Helpers { - def getProp(name: String): Option[String] = sys.props.get(name) orElse sys.env.get(name) - def parseBool(str: String): Boolean = Set("yes", "y", "true", "t", "1") contains str.trim.toLowerCase - def boolFlag(name: String): Option[Boolean] = getProp(name) map { parseBool _ } - def boolFlag(name: String, default: Boolean): Boolean = boolFlag(name) getOrElse default - def opts(names: String*): Option[String] = names.view.map(getProp _).foldLeft(None: Option[String]) { _ orElse _ } - - import scala.xml._ - def excludePomDeps(exclude: (String, String) => Boolean): Node => Node = { node: Node => - val rewriteRule = new transform.RewriteRule { - override def transform(n: Node): NodeSeq = { - if ((n.label == "dependency") && exclude((n \ "groupId").text, (n \ "artifactId").text)) - NodeSeq.Empty - else - n - } - } - val transformer = new transform.RuleTransformer(rewriteRule) - transformer.transform(node)(0) - } -} - -object Resolvers { - val sonatypeSnaps = Resolver.sonatypeRepo("snapshots") - val sonatypeRelease = Resolver.sonatypeRepo("releases") - val sonatypeStaging = "Sonatype Staging" at "https://oss.sonatype.org/service/local/staging/deploy/maven2" -} - -object Publish { - import BuildSettings._ - import Resolvers._ - import Helpers._ - - val sonaCreds = ( - for { - user <- getProp("SONATYPE_USER") - pass <- getProp("SONATYPE_PASS") - } yield { - credentials += - Credentials("Sonatype Nexus Repository Manager", - "oss.sonatype.org", - user, pass) - } - ).toSeq - - val settings = sonaCreds ++ Seq ( - publishMavenStyle := true, - pomIncludeRepository := { _ => false }, - publishArtifact in Test := false, - - publishTo := { - if (version.value.trim endsWith "SNAPSHOT") - Some(sonatypeSnaps) - else - Some(sonatypeStaging) - }, - - pomExtra := developerInfo - ) - - /** Use this if you don't want to publish a certain module. - * (SBT's release plugin doesn't handle this well.) - */ - val falseSettings = settings ++ Seq ( - publishArtifact in Compile := false, - publishArtifact in Test := false, - publishTo := Some(Resolver.file("phony-repo", file("target/repo"))) - ) -} - -object Release { - val settings = Seq ( - releaseCrossBuild := true, - releasePublishArtifactsAction := PgpKeys.publishSigned.value - ) -} - -object Eclipse { - import com.typesafe.sbteclipse.plugin.EclipsePlugin._ - - val settings = Seq ( - EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.Resource, - EclipseKeys.projectFlavor := EclipseProjectFlavor.Scala, - EclipseKeys.executionEnvironment := Some(EclipseExecutionEnvironment.JavaSE18), - EclipseKeys.withSource := true, - EclipseKeys.eclipseOutput := Some("target/scala-2.11/classes") - ) -} - -object Dependencies { - /* ********************************************************************** */ - /* Akka */ - /* ********************************************************************** */ - final val akkaVersion = "2.4.8" - - val akkaActor = "com.typesafe.akka" %% "akka-actor" % akkaVersion - val akkaAgent = "com.typesafe.akka" %% "akka-agent" % akkaVersion - val akkaStream = "com.typesafe.akka" %% "akka-stream" % akkaVersion - - /* ********************************************************************** */ - /* Utility Dependencies */ - /* ********************************************************************** */ - final val slf4jVersion = "1.7.21" - final val log4sVersion = "1.3.0" - final val logbackVersion = "1.1.7" - final val commonsVfsVersion = "2.0" - final val commonsIoVersion = "2.4" - final val spireVersion = "0.11.0" - final val groovyVersion = "2.4.4" - final val scalaJava8Version = "0.7.0" - final val scalaParserVersion = "1.0.4" - final val scalaXmlVersion = "1.0.5" - final val gerweckUtilVersion = "2.2.3" - final val scalazVersion = "7.2.4" - final val shapelessVersion = "2.3.1" - final val scallopVersion = "1.0.1" - - val log4s = "org.log4s" %% "log4s" % log4sVersion - val slf4j = "org.slf4j" % "slf4j-api" % slf4jVersion - val jclBridge = "org.slf4j" % "jcl-over-slf4j" % slf4jVersion - val log4jBridge = "org.slf4j" % "log4j-over-slf4j" % slf4jVersion - val logback = "ch.qos.logback" % "logback-classic" % logbackVersion - val spire = "org.spire-math" %% "spire" % spireVersion - val commonsIo = "commons-io" % "commons-io" % commonsIoVersion - val groovy = "org.codehaus.groovy" % "groovy-all" % groovyVersion - val gerweckUtil = "org.gerweck.scala" %% "gerweck-utils" % gerweckUtilVersion - val gerweckUtilAkka = "org.gerweck.scala" %% "gerweck-utils-akka" % gerweckUtilVersion - val scalaJava8 = "org.scala-lang.modules" %% "scala-java8-compat" % scalaJava8Version - val scalaz = "org.scalaz" %% "scalaz-core" % scalazVersion - val shapeless = "com.chuusai" %% "shapeless" % shapelessVersion - val scallop = "org.rogach" %% "scallop" % scallopVersion - - val commonsVfs = { - val base = "org.apache.commons" % "commons-vfs2" % commonsVfsVersion - base.exclude("commons-logging", "commons-logging") - .exclude("org.apache.maven.scm", "maven-scm-provider-svnexe") - .exclude("org.apache.maven.scm", "maven-scm-api") - base - } - - /* Use like this: libraryDependencies <++= (scalaBinaryVersion) (scalaParser) */ - def scalaParser(optional: Boolean): String => Seq[ModuleID] = { scalaBinaryVersion: String => - optionalize(optional) { - scalaBinaryVersion match { - case "2.11" => Seq("org.scala-lang.modules" %% "scala-parser-combinators" % scalaParserVersion % "optional") - case _ => Seq.empty - } - } - } - - def scalaXml(optional: Boolean)(scalaBinaryVersion: String): String => Seq[ModuleID] = { scalaBinaryVersion: String => - optionalize(optional) { - scalaBinaryVersion match { - case "2.11" => Seq("org.scala-lang.modules" %% "scala-xml" % scalaXmlVersion % "optional") - case _ => Seq.empty - } - } - } - - /* ********************************************************************** */ - /* Testing Dependencies */ - /* ********************************************************************** */ - final val scalaCheckVersion = "1.12.2" - final val scalaTestVersion = "2.2.4" - - val scalaCheck = "org.scalacheck" %% "scalacheck" % scalaCheckVersion - val scalaTest = "org.scalatest" %% "scalatest" % scalaTestVersion - - /* ********************************************************************** */ - /* ScalaFX */ - /* ********************************************************************** */ - final val scalaFxVersion = "8.0.92-R10" - - val scalaFx = "org.scalafx" %% "scalafx" % scalaFxVersion - - /* ********************************************************************** */ - /* Helpers */ - /* ********************************************************************** */ - private[this] def optionalize(optional: Boolean)(f: => Seq[ModuleID]): Seq[ModuleID] = { - if (optional) { - f map { _ % "optional" } - } else { - f - } - } - - private[this] def noCL(m: ModuleID) = ( - m exclude("commons-logging", "commons-logging") - exclude("commons-logging", "commons-logging-api") - ) -} - -object UtilsBuild extends Build { - build => - - import BuildSettings._ - import Resolvers._ - import Dependencies._ - import Helpers._ - - lazy val root = (project in file (".")) - .commonSettings() - .settings(Eclipse.settings: _*) - .settings(Publish.settings: _*) - .settings(Release.settings: _*) - .settings(resolvers += sonatypeRelease) - .settings( - name := "ScalaFX Utils", - - libraryDependencies ++= Seq ( - log4s, - slf4j, - jclBridge % "runtime,optional", - log4jBridge % "runtime,optional", - logback % "runtime,optional", - gerweckUtil, - scalaJava8, - scalaFx, - scalaz, - shapeless - ), - - /* Akka dependencies */ - libraryDependencies ++= Seq ( - akkaActor % "optional", - akkaStream % "optional", - akkaAgent % "optional", - gerweckUtilAkka % "optional" - ), - - unmanagedJars in Compile += Attributed.blank(file(System.getenv("JAVA_HOME") + "/jre/lib/ext/jfxrt.jar")) - ) -} diff --git a/project/Dependencies.scala b/project/Dependencies.scala new file mode 100644 index 0000000..44f7a1b --- /dev/null +++ b/project/Dependencies.scala @@ -0,0 +1,106 @@ +import sbt._ + +object Dependencies { + /* ********************************************************************** */ + /* Akka */ + /* ********************************************************************** */ + final val akkaVersion = "2.4.8" + + val akkaActor = "com.typesafe.akka" %% "akka-actor" % akkaVersion + val akkaAgent = "com.typesafe.akka" %% "akka-agent" % akkaVersion + val akkaStream = "com.typesafe.akka" %% "akka-stream" % akkaVersion + + /* ********************************************************************** */ + /* Utility Dependencies */ + /* ********************************************************************** */ + final val slf4jVersion = "1.7.21" + final val log4sVersion = "1.3.0" + final val logbackVersion = "1.1.7" + final val commonsVfsVersion = "2.0" + final val commonsIoVersion = "2.4" + final val spireVersion = "0.11.0" + final val groovyVersion = "2.4.4" + final val scalaJava8Version = "0.7.0" + final val scalaParserVersion = "1.0.4" + final val scalaXmlVersion = "1.0.5" + final val gerweckUtilVersion = "2.2.3" + final val scalazVersion = "7.2.4" + final val shapelessVersion = "2.3.1" + final val scallopVersion = "1.0.1" + + val log4s = "org.log4s" %% "log4s" % log4sVersion + val slf4j = "org.slf4j" % "slf4j-api" % slf4jVersion + val jclBridge = "org.slf4j" % "jcl-over-slf4j" % slf4jVersion + val log4jBridge = "org.slf4j" % "log4j-over-slf4j" % slf4jVersion + val logback = "ch.qos.logback" % "logback-classic" % logbackVersion + val spire = "org.spire-math" %% "spire" % spireVersion + val commonsIo = "commons-io" % "commons-io" % commonsIoVersion + val groovy = "org.codehaus.groovy" % "groovy-all" % groovyVersion + val gerweckUtil = "org.gerweck.scala" %% "gerweck-utils" % gerweckUtilVersion + val gerweckUtilAkka = "org.gerweck.scala" %% "gerweck-utils-akka" % gerweckUtilVersion + val scalaJava8 = "org.scala-lang.modules" %% "scala-java8-compat" % scalaJava8Version + val scalaz = "org.scalaz" %% "scalaz-core" % scalazVersion + val shapeless = "com.chuusai" %% "shapeless" % shapelessVersion + val scallop = "org.rogach" %% "scallop" % scallopVersion + + val commonsVfs = { + val base = "org.apache.commons" % "commons-vfs2" % commonsVfsVersion + base.exclude("commons-logging", "commons-logging") + .exclude("org.apache.maven.scm", "maven-scm-provider-svnexe") + .exclude("org.apache.maven.scm", "maven-scm-api") + base + } + + /* Use like this: libraryDependencies <++= (scalaBinaryVersion) (scalaParser) */ + def scalaParser(optional: Boolean): String => Seq[ModuleID] = { scalaBinaryVersion: String => + optionalize(optional) { + scalaBinaryVersion match { + case "2.11" => Seq("org.scala-lang.modules" %% "scala-parser-combinators" % scalaParserVersion % "optional") + case _ => Seq.empty + } + } + } + + def scalaXml(optional: Boolean)(scalaBinaryVersion: String): String => Seq[ModuleID] = { scalaBinaryVersion: String => + optionalize(optional) { + scalaBinaryVersion match { + case "2.11" => Seq("org.scala-lang.modules" %% "scala-xml" % scalaXmlVersion % "optional") + case _ => Seq.empty + } + } + } + + /* ********************************************************************** */ + /* Testing Dependencies */ + /* ********************************************************************** */ + final val scalaCheckVersion = "1.12.2" + final val scalaTestVersion = "2.2.4" + + val scalaCheck = "org.scalacheck" %% "scalacheck" % scalaCheckVersion + val scalaTest = "org.scalatest" %% "scalatest" % scalaTestVersion + + /* ********************************************************************** */ + /* ScalaFX */ + /* ********************************************************************** */ + final val scalaFxVersion = "8.0.92-R10" + + val scalaFx = "org.scalafx" %% "scalafx" % scalaFxVersion + + /* ********************************************************************** */ + /* Helpers */ + /* ********************************************************************** */ + private[this] def optionalize(optional: Boolean)(f: => Seq[ModuleID]): Seq[ModuleID] = { + if (optional) { + f map { _ % "optional" } + } else { + f + } + } + + private[this] def noCL(m: ModuleID) = ( + m exclude("commons-logging", "commons-logging") + exclude("commons-logging", "commons-logging-api") + ) +} + + diff --git a/project/Eclipse.scala b/project/Eclipse.scala new file mode 100644 index 0000000..626db91 --- /dev/null +++ b/project/Eclipse.scala @@ -0,0 +1,14 @@ +import sbt._ + +import com.typesafe.sbteclipse.plugin.EclipsePlugin._ + +object Eclipse { + + val settings = Seq ( + EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.Resource, + EclipseKeys.projectFlavor := EclipseProjectFlavor.Scala, + EclipseKeys.executionEnvironment := Some(EclipseExecutionEnvironment.JavaSE18), + EclipseKeys.withSource := true, + EclipseKeys.eclipseOutput := Some("target/scala-2.11/classes") + ) +} diff --git a/project/Helpers.scala b/project/Helpers.scala new file mode 100644 index 0000000..1d74259 --- /dev/null +++ b/project/Helpers.scala @@ -0,0 +1,60 @@ +object Helpers { + def getProp(name: String): Option[String] = sys.props.get(name) orElse sys.env.get(name) + def parseBool(str: String): Boolean = Set("yes", "y", "true", "t", "1") contains str.trim.toLowerCase + def boolFlag(name: String): Option[Boolean] = getProp(name) map { parseBool _ } + def boolFlag(name: String, default: Boolean): Boolean = boolFlag(name) getOrElse default + def opts(names: String*): Option[String] = names.view.map(getProp _).foldLeft(None: Option[String]) { _ orElse _ } + + import scala.xml._ + def excludePomDeps(exclude: (String, String) => Boolean): Node => Node = { node: Node => + val rewriteRule = new transform.RewriteRule { + override def transform(n: Node): NodeSeq = { + if ((n.label == "dependency") && exclude((n \ "groupId").text, (n \ "artifactId").text)) + NodeSeq.Empty + else + n + } + } + val transformer = new transform.RuleTransformer(rewriteRule) + transformer.transform(node)(0) + } + + sealed trait SVer { + def requireJava8: Boolean + } + object SVer { + def apply(scalaVersion: String): SVer = { + scalaVersion match { + case "2.10" => SVer2_10 + case "2.11" => SVer2_11 + case "2.12.0-M1" => SVer2_12M1 + case "2.12.0-M2" => SVer2_12M2 + case "2.12.0-M3" => SVer2_12M3 + case "2.12.0-M4" => SVer2_12M4 + case "2.12" => SVer2_12 + } + } + } + case object SVer2_10 extends SVer { + def requireJava8 = false + } + case object SVer2_11 extends SVer { + def requireJava8 = false + } + case object SVer2_12M1 extends SVer { + def requireJava8 = true + } + case object SVer2_12M2 extends SVer { + def requireJava8 = true + } + case object SVer2_12M3 extends SVer { + def requireJava8 = true + } + case object SVer2_12M4 extends SVer { + def requireJava8 = true + } + case object SVer2_12 extends SVer { + def requireJava8 = true + } +} + diff --git a/project/Publish.scala b/project/Publish.scala new file mode 100644 index 0000000..c2a8360 --- /dev/null +++ b/project/Publish.scala @@ -0,0 +1,45 @@ +import sbt._ +import Keys._ + +object Publish { + import Resolvers._ + import Helpers._ + + val sonaCreds = ( + for { + user <- getProp("SONATYPE_USER") + pass <- getProp("SONATYPE_PASS") + } yield { + credentials += + Credentials("Sonatype Nexus Repository Manager", + "oss.sonatype.org", + user, pass) + } + ).toSeq + + val settings = sonaCreds ++ Seq ( + publishMavenStyle := true, + pomIncludeRepository := { _ => false }, + publishArtifact in Test := false, + + publishTo := { + if (version.value.trim endsWith "SNAPSHOT") + Some(sonatypeSnaps) + else + Some(sonatypeStaging) + }, + + pomExtra := BasicSettings.developerInfo + ) + + /** Use this if you don't want to publish a certain module. + * (SBT's release plugin doesn't handle this well.) + */ + val falseSettings = settings ++ Seq ( + publishArtifact in Compile := false, + publishArtifact in Test := false, + publishTo := Some(Resolver.file("phony-repo", file("target/repo"))) + ) +} + + diff --git a/project/Release.scala b/project/Release.scala new file mode 100644 index 0000000..a341477 --- /dev/null +++ b/project/Release.scala @@ -0,0 +1,11 @@ +import sbt._ + +import sbtrelease.ReleasePlugin.autoImport._ +import com.typesafe.sbt.SbtPgp.autoImport._ + +object Release { + lazy val settings = Seq ( + releaseCrossBuild := true, + releasePublishArtifactsAction := PgpKeys.publishSigned.value + ) +} diff --git a/project/Resolvers.scala b/project/Resolvers.scala new file mode 100644 index 0000000..fe0db2d --- /dev/null +++ b/project/Resolvers.scala @@ -0,0 +1,8 @@ +import sbt._ + +object Resolvers { + val sonatypeSnaps = Resolver.sonatypeRepo("snapshots") + val sonatypeRelease = Resolver.sonatypeRepo("releases") + val sonatypeStaging = "Sonatype Staging" at "https://oss.sonatype.org/service/local/staging/deploy/maven2" +} + diff --git a/project/build.properties b/project/build.properties index 43b8278..35c88ba 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.11 +sbt.version=0.13.12