Updated build Helpers
file
This commit is contained in:
parent
2936952a12
commit
136d2b59a3
@ -1,83 +1,98 @@
|
|||||||
import sbt._
|
import sbt._
|
||||||
import Keys._
|
import sbt.Keys._
|
||||||
|
|
||||||
object Helpers {
|
import HelpersImpl._
|
||||||
def getProp(name: String): Option[String] = sys.props.get(name) orElse sys.env.get(name)
|
object Helpers extends AnyRef with PropertyHelper with VersionHelper with PomHelper
|
||||||
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 _ }
|
|
||||||
|
|
||||||
lazy val buildNumberOpt = sys.env.get("BUILD_NUMBER")
|
/* Note: This file is shared among many projects. Avoid putting project-specific things here. */
|
||||||
lazy val isJenkins = buildNumberOpt.isDefined
|
|
||||||
|
|
||||||
import scala.xml._
|
object HelpersImpl {
|
||||||
def excludePomDeps(exclude: (String, String) => Boolean): Node => Node = { node: Node =>
|
sealed trait PropertyHelper {
|
||||||
val rewriteRule = new transform.RewriteRule {
|
private[this] lazy val boolNames = Set("yes", "y", "true", "t", "1")
|
||||||
override def transform(n: Node): NodeSeq = {
|
|
||||||
if ((n.label == "dependency") && exclude((n \ "groupId").text, (n \ "artifactId").text))
|
def getProp(name: String): Option[String] = sys.props.get(name) orElse sys.env.get(name)
|
||||||
NodeSeq.Empty
|
def parseBool(str: String): Boolean = boolNames(str.trim.toLowerCase)
|
||||||
else
|
def boolFlag(name: String): Option[Boolean] = getProp(name).map(parseBool)
|
||||||
n
|
def boolFlag(name: String, default: Boolean): Boolean = boolFlag(name) getOrElse default
|
||||||
|
def intFlag(name: String) = getProp(name).map(_.toInt)
|
||||||
|
def intFlag(name: String, default: Int): Int = intFlag(name) getOrElse default
|
||||||
|
def opts(names: String*): Option[String] = names.collectFirst(Function.unlift(getProp))
|
||||||
|
|
||||||
|
lazy val buildNumberOpt = sys.env.get("BUILD_NUMBER")
|
||||||
|
lazy val isJenkins = buildNumberOpt.isDefined
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed trait VersionHelper {
|
||||||
|
final lazy val sver: Def.Initialize[SVer] = {
|
||||||
|
Def.map(scalaBinaryVersion)(SVer.apply)
|
||||||
|
}
|
||||||
|
|
||||||
|
final lazy val forceOldInlineSyntax: Def.Initialize[Boolean] = {
|
||||||
|
val pat = """(?x)^ 2\.12\.[0-2] (?:[^\d].*)? $""".r
|
||||||
|
Def.map(scalaVersion) {
|
||||||
|
case pat() => true
|
||||||
|
case _ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val transformer = new transform.RuleTransformer(rewriteRule)
|
|
||||||
transformer.transform(node)(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
final lazy val sver: Def.Initialize[SVer] = {
|
sealed trait Backend
|
||||||
Def.map(scalaBinaryVersion)(SVer.apply)
|
case object NewBackend extends Backend
|
||||||
}
|
case object SupportsNewBackend extends Backend
|
||||||
|
case object OldBackend extends Backend
|
||||||
|
|
||||||
final lazy val forceOldInlineSyntax: Def.Initialize[Boolean] = {
|
sealed trait SVer {
|
||||||
val pat = """(?x)^ 2\.12\.[0-2] (?:[^\d].*)? $""".r
|
val backend: Backend
|
||||||
Def.map(scalaVersion) {
|
val requireJava8: Boolean
|
||||||
case pat() => true
|
|
||||||
case _ => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sealed trait Backend
|
def supportsNewBackend = backend match {
|
||||||
case object NewBackend extends Backend
|
case NewBackend => true
|
||||||
case object SupportsNewBackend extends Backend
|
case SupportsNewBackend => true
|
||||||
case object OldBackend extends Backend
|
case OldBackend => false
|
||||||
|
|
||||||
sealed trait SVer {
|
|
||||||
val backend: Backend
|
|
||||||
val requireJava8: Boolean
|
|
||||||
|
|
||||||
def supportsNewBackend = backend match {
|
|
||||||
case NewBackend => true
|
|
||||||
case SupportsNewBackend => true
|
|
||||||
case OldBackend => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
object SVer {
|
|
||||||
def apply(scalaVersion: String): SVer = {
|
|
||||||
CrossVersion.partialVersion(scalaVersion) match {
|
|
||||||
case Some((2, 10)) => SVer2_10
|
|
||||||
case Some((2, 11)) => SVer2_11
|
|
||||||
case Some((2, 12)) => SVer2_12
|
|
||||||
case Some((2, n)) if n >= 13 => SVer2_13
|
|
||||||
case _ =>
|
|
||||||
throw new IllegalArgumentException(s"Scala version $scalaVersion is not supported")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
object SVer {
|
||||||
|
def apply(scalaVersion: String): SVer = {
|
||||||
|
CrossVersion.partialVersion(scalaVersion) match {
|
||||||
|
case Some((2, 10)) => SVer2_10
|
||||||
|
case Some((2, 11)) => SVer2_11
|
||||||
|
case Some((2, 12)) => SVer2_12
|
||||||
|
case Some((2, n)) if n >= 13 => SVer2_13
|
||||||
|
case _ =>
|
||||||
|
throw new IllegalArgumentException(s"Scala version $scalaVersion is not supported")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case object SVer2_10 extends SVer {
|
||||||
|
override final val backend = OldBackend
|
||||||
|
override final val requireJava8 = false
|
||||||
|
}
|
||||||
|
case object SVer2_11 extends SVer {
|
||||||
|
override final val backend = SupportsNewBackend
|
||||||
|
override final val requireJava8 = false
|
||||||
|
}
|
||||||
|
case object SVer2_12 extends SVer {
|
||||||
|
override final val backend = NewBackend
|
||||||
|
override final val requireJava8 = true
|
||||||
|
}
|
||||||
|
case object SVer2_13 extends SVer {
|
||||||
|
override final val backend = NewBackend
|
||||||
|
override final val requireJava8 = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case object SVer2_10 extends SVer {
|
|
||||||
override final val backend = OldBackend
|
sealed trait PomHelper {
|
||||||
override final val requireJava8 = false
|
import scala.xml.{ Node, NodeSeq }
|
||||||
}
|
import scala.xml.transform.{ RewriteRule, RuleTransformer }
|
||||||
case object SVer2_11 extends SVer {
|
|
||||||
override final val backend = SupportsNewBackend
|
def excludePomDeps(exclude: (String, String) => Boolean): Node => Node = { node: Node =>
|
||||||
override final val requireJava8 = false
|
def shouldExclude(n: Node): Boolean =
|
||||||
}
|
n.label == "dependency" && exclude((n \ "groupId").text, (n \ "artifactId").text)
|
||||||
case object SVer2_12 extends SVer {
|
|
||||||
override final val backend = NewBackend
|
val rewriteRule = new RewriteRule {
|
||||||
override final val requireJava8 = true
|
override def transform(n: Node): NodeSeq = if (shouldExclude(n)) NodeSeq.Empty else n
|
||||||
}
|
}
|
||||||
case object SVer2_13 extends SVer {
|
val transformer = new RuleTransformer(rewriteRule)
|
||||||
override final val backend = NewBackend
|
transformer.transform(node).head
|
||||||
override final val requireJava8 = true
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user