Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Dependencies extends sbt.Plugin with CommandSupport {
- override lazy val settings = Seq(commands += myCommand)
- lazy val myCommand =
- Command.args("dependencies", "<project>") { deps }
- def deps(state: State, args: Seq[String]): State = {
- val extracted = Project.extract(state)
- implicit val pr = extracted.currentRef
- implicit val bs = extracted.structure
- val evictedJars: Set[File] = {
- val s: Seq[File] =
- for(
- ep <- evicted.run.allEvictions;
- mr <- ep.evicteds;
- (artifact, file) <- mr.artifacts
- ) yield {
- if (file == null) sys.error(s"Artifact: ${artifact} could not be found at ${file.getAbsolutePath}")
- file
- }
- s.toSet
- }
- }
- trait CommandSupport {
- this: Plugin =>
- protected def fail(errorMessage: String)(implicit state: State): Nothing = {
- state.log.error(errorMessage)
- throw new IllegalArgumentException()
- }
- protected def log(implicit state: State) = state.log
- // our version of http://stackoverflow.com/questions/25246920
- protected implicit class RichSettingKey[A](key: SettingKey[A]) {
- def gimme(implicit pr: ProjectRef, bs: BuildStructure, s: State): A =
- gimmeOpt getOrElse { fail(s"Missing setting: ${key.key.label}") }
- def gimmeOpt(implicit pr: ProjectRef, bs: BuildStructure, s: State): Option[A] =
- key in pr get bs.data
- }
- protected implicit class RichTaskKey[A](key: TaskKey[A]) {
- def run(implicit pr: ProjectRef, bs: BuildStructure, s: State): A =
- runOpt.getOrElse { fail(s"Missing task key: ${key.key.label}") }
- def runOpt(implicit pr: ProjectRef, bs: BuildStructure, s: State): Option[A] =
- EvaluateTask(bs, key, s, pr).map(_._2) match {
- case Some(Value(v)) => Some(v)
- case _ => None
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement