Bump to util 1.0.0-M23

I'm now going to use `CacheStore.apply` in `JsonUtil` (used by cached resolution). This gets rid of `fileToStore` parameter from a bunch of classes and simplifies the setup around librarymanagement.
This commit is contained in:
Eugene Yokota 2017-04-17 13:06:32 -04:00
parent 4e3693179b
commit 4b0b3a05f9
9 changed files with 21 additions and 52 deletions

View File

@ -30,9 +30,8 @@ import sbt.util.Logger
import sbt.librarymanagement._
import Resolver.PluginPattern
import ivyint.{ CachedResolutionResolveEngine, CachedResolutionResolveCache, SbtDefaultDependencyDescriptor }
import sbt.internal.util.CacheStore
final class IvySbt(val configuration: IvyConfiguration, fileToStore: File => CacheStore) { self =>
final class IvySbt(val configuration: IvyConfiguration) { self =>
import configuration.baseDirectory
/*
@ -93,8 +92,7 @@ final class IvySbt(val configuration: IvyConfiguration, fileToStore: File => Cac
setEventManager(new EventManager())
if (configuration.updateOptions.cachedResolution) {
setResolveEngine(new ResolveEngine(getSettings, getEventManager, getSortEngine) with CachedResolutionResolveEngine {
override private[sbt] val fileToStore: File => CacheStore = self.fileToStore
val cachedResolutionResolveCache = IvySbt.cachedResolutionResolveCache(fileToStore)
val cachedResolutionResolveCache = IvySbt.cachedResolutionResolveCache
val projectResolver = prOpt
def makeInstance = mkIvy
})
@ -141,7 +139,7 @@ final class IvySbt(val configuration: IvyConfiguration, fileToStore: File => Cac
withIvy(log) { i =>
val prOpt = Option(i.getSettings.getResolver(ProjectResolver.InterProject)) map { case pr: ProjectResolver => pr }
if (configuration.updateOptions.cachedResolution) {
IvySbt.cachedResolutionResolveCache(fileToStore).clean(md, prOpt)
IvySbt.cachedResolutionResolveCache.clean(md, prOpt)
}
}
@ -251,7 +249,7 @@ private[sbt] object IvySbt {
val DefaultIvyFilename = "ivy.xml"
val DefaultMavenFilename = "pom.xml"
val DefaultChecksums = Vector("sha1", "md5")
private[sbt] def cachedResolutionResolveCache(fileToStore: File => CacheStore): CachedResolutionResolveCache = new CachedResolutionResolveCache(fileToStore)
private[sbt] def cachedResolutionResolveCache: CachedResolutionResolveCache = new CachedResolutionResolveCache
def defaultIvyFile(project: File) = new File(project, DefaultIvyFilename)
def defaultIvyConfiguration(project: File) = new File(project, DefaultIvyConfigFilename)

View File

@ -12,16 +12,12 @@ import org.apache.ivy.plugins.repository.{ ArtifactResourceResolver, Resource, R
import org.apache.ivy.plugins.resolver.util.ResolvedResource
import org.apache.ivy.util.FileUtil
import sbt.io.Path
import sbt.util.Logger
import sbt.librarymanagement._
import sbt.internal.util.{ CacheStore, FileBasedStore }
import sbt.util.Logger
import scala.json.ast.unsafe._
import scala.collection.mutable
import jawn.{ SupportParser, MutableFacade }
import sjsonnew.IsoString
import sjsonnew.support.scalajson.unsafe.{ CompactPrinter, Converter }
class NotInCache(val id: ModuleID, cause: Throwable)
extends RuntimeException(NotInCache(id, cause), cause) {
@ -35,9 +31,7 @@ private object NotInCache {
}
}
/** Provides methods for working at the level of a single jar file with the default Ivy cache.*/
class IvyCache(val ivyHome: Option[File], fileToStore: File => CacheStore) {
def this(ivyHome: Option[File]) = this(ivyHome, DefaultFileToStore)
class IvyCache(val ivyHome: Option[File]) {
def lockFile = new File(ivyHome getOrElse Path.userHome, ".sbt.cache.lock")
/** Caches the given 'file' with the given ID. It may be retrieved or cleared using this ID.*/
def cacheJar(moduleID: ModuleID, file: File, lock: Option[xsbti.GlobalLock], log: Logger): Unit = {
@ -92,7 +86,7 @@ class IvyCache(val ivyHome: Option[File], fileToStore: File => CacheStore) {
val local = Resolver.defaultLocal
val paths = IvyPaths(new File("."), ivyHome)
val conf = new InlineIvyConfiguration(paths, Vector(local), Vector.empty, Vector.empty, false, lock, IvySbt.DefaultChecksums, None, UpdateOptions(), log)
(new IvySbt(conf, fileToStore), local)
(new IvySbt(conf), local)
}
/** Creates a default jar artifact based on the given ID.*/
private def defaultArtifact(moduleID: ModuleID): IvyArtifact =
@ -131,8 +125,3 @@ object FixedParser extends SupportParser[JValue] {
}
}
}
object DefaultFileToStore extends (File => CacheStore) {
private implicit lazy val isoString: IsoString[JValue] = IsoString.iso(CompactPrinter.apply _, FixedParser.parseUnsafe _)
override def apply(f: File): CacheStore = new FileBasedStore(f, Converter)
}

View File

@ -3,22 +3,18 @@ package sbt.internal.librarymanagement
import java.io.File
import org.apache.ivy.core
import core.module.descriptor.ModuleDescriptor
import sbt.util.Logger
import sbt.internal.util.CacheStore
import sbt.util.{ CacheStore, Logger }
import sbt.librarymanagement._
import sbt.librarymanagement.LibraryManagementCodec._
import JsonUtil._
private[sbt] object JsonUtil {
def sbtOrgTemp = "org.scala-sbt.temp"
def fakeCallerOrganization = "org.scala-sbt.temp-callers"
}
private[sbt] class JsonUtil(fileToStore: File => CacheStore) {
def parseUpdateReport(md: ModuleDescriptor, path: File, cachedDescriptor: File, log: Logger): UpdateReport =
{
try {
val lite = fileToStore(path).read[UpdateReportLite]
val lite = CacheStore(path).read[UpdateReportLite]
fromLite(lite, cachedDescriptor)
} catch {
case e: Throwable =>
@ -29,7 +25,7 @@ private[sbt] class JsonUtil(fileToStore: File => CacheStore) {
def writeUpdateReport(ur: UpdateReport, graphPath: File): Unit =
{
sbt.io.IO.createDirectory(graphPath.getParentFile)
fileToStore(graphPath).write(toLite(ur))
CacheStore(graphPath).write(toLite(ur))
}
def toLite(ur: UpdateReport): UpdateReportLite =
UpdateReportLite(ur.configurations map { cr =>

View File

@ -21,9 +21,8 @@ import org.apache.ivy.plugins.matcher.{ MapMatcher, PatternMatcher }
import annotation.tailrec
import scala.concurrent.duration._
import sbt.io.{ DirectoryFilter, Hash, IO }
import sbt.util.Logger
import sbt.librarymanagement._, syntax._
import sbt.internal.util.CacheStore
import sbt.util.Logger
private[sbt] object CachedResolutionResolveCache {
def createID(organization: String, name: String, revision: String) =
@ -38,9 +37,8 @@ private[sbt] object CachedResolutionResolveCache {
lazy val yyyymmdd: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd")
}
private[sbt] class CachedResolutionResolveCache(fileToStore: File => CacheStore) {
private[sbt] class CachedResolutionResolveCache {
import CachedResolutionResolveCache._
val jsonUtil = new JsonUtil(fileToStore)
val updateReportCache: concurrent.Map[ModuleRevisionId, Either[ResolveException, UpdateReport]] = concurrent.TrieMap()
// Used for subproject
val projectReportCache: concurrent.Map[(ModuleRevisionId, LogicalClock), Either[ResolveException, UpdateReport]] = concurrent.TrieMap()
@ -165,7 +163,7 @@ private[sbt] class CachedResolutionResolveCache(fileToStore: File => CacheStore)
else None) match {
case Some(path) =>
log.debug(s"parsing ${path.getAbsolutePath.toString}")
val ur = jsonUtil.parseUpdateReport(md, path, cachedDescriptor, log)
val ur = JsonUtil.parseUpdateReport(md, path, cachedDescriptor, log)
if (ur.allFiles forall { _.exists }) {
updateReportCache(md.getModuleRevisionId) = Right(ur)
Some(Right(ur))
@ -199,7 +197,7 @@ private[sbt] class CachedResolutionResolveCache(fileToStore: File => CacheStore)
if (changing) {
cleanDynamicGraph()
}
jsonUtil.writeUpdateReport(ur, gp)
JsonUtil.writeUpdateReport(ur, gp)
// limit the update cache size
if (updateReportCache.size > maxUpdateReportCacheSize) {
updateReportCache.remove(updateReportCache.head._1)
@ -258,9 +256,6 @@ private[sbt] trait CachedResolutionResolveEngine extends ResolveEngine {
private[sbt] def makeInstance: Ivy
private[sbt] val ignoreTransitiveForce: Boolean = true
private[sbt] val fileToStore: File => CacheStore
private val jsonUtil = new JsonUtil(fileToStore)
def withIvy[A](log: Logger)(f: Ivy => A): A =
withIvy(new IvyLoggerInterface(log))(f)
def withIvy[A](log: MessageLogger)(f: Ivy => A): A =
@ -432,7 +427,7 @@ private[sbt] trait CachedResolutionResolveEngine extends ResolveEngine {
if (mr.evicted || mr.problem.nonEmpty) None
else
// https://github.com/sbt/sbt/issues/1763
Some(mr.withCallers(jsonUtil.filterOutArtificialCallers(mr.callers)))
Some(mr.withCallers(JsonUtil.filterOutArtificialCallers(mr.callers)))
} match {
case Vector() => None
case ms => Some(OrganizationArtifactReport(report0.organization, report0.name, ms))

View File

@ -7,7 +7,7 @@ import sbt.util.Logger
import sbt.io.Hash
class DefaultLibraryManagement(ivyConfiguration: IvyConfiguration, log: Logger) extends LibraryManagement {
private[sbt] val ivySbt: IvySbt = new IvySbt(ivyConfiguration, DefaultFileToStore)
private[sbt] val ivySbt: IvySbt = new IvySbt(ivyConfiguration)
private val sbtOrgTemp = JsonUtil.sbtOrgTemp
private val modulePrefixTemp = "temp-module-"

View File

@ -8,13 +8,6 @@ import sbt.internal.util.ConsoleLogger
import sbt.librarymanagement._
import Configurations._
import sbt.internal.util.FileBasedStore
import sjsonnew.IsoString
import sjsonnew.support.scalajson.unsafe.{ CompactPrinter, Converter }
import scala.json.ast.unsafe.JValue
trait BaseIvySpecification extends UnitSpec {
def currentBase: File = new File(".")
def currentTarget: File = currentBase / "target" / "ivyhome"
@ -22,8 +15,6 @@ trait BaseIvySpecification extends UnitSpec {
def currentDependency: File = currentBase / "target" / "dependency"
def defaultModuleId: ModuleID = ModuleID("com.example", "foo", "0.1.0").withConfigurations(Some("compile"))
implicit val isoString: IsoString[JValue] = IsoString.iso(CompactPrinter.apply, FixedParser.parseUnsafe)
val fileToStore = (f: File) => new FileBasedStore(f, Converter)
lazy val log = ConsoleLogger()
def configurations = Vector(Compile, Test, Runtime)
@ -47,7 +38,7 @@ trait BaseIvySpecification extends UnitSpec {
moduleInfo = ModuleInfo("foo"),
dependencies = deps
).withConfigurations(configurations)
val ivySbt = new IvySbt(mkIvyConfiguration(uo), fileToStore)
val ivySbt = new IvySbt(mkIvyConfiguration(uo))
new ivySbt.Module(moduleSetting)
}

View File

@ -16,7 +16,7 @@ class CustomPomParserTest extends UnitSpec {
val local = MavenRepository("Test Repo", repoUrl.toExternalForm)
val paths = IvyPaths(new File("."), Some(cacheDir))
val conf = new InlineIvyConfiguration(paths, Vector(local), Vector.empty, Vector.empty, false, None, Vector("sha1", "md5"), None, UpdateOptions(), log)
val ivySbt = new IvySbt(conf, DefaultFileToStore)
val ivySbt = new IvySbt(conf)
val resolveOpts = new ResolveOptions().setConfs(Array("default"))
val mrid = ModuleRevisionId.newInstance("com.test", "test-artifact", "1.0.0-SNAPSHOT")

View File

@ -5,8 +5,8 @@ object Dependencies {
val scala211 = "2.11.8"
val scala212 = "2.12.1"
private val ioVersion = "1.0.0-M10"
private val utilVersion = "1.0.0-M22"
private val ioVersion = "1.0.0-M11"
private val utilVersion = "1.0.0-M23"
private val sbtIO = "org.scala-sbt" %% "io" % ioVersion

View File

@ -1 +1 @@
sbt.version=0.13.13
sbt.version=0.13.15