scalafx-utils/project/Helpers.scala

47 lines
1.6 KiB
Scala
Raw Normal View History

2016-09-25 04:06:36 +00:00
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 {
2016-12-07 07:25:12 +00:00
val supportsNewBackend: Boolean = false
val requireJava8: Boolean = true
val newOptimize: Boolean = false
2016-09-25 04:06:36 +00:00
}
object SVer {
def apply(scalaVersion: String): SVer = {
scalaVersion match {
2016-12-07 07:25:12 +00:00
case "2.10" => SVer2_10
case "2.11" => SVer2_11
case "2.12" => SVer2_12
2016-09-25 04:06:36 +00:00
}
}
}
case object SVer2_10 extends SVer {
2016-12-07 07:25:12 +00:00
override val requireJava8 = false
2016-09-25 04:06:36 +00:00
}
case object SVer2_11 extends SVer {
2016-12-07 07:25:12 +00:00
override val supportsNewBackend = true
override val requireJava8 = false
2016-09-25 04:06:36 +00:00
}
case object SVer2_12 extends SVer {
2016-12-07 07:25:12 +00:00
override val newOptimize = true
2016-09-25 04:06:36 +00:00
}
}