2011-04-26 14:22:33 +03:00
|
|
|
/* sbt -- Simple Build Tool
|
|
|
|
|
* Copyright 2011 Artyom Olshevskiy
|
|
|
|
|
*/
|
2011-10-16 17:27:36 -04:00
|
|
|
package sbt
|
2011-04-25 15:27:32 +03:00
|
|
|
|
|
|
|
|
import Project.Initialize
|
|
|
|
|
import Keys._
|
|
|
|
|
import classpath.ClasspathUtilities
|
2013-06-10 11:54:40 -04:00
|
|
|
import java.lang.reflect.{InvocationTargetException,Method}
|
2011-04-25 15:27:32 +03:00
|
|
|
import java.util.Properties
|
|
|
|
|
|
|
|
|
|
object ScriptedPlugin extends Plugin {
|
2011-04-28 06:01:53 +03:00
|
|
|
def scriptedConf = config("scripted-sbt") hide
|
2013-06-10 11:54:40 -04:00
|
|
|
private[this] def scriptedLaunchConf = config("scripted-sbt-launch") hide
|
2011-04-25 15:27:32 +03:00
|
|
|
|
|
|
|
|
val scriptedSbt = SettingKey[String]("scripted-sbt")
|
|
|
|
|
val sbtLauncher = SettingKey[File]("sbt-launcher")
|
2013-06-10 11:54:40 -04:00
|
|
|
// need to get the launcher from 'update', which requires a Task, but cannot break compatibility in 0.12
|
|
|
|
|
private[this] val sbtLauncherTask = TaskKey[File]("sbt-launcher-task")
|
|
|
|
|
|
2011-04-25 15:27:32 +03:00
|
|
|
val sbtTestDirectory = SettingKey[File]("sbt-test-directory")
|
|
|
|
|
val scriptedBufferLog = SettingKey[Boolean]("scripted-buffer-log")
|
|
|
|
|
final case class ScriptedScalas(build: String, versions: String)
|
|
|
|
|
val scriptedScalas = SettingKey[ScriptedScalas]("scripted-scalas")
|
|
|
|
|
|
|
|
|
|
val scriptedClasspath = TaskKey[PathFinder]("scripted-classpath")
|
|
|
|
|
val scriptedTests = TaskKey[AnyRef]("scripted-tests")
|
|
|
|
|
val scriptedRun = TaskKey[Method]("scripted-run")
|
2012-01-20 14:16:23 -08:00
|
|
|
val scriptedLaunchOpts = SettingKey[Seq[String]]("scripted-launch-opts", "options to pass to jvm launching scripted tasks")
|
2011-04-25 15:27:32 +03:00
|
|
|
val scriptedDependencies = TaskKey[Unit]("scripted-dependencies")
|
|
|
|
|
val scripted = InputKey[Unit]("scripted")
|
|
|
|
|
|
|
|
|
|
def scriptedTestsTask: Initialize[Task[AnyRef]] = (scriptedClasspath, scalaInstance) map {
|
|
|
|
|
(classpath, scala) =>
|
2013-06-10 11:56:38 -04:00
|
|
|
val parent = new sbt.classpath.FilteredLoader(scala.loader, "jline." :: Nil)
|
|
|
|
|
val loader = ClasspathUtilities.toLoader(classpath, parent)
|
2011-04-25 15:27:32 +03:00
|
|
|
ModuleUtilities.getObject("sbt.test.ScriptedTests", loader)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def scriptedRunTask: Initialize[Task[Method]] = (scriptedTests) map {
|
2013-06-10 11:57:37 -04:00
|
|
|
(m) => try get012Method(m) catch { case e12: NoSuchMethodException =>
|
|
|
|
|
try get013Method(m) catch { case _: NoSuchMethodException => throw e12 }
|
|
|
|
|
}
|
2011-04-25 15:27:32 +03:00
|
|
|
}
|
2013-06-10 11:57:37 -04:00
|
|
|
private[this] def get012Method(m: AnyRef): Method =
|
|
|
|
|
m.getClass.getMethod("run", classOf[File], classOf[Boolean], classOf[String], classOf[String], classOf[String], classOf[Array[String]], classOf[File], classOf[Array[String]])
|
|
|
|
|
private[this] def get013Method(m: AnyRef): Method =
|
|
|
|
|
m.getClass.getMethod("run", classOf[File], classOf[Boolean], classOf[Array[String]], classOf[File], classOf[Array[String]])
|
|
|
|
|
|
2011-04-25 15:27:32 +03:00
|
|
|
|
|
|
|
|
def scriptedTask: Initialize[InputTask[Unit]] = InputTask(_ => complete.Parsers.spaceDelimited("<arg>")) { result =>
|
2013-06-10 11:54:40 -04:00
|
|
|
(scriptedDependencies, scriptedTests, scriptedRun, sbtTestDirectory, scriptedBufferLog, scriptedSbt, scriptedScalas, sbtLauncherTask, scriptedLaunchOpts, result) map {
|
2012-01-20 14:16:23 -08:00
|
|
|
(deps, m, r, testdir, bufferlog, version, scriptedScalas, launcher, launchOpts, args) =>
|
2013-06-10 11:57:37 -04:00
|
|
|
def invoke12 = r.invoke(m, testdir, bufferlog: java.lang.Boolean, version.toString, scriptedScalas.build, scriptedScalas.versions, args.toArray, launcher, launchOpts.toArray)
|
|
|
|
|
def invoke13 = r.invoke(m, testdir, bufferlog: java.lang.Boolean, args.toArray, launcher, launchOpts.toArray)
|
|
|
|
|
try invoke12 catch {
|
|
|
|
|
case e: InvocationTargetException => throw e.getCause
|
|
|
|
|
case i: IllegalArgumentException =>
|
|
|
|
|
try invoke13 catch { case e: InvocationTargetException => throw e.getCause }
|
|
|
|
|
}
|
2011-04-25 15:27:32 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val scriptedSettings = Seq(
|
2013-06-10 11:54:40 -04:00
|
|
|
ivyConfigurations ++= Seq(scriptedConf, scriptedLaunchConf),
|
|
|
|
|
scriptedSbt <<= sbtVersion,
|
2011-04-28 06:01:53 +03:00
|
|
|
scriptedScalas <<= (scalaVersion) { (scala) => ScriptedScalas(scala, scala) },
|
2013-06-10 11:54:40 -04:00
|
|
|
libraryDependencies <<= (libraryDependencies, scriptedSbt) {(deps, version) =>
|
|
|
|
|
deps ++ Seq(
|
|
|
|
|
"org.scala-sbt" % "scripted-sbt" % version % scriptedConf.toString,
|
|
|
|
|
"org.scala-sbt" % "sbt-launch" % version % scriptedLaunchConf.toString from launcherURL(version)
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
scriptedClasspath <<= getJars(scriptedConf),
|
2011-04-25 15:27:32 +03:00
|
|
|
sbtLauncher <<= (appConfiguration)(app => IO.classLocationFile(app.provider.scalaProvider.launcher.getClass)),
|
2013-06-10 11:54:40 -04:00
|
|
|
sbtLauncherTask <<= getJars(scriptedLaunchConf).map(_.get.head),
|
2011-04-25 15:27:32 +03:00
|
|
|
sbtTestDirectory <<= sourceDirectory / "sbt-test",
|
|
|
|
|
scriptedBufferLog := true,
|
2011-05-14 18:21:41 -04:00
|
|
|
scriptedClasspath <<= (classpathTypes, update) map { (ct, report) => PathFinder(Classpaths.managedJars(scriptedConf, ct, report).map(_.data)) },
|
2011-04-25 15:27:32 +03:00
|
|
|
scriptedTests <<= scriptedTestsTask,
|
|
|
|
|
scriptedRun <<= scriptedRunTask,
|
|
|
|
|
scriptedDependencies <<= (compile in Test, publishLocal) map { (analysis, pub) => Unit },
|
2012-01-20 14:16:23 -08:00
|
|
|
scriptedLaunchOpts := Seq(),
|
2011-04-25 15:27:32 +03:00
|
|
|
scripted <<= scriptedTask
|
|
|
|
|
)
|
2013-06-10 11:54:40 -04:00
|
|
|
private[this] def getJars(config: Configuration): Initialize[Task[PathFinder]] =
|
|
|
|
|
(classpathTypes, update) map { (ct, report) => PathFinder(Classpaths.managedJars(config, ct, report).map(_.data)) }
|
|
|
|
|
private[this] def launcherURL(v: String): String =
|
|
|
|
|
"http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/" + v + "/sbt-launch.jar"
|
2011-04-25 15:27:32 +03:00
|
|
|
}
|