Skip to content

Instantly share code, notes, and snippets.

@larsrh
Created November 22, 2015 09:59
Show Gist options
  • Save larsrh/42da43aa74dc4e78aa59 to your computer and use it in GitHub Desktop.
Save larsrh/42da43aa74dc4e78aa59 to your computer and use it in GitHub Desktop.
Resolving multiple artifacts
def fetchPIDE(version: Version)(implicit ec: ExecutionContext): Future[List[Path]] = {
val repositories = Seq(Repository.ivy2Local, Repository.mavenCentral, Repository.sonatypeReleases)
val files = coursier.Files(
Seq("https://" -> new File(sys.props("user.home") + "/.libisabelle/cache")),
() => sys.error("impossible")
)
val cachePolicy = Repository.CachePolicy.Default
def resolve(identifier: String) = {
val dependency =
Dependency(
Module(BuildInfo.organization, s"pide-${identifier}_${BuildInfo.scalaBinaryVersion}"),
BuildInfo.version
)
Resolution(Set(dependency)).process.run(repositories).toScalaFuture.map { res =>
if (!res.isDone)
sys.error("not converged")
else if (!res.errors.isEmpty)
sys.error(s"errors: ${res.errors}")
else
res.artifacts.toSet
}
}
val pideInterface = resolve("interface")
val pideVersion = resolve(version.identifier)
for {
i <- pideInterface
v <- pideVersion
artifacts = v -- i
res <- Future.traverse(artifacts.toList)(files.file(_, cachePolicy).run.toScalaFuture)
}
yield
res.map(_.fold(sys.error, _.toPath))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment