Rename Files to Cache

This commit is contained in:
Alexandre Archambault 2015-12-30 01:34:41 +01:00
parent 064f495114
commit 9f26ed05b2
6 changed files with 20 additions and 20 deletions

View File

@ -234,7 +234,7 @@ case class Bootstrap(
val bootstrapJar = val bootstrapJar =
Option(Thread.currentThread().getContextClassLoader.getResourceAsStream("bootstrap.jar")) match { Option(Thread.currentThread().getContextClassLoader.getResourceAsStream("bootstrap.jar")) match {
case Some(is) => Files.readFullySync(is) case Some(is) => Cache.readFullySync(is)
case None => case None =>
Console.err.println(s"Error: bootstrap JAR not found") Console.err.println(s"Error: bootstrap JAR not found")
sys.exit(1) sys.exit(1)

View File

@ -217,7 +217,7 @@ class Helper(
logger.foreach(_.init()) logger.foreach(_.init())
val fetchs = cachePolicies.map(p => val fetchs = cachePolicies.map(p =>
Files.fetch(caches, p, logger = logger, pool = pool) Cache.fetch(caches, p, logger = logger, pool = pool)
) )
val fetchQuiet = coursier.Fetch( val fetchQuiet = coursier.Fetch(
repositories, repositories,
@ -344,8 +344,8 @@ class Helper(
None None
logger.foreach(_.init()) logger.foreach(_.init())
val tasks = artifacts.map(artifact => val tasks = artifacts.map(artifact =>
(Files.file(artifact, caches, cachePolicies.head, logger = logger, pool = pool) /: cachePolicies.tail)( (Cache.file(artifact, caches, cachePolicies.head, logger = logger, pool = pool) /: cachePolicies.tail)(
_ orElse Files.file(artifact, caches, _, logger = logger, pool = pool) _ orElse Cache.file(artifact, caches, _, logger = logger, pool = pool)
).run.map(artifact.->) ).run.map(artifact.->)
) )
def printTask = Task { def printTask = Task {

View File

@ -5,7 +5,7 @@ import java.util.concurrent._
import ammonite.terminal.{ TTY, Ansi } import ammonite.terminal.{ TTY, Ansi }
import coursier.Files.Logger import coursier.Cache
import scala.annotation.tailrec import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer import scala.collection.mutable.ArrayBuffer
@ -13,7 +13,7 @@ import scala.collection.mutable.ArrayBuffer
class TermDisplay( class TermDisplay(
out: Writer, out: Writer,
var fallbackMode: Boolean = false var fallbackMode: Boolean = false
) extends Logger { ) extends Cache.Logger {
private val ansi = new Ansi(out) private val ansi = new Ansi(out)
private var width = 80 private var width = 80

View File

@ -11,7 +11,7 @@ import scalaz.concurrent.{ Task, Strategy }
import java.io.{ Serializable => _, _ } import java.io.{ Serializable => _, _ }
object Files { object Cache {
def withLocal(artifact: Artifact, cache: Seq[(String, File)]): Artifact = { def withLocal(artifact: Artifact, cache: Seq[(String, File)]): Artifact = {
def local(url: String) = def local(url: String) =
@ -54,7 +54,7 @@ object Files {
checksums: Set[String], checksums: Set[String],
cachePolicy: CachePolicy, cachePolicy: CachePolicy,
pool: ExecutorService, pool: ExecutorService,
logger: Option[Files.Logger] = None logger: Option[Logger] = None
): Task[Seq[((File, String), FileError \/ Unit)]] = { ): Task[Seq[((File, String), FileError \/ Unit)]] = {
implicit val pool0 = pool implicit val pool0 = pool
@ -159,7 +159,7 @@ object Files {
for (len <- Option(conn.getContentLengthLong).filter(_ >= 0L)) for (len <- Option(conn.getContentLengthLong).filter(_ >= 0L))
logger.foreach(_.downloadLength(url, len)) logger.foreach(_.downloadLength(url, len))
val in = new BufferedInputStream(conn.getInputStream, Files.bufferSize) val in = new BufferedInputStream(conn.getInputStream, bufferSize)
val result = val result =
try { try {
@ -172,7 +172,7 @@ object Files {
if (lock == null) if (lock == null)
-\/(FileError.Locked(file)) -\/(FileError.Locked(file))
else { else {
val b = Array.fill[Byte](Files.bufferSize)(0) val b = Array.fill[Byte](bufferSize)(0)
@tailrec @tailrec
def helper(count: Long): Unit = { def helper(count: Long): Unit = {
@ -300,7 +300,7 @@ object Files {
if (lock == null) if (lock == null)
-\/(FileError.Locked(f)) -\/(FileError.Locked(f))
else { else {
Files.withContent(is, md.update(_, 0, _)) withContent(is, md.update(_, 0, _))
\/-(()) \/-(())
} }
} }
@ -333,8 +333,8 @@ object Files {
cache: Seq[(String, File)], cache: Seq[(String, File)],
cachePolicy: CachePolicy, cachePolicy: CachePolicy,
checksums: Seq[Option[String]] = Seq(Some("SHA-1")), checksums: Seq[Option[String]] = Seq(Some("SHA-1")),
logger: Option[Files.Logger] = None, logger: Option[Logger] = None,
pool: ExecutorService = Files.defaultPool pool: ExecutorService = defaultPool
): EitherT[Task, FileError, File] = { ): EitherT[Task, FileError, File] = {
implicit val pool0 = pool implicit val pool0 = pool
@ -384,8 +384,8 @@ object Files {
cache: Seq[(String, File)], cache: Seq[(String, File)],
cachePolicy: CachePolicy, cachePolicy: CachePolicy,
checksums: Seq[Option[String]] = Seq(Some("SHA-1")), checksums: Seq[Option[String]] = Seq(Some("SHA-1")),
logger: Option[Files.Logger] = None, logger: Option[Logger] = None,
pool: ExecutorService = Files.defaultPool pool: ExecutorService = defaultPool
): Fetch.Content[Task] = { ): Fetch.Content[Task] = {
artifact => artifact =>
file( file(

View File

@ -162,8 +162,8 @@ object Tasks {
logger.foreach(_.init()) logger.foreach(_.init())
val fetch = coursier.Fetch( val fetch = coursier.Fetch(
repositories, repositories,
Files.fetch(caches, CachePolicy.LocalOnly, checksums = checksums, logger = logger, pool = pool), Cache.fetch(caches, CachePolicy.LocalOnly, checksums = checksums, logger = logger, pool = pool),
Files.fetch(caches, cachePolicy, checksums = checksums, logger = logger, pool = pool) Cache.fetch(caches, cachePolicy, checksums = checksums, logger = logger, pool = pool)
) )
def depsRepr = currentProject.dependencies.map { case (config, dep) => def depsRepr = currentProject.dependencies.map { case (config, dep) =>
@ -248,7 +248,7 @@ object Tasks {
} }
val artifactFileOrErrorTasks = allArtifacts.toVector.map { a => val artifactFileOrErrorTasks = allArtifacts.toVector.map { a =>
Files.file(a, caches, cachePolicy, checksums = checksums, logger = logger, pool = pool).run.map((a, _)) Cache.file(a, caches, cachePolicy, checksums = checksums, logger = logger, pool = pool).run.map((a, _))
} }
if (verbosity >= 0) if (verbosity >= 0)

View File

@ -1,6 +1,6 @@
package coursier.test package coursier.test
import coursier.{ Module, Files } import coursier.{ Module, Cache }
import utest._ import utest._
object IvyLocalTests extends TestSuite { object IvyLocalTests extends TestSuite {
@ -10,7 +10,7 @@ object IvyLocalTests extends TestSuite {
// Assume this module (and the sub-projects it depends on) is published locally // Assume this module (and the sub-projects it depends on) is published locally
CentralTests.resolutionCheck( CentralTests.resolutionCheck(
Module("com.github.alexarchambault", "coursier_2.11"), "0.1.0-SNAPSHOT", Module("com.github.alexarchambault", "coursier_2.11"), "0.1.0-SNAPSHOT",
Some(Files.ivy2Local)) Some(Cache.ivy2Local))
} }
} }