mirror of https://github.com/sbt/sbt.git
30 lines
1008 B
Scala
30 lines
1008 B
Scala
import sbt._
|
|
import sbt.Keys._
|
|
|
|
object Transform {
|
|
|
|
def configSettings = Seq(
|
|
resourceGenerators += Def.task {
|
|
val rdirs = Seq(sourceDirectory.value / "input_resources")
|
|
val rm = resourceManaged.value
|
|
val paths = (rdirs ** (-DirectoryFilter)).get --- rdirs
|
|
val rs = paths.pair(Path.rebase(rdirs, rm) | Path.flat(rm))
|
|
val props = Map(
|
|
"org" -> organization.value,
|
|
"sbt.version" -> version.value,
|
|
"scala.version" -> scalaVersion.value,
|
|
)
|
|
def get(key: String) = props.getOrElse(key, sys.error(s"No value defined for key '$key'"))
|
|
val Property = """\$\{\{([\w.-]+)\}\}""".r
|
|
val catcher = scala.util.control.Exception.catching(classOf[java.io.IOException])
|
|
rs.map {
|
|
case (in, out) =>
|
|
val newString = Property.replaceAllIn(IO.read(in), mtch => get(mtch.group(1)))
|
|
if (Some(newString) != catcher.opt(IO.read(out)))
|
|
IO.write(out, newString)
|
|
out
|
|
}
|
|
}.taskValue,
|
|
)
|
|
}
|