Last active
January 26, 2016 10:44
-
-
Save motemen/580e0039f8c6c827ca40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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