Skip to content

Instantly share code, notes, and snippets.

@motemen
Last active January 26, 2016 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motemen/580e0039f8c6c827ca40 to your computer and use it in GitHub Desktop.
Save motemen/580e0039f8c6c827ca40 to your computer and use it in GitHub Desktop.
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