Created
September 12, 2014 15:43
-
-
Save paulp/fbc034927a12136a0623 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package psp | |
| import sbt._, Keys._, scala.util.Try | |
| package object stub extends stub.LibSbtStub { | |
| lazy val props = new SbtBuildProps() | |
| lazy val pspBintray = new Bintray("paulp") | |
| def buildSettings = quietSettings ++ Seq(resolvers ++= pspBintray.repos) ++ addSbtPlugin(pspOrg % "psp-libsbt" % dependVersion) | |
| def projectSettings = quietSettings | |
| } | |
| /** Code which we want available everywhere. | |
| */ | |
| package stub { | |
| class Bintray(owner: String) { | |
| def base = "https://dl.bintray.com" | |
| def maven = new MavenRepository(s"bintray-$owner-maven", s"$base/$owner/maven/") | |
| def plugins = Resolver.url(s"bintray-$owner-sbt-plugins", url(s"$base/$owner/sbt-plugins"))(Resolver.ivyStylePatterns) | |
| def repos = Seq(maven, plugins) | |
| def addPlugin = addSbtPlugin("org.improving" % "psp-libsbt" % sys.props.getOrElse("depend.version", "latest.release")) | |
| } | |
| class FileOrSystemProps(file: File) { | |
| private lazy val fileProps = Try(load()).toOption getOrElse Map[String, String]() | |
| def contains(prop: String) = apply(prop, null) != null | |
| def apply(prop: String): String = apply(prop, sys error s"Set $prop in $file or as a system property.") | |
| def apply(prop: String, alt: => String): String = fileProps get prop orElse (sys.props get prop) getOrElse alt | |
| private def load() = { | |
| import scala.collection.JavaConverters._ | |
| val props = new java.util.Properties | |
| IO.load(props, file) | |
| props.asScala.toMap | |
| } | |
| } | |
| class SbtBuildProps() extends FileOrSystemProps(file("project/build.properties")) { | |
| def sbtVersionProperty = "sbt.version" | |
| def releaseProperty = "release.version" | |
| def dependProperty = "depend.version" | |
| def publishProperty = "publish.version" | |
| def localProperty = "local" | |
| def debugProperty = "debug" | |
| lazy val sbtVersion = apply(sbtVersionProperty, "0.13.5") | |
| lazy val releaseVersion = apply(releaseProperty) | |
| lazy val dependVersion = apply(dependProperty, releaseVersion) | |
| lazy val publishVersion = apply(publishProperty, incrementVersion(dependVersion) + localSuffix) | |
| lazy val hasLocalSuffix = this contains localProperty | |
| lazy val isDebug = this contains debugProperty | |
| private def dateTime = new java.text.SimpleDateFormat("yyyyMMdd-HH-mm-ss") format new java.util.Date | |
| private def localSuffix = if (hasLocalSuffix) "-" + dateTime else "" | |
| private def incrementVersion(v: String): String = { | |
| val num = (v.reverse takeWhile (_.isDigit)).reverse | |
| (v dropRight num.length) + (num.toInt + 1).toString | |
| } | |
| } | |
| trait LibSbtStub { | |
| def props: SbtBuildProps | |
| def publishVersion = props.publishVersion | |
| def dependVersion = props.dependVersion | |
| def localSuffixProperty = "local" | |
| def debugProperty = "debug" | |
| def sbtRelease = props.sbtVersion | |
| def scalaVersionSbt = "2.10.4" | |
| def scalaVersionLatest = "2.11.2" | |
| def scalaVersionsCross = Seq("2.10.4", "2.11.2") | |
| def pspOrg = "org.improving" | |
| def pspLicenses = Seq("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")) | |
| def bintrayPlugin = "me.lessis" % "bintray-sbt" % "0.1.2" | |
| def versioncheckPlugin = "com.typesafe.sbt" % "sbt-javaversioncheck" % "0.1.0" | |
| def typesafeConfig = "com.typesafe" % "config" % "1.2.1" | |
| def pspApi = pspOrg %% "psp-api" % dependVersion | |
| def scalacheck = "org.scalacheck" %% "scalacheck" % "1.11.5" % "test" | |
| def scalaReflect(v: String) = "org.scala-lang" % "scala-reflect" % v | |
| def scalacOptionsFor(binaryVersion: String): Seq[String] = binaryVersion match { | |
| case "2.11" => Seq("-Ywarn-unused", "-Ywarn-unused-import") | |
| case _ => Nil | |
| } | |
| def buildBase = baseDirectory in ThisBuild | |
| def initRepl = initialCommands in console | |
| def quietSettings = Seq( | |
| javacOptions in Compile ++= Seq("-nowarn", "-XDignore.symbol.file"), | |
| scalacOptions in Compile ++= Seq("-language:_"), | |
| logLevel in update := Level.Warn, | |
| publishArtifact in Test := false, | |
| scalacOptions ++= ( if (props.isDebug) Seq("-Ylog:all") else Nil ) | |
| ) | |
| implicit class StubSeqModuleIDOps(val ids: Seq[ModuleID]) { | |
| def deps(): Setting[_] = libraryDependencies ++= ids | |
| // def intransitive(): Seq[ModuleID] = ids map (_.intransitive()) | |
| // def inTest(): Seq[ModuleID] = ids map (_ % "test") | |
| // def inCompile(): Seq[ModuleID] = ids map (_ % "compile") | |
| } | |
| implicit class StubProjectOps(val p: Project) { | |
| def also(m: ModuleID, ms: ModuleID*) = p settings (m +: ms.toSeq).deps | |
| def also(s: Setting[_], ss: Setting[_]*) = p settings (s +: ss.toSeq: _*) | |
| def also(ss: Traversable[Setting[_]]) = p settings (ss.toSeq: _*) | |
| def deps(ms: ModuleID*) = p settings (libraryDependencies ++= ms.toSeq) | |
| def noArtifacts: Project = also(publish := (()), publishLocal := (()), Keys.`package` := file(""), packageBin := file(""), packagedArtifacts := Map()) | |
| def root: Project = p.noArtifacts in file(".") | |
| } | |
| } | |
| abstract class LibSbtBuild extends sbt.Build with LibSbtStub { } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment