Advertisement
Guest User

Untitled

a guest
Sep 17th, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.82 KB | None | 0 0
  1. object Dependencies extends sbt.Plugin with CommandSupport {
  2.  
  3.   override lazy val settings = Seq(commands += myCommand)
  4.  
  5.   lazy val myCommand =
  6.     Command.args("dependencies", "<project>") { deps }
  7.  
  8.   def deps(state: State, args: Seq[String]): State = {
  9.     val extracted = Project.extract(state)
  10.     implicit val pr = extracted.currentRef
  11.     implicit val bs = extracted.structure
  12.  
  13.     val evictedJars: Set[File] = {
  14.       val s: Seq[File] =
  15.       for(
  16.         ep <- evicted.run.allEvictions;
  17.         mr <- ep.evicteds;
  18.         (artifact, file) <- mr.artifacts
  19.       ) yield {
  20.         if (file == null) sys.error(s"Artifact: ${artifact} could not be found at ${file.getAbsolutePath}")
  21.         file
  22.       }
  23.       s.toSet
  24.     }
  25. }
  26.  
  27.  
  28. trait CommandSupport {
  29.   this: Plugin =>
  30.  
  31.   protected def fail(errorMessage: String)(implicit state: State): Nothing = {
  32.     state.log.error(errorMessage)
  33.     throw new IllegalArgumentException()
  34.   }
  35.  
  36.   protected def log(implicit state: State) = state.log
  37.  
  38.   // our version of http://stackoverflow.com/questions/25246920
  39.   protected implicit class RichSettingKey[A](key: SettingKey[A]) {
  40.     def gimme(implicit pr: ProjectRef, bs: BuildStructure, s: State): A =
  41.       gimmeOpt getOrElse { fail(s"Missing setting: ${key.key.label}") }
  42.     def gimmeOpt(implicit pr: ProjectRef, bs: BuildStructure, s: State): Option[A] =
  43.       key in pr get bs.data
  44.   }
  45.  
  46.   protected implicit class RichTaskKey[A](key: TaskKey[A]) {
  47.     def run(implicit pr: ProjectRef, bs: BuildStructure, s: State): A =
  48.       runOpt.getOrElse { fail(s"Missing task key: ${key.key.label}") }
  49.     def runOpt(implicit pr: ProjectRef, bs: BuildStructure, s: State): Option[A] =
  50.       EvaluateTask(bs, key, s, pr).map(_._2) match {
  51.         case Some(Value(v)) => Some(v)
  52.         case _              => None
  53.       }
  54.   }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement