Skip to content

Instantly share code, notes, and snippets.

@motemen motemen/ghq.sbt
Last active Jan 26, 2016

Embed
What would you like to do?
lazy val ghqGetDepndencies = taskKey[Unit]("""Download dependencies using "ghq get".""")
ghqGetDepndencies <<= (ivyPaths, libraryDependencies, streams) map {
(ivyPaths, libraryDependencies, s) =>
new IvyCache(ivyPaths.ivyHome).withDefaultCache(None, s.log) {
cache =>
libraryDependencies.foreach {
m =>
import org.apache.ivy.core.module.id.ModuleRevisionId
import scala.collection.JavaConversions._
import scala.xml.parsing.ConstructingParser
val modRevId = ModuleRevisionId.newInstance(m.organization, m.name, m.revision, m.extraAttributes)
val path = cache.getIvyFileInCache(modRevId).getPath
try {
val doc = ConstructingParser.fromSource(io.Source.fromFile(s"$path.original"), preserveWS = false).document()
val pat = "^scm:(?:git|hg|svn):(.+)$".r
(doc \ "scm" \ "connection").text match {
case pat(url) =>
s.log.info(s"$modRevId :: $url")
Process(Seq("ghq", "get", url)) !
case _ =>
s.log.info(s"$modRevId :: (not found)")
}
} catch {
case e: Throwable =>
s.log.warn(s"$modRevId :: $e")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.