Skip to content

Instantly share code, notes, and snippets.

@koduki
Created May 20, 2012 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koduki/2757597 to your computer and use it in GitHub Desktop.
Save koduki/2757597 to your computer and use it in GitHub Desktop.
環境依存ファイルを変更するためのsbtのカスタムタスク
import sbt._
import sbt.Keys._
import sbt.IO._
object ProjectBuild extends Build {
val dependencyFiles = Seq("src/main/webapp/WEB-INF/web.xml")
val enviroment = InputKey[Unit]("enviroment", "chagen enviroment seting.")
val enviromentTask = enviroment <<= inputTask { (argTask: TaskKey[Seq[String]]) =>
argTask map { (args: Seq[String]) =>
changeEnviroment(args.first)
}
}
def changeEnviroment(env:String) = {
println("change enviroment:" + env)
dependencyFiles.foreach { path =>
val envPath = path + "." + env
val envFile = new File(envPath)
val msg = if (envFile.exists) {
copyFile(envFile, new File(path))
"copy:" + envPath
} else {
"not found:" + envPath
}
println(msg)
}
}
lazy val root = Project( id = "", base = file("."),
settings = Defaults.defaultSettings ++ Seq(enviromentTask)).dependsOn()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment