Created
May 25, 2015 11:43
-
-
Save diversit/dca340ef161babc35c62 to your computer and use it in GitHub Desktop.
Custom sbt task to run an application many times
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
// Custom task to run an application many times. | |
// Add scriptlet into build.sbt | |
lazy val runMany = inputKey[Unit]("Running the app many times. Provide nr of times. Defaults to 10.") | |
runMany in Runtime := { | |
val args: Seq[String] = Def.spaceDelimited("Number of times to run. Default is: 10.").parsed | |
val times = Try { | |
args.head.toInt | |
}.getOrElse(10) | |
println(s"Running $times times...") | |
val myMain: Option[String] = (selectMainClass in Runtime).value | |
val myRunner: ScalaRun = (runner in Runtime).value | |
val fcp: Seq[Attributed[File]] = (fullClasspath in Runtime).value | |
myMain match { | |
case Some(mainclass) => | |
println("Warming up...") | |
for (i <- 1 to times) { | |
print(i) | |
myRunner.run(mainclass, Attributed.data(fcp), Seq.empty[String], streams.value.log) | |
} | |
println("Done.") | |
case None => | |
println("No main class selected.") | |
} | |
println("Done!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment