diff --git a/USAGE.md b/USAGE.md index c7a47379a..a69607930 100644 --- a/USAGE.md +++ b/USAGE.md @@ -26,11 +26,13 @@ val dependencies = Set( val resolution = Resolution(dependencies) - .process - .run(repositories) - .run + .process // Process ADT, allows to go from a Resolution to the next + .run(repositories) // Running the process, fetching metadata from these repositories + .run // Run the Task[Resolution], and get the resulting Resolution // Note that only metadata are downloaded during resolution +// Repositories use scalaz Task-s. Thus the line .run(repositories) implicitily +// runs the resolution process within Task-s. Alternative monads could run the process too. assert(resolution.isDone) // Check that resolution converged @@ -46,7 +48,10 @@ resolution.artifacts // Seq[Artifact] // "com.github.alexarchambault" %% "coursier-files" % "0.1.0-SNAPSHOT" val files = Files( - Seq(), + Seq( + Repository.mavenCentral.fetch.root -> // URL with this prefix cached in directory: + new java.io.File(sys.props("user.home") + "/.coursier/cache/central/files") + ), () => ???, // TODO Tmp directory for URLs with no cache Some(logger) // Optional, logger: FilesLogger ) diff --git a/core-js/src/main/scala/coursier/core/Fetch.scala b/core-js/src/main/scala/coursier/core/Fetch.scala index 682b58f4b..62828ef3e 100644 --- a/core-js/src/main/scala/coursier/core/Fetch.scala +++ b/core-js/src/main/scala/coursier/core/Fetch.scala @@ -19,13 +19,19 @@ object Fetch { lazy val jsonpAvailable = !js.isUndefined(g.jsonp) + val timeout = + if (jsonpAvailable) + 10000 // Browser - better to have it > 5000 for complex resolutions + else + 4000 // Node - tests crash if not < 5000 + /** Available if we're running on node, and package xhr2 is installed */ lazy val xhr = g.require("xhr2") def xhrReq() = js.Dynamic.newInstance(xhr)().asInstanceOf[XMLHttpRequest] def fetchTimeout(target: String, p: Promise[_]) = - setTimeout(5000) { + setTimeout(timeout) { if (!p.isCompleted) { p.failure(new Exception(s"Timeout when fetching $target")) } @@ -84,13 +90,19 @@ case class Fetch(root: String, def apply(artifact: Artifact, cachePolicy: Repository.CachePolicy): EitherT[Task, String, String] = { + val url0 = root + artifact.url + EitherT( Task { implicit ec => - Fetch.get(root + artifact.url) - .map(\/-(_)) - .recover{case e: Exception => -\/(e.getMessage)} + Future(logger.foreach(_.fetching(url0))) + .flatMap(_ => Fetch.get(url0)) + .map{ s => logger.foreach(_.fetched(url0)); \/-(s) } + .recover{case e: Exception => + logger.foreach(_.other(url0, e.getMessage)) + -\/(e.getMessage) + } } ) } -} \ No newline at end of file +} diff --git a/project/Coursier.scala b/project/Coursier.scala index a530be5b5..809811929 100644 --- a/project/Coursier.scala +++ b/project/Coursier.scala @@ -57,7 +57,6 @@ object CoursierBuild extends Build { lazy val commonSettings = Seq[Setting[_]]( organization := "com.github.alexarchambault", - version := "0.1.0-SNAPSHOT", scalaVersion := "2.11.6", crossScalaVersions := Seq("2.10.5", "2.11.6"), resolvers += "Scalaz Bintray Repo" at "http://dl.bintray.com/scalaz/releases"