Skip to content

Instantly share code, notes, and snippets.

@Duhemm
Last active July 11, 2017 07:28
Show Gist options
  • Save Duhemm/0b2a6a7bd198abfda36f5412d49bdaf9 to your computer and use it in GitHub Desktop.
Save Duhemm/0b2a6a7bd198abfda36f5412d49bdaf9 to your computer and use it in GitHub Desktop.
package lm
import java.io.File
import sbt.librarymanagement._
import sbt.librarymanagement.ivy._
object Main {
def main(args: Array[String]): Unit = {
val Array(org, name, version) = args
fetch(org, name, version, Logger) match {
case Left(_) => ???
case Right(files) =>
files.foreach(f => println(s" * $f"))
}
}
private def getIvy(log: xsbti.Logger): IvyLibraryManagement = {
val resolvers =
Resolver.withDefaultResolvers(Seq.empty, true, true).toVector
val configuration = InlineIvyConfiguration(log)
new IvyLibraryManagement(configuration)
}
private def fetch(org: String,
name: String,
version: String,
log: xsbti.Logger) = {
val ivy = getIvy(log)
val target = new File("out")
val module =
ModuleID(org, name, version).withConfigurations(Some("component"))
ivy.retrieve(module, None, target, log)
}
object Logger extends xsbti.Logger {
def debug(msg: xsbti.F0[String]): Unit = println(s"[debug] ${msg()}")
def error(msg: xsbti.F0[String]): Unit = println(s"[error] ${msg()}")
def info(msg: xsbti.F0[String]): Unit = println(s"[info ] ${msg()}")
def trace(msg: xsbti.F0[Throwable]): Unit = println(s"[trace] ${msg()}")
def warn(msg: xsbti.F0[String]): Unit = println(s"[warn ] ${msg()}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment