mirror of https://github.com/sbt/sbt.git
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:
parent
4e3693179b
commit
4b0b3a05f9
|
|
@ -30,9 +30,8 @@ import sbt.util.Logger
|
||||||
import sbt.librarymanagement._
|
import sbt.librarymanagement._
|
||||||
import Resolver.PluginPattern
|
import Resolver.PluginPattern
|
||||||
import ivyint.{ CachedResolutionResolveEngine, CachedResolutionResolveCache, SbtDefaultDependencyDescriptor }
|
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
|
import configuration.baseDirectory
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -93,8 +92,7 @@ final class IvySbt(val configuration: IvyConfiguration, fileToStore: File => Cac
|
||||||
setEventManager(new EventManager())
|
setEventManager(new EventManager())
|
||||||
if (configuration.updateOptions.cachedResolution) {
|
if (configuration.updateOptions.cachedResolution) {
|
||||||
setResolveEngine(new ResolveEngine(getSettings, getEventManager, getSortEngine) with CachedResolutionResolveEngine {
|
setResolveEngine(new ResolveEngine(getSettings, getEventManager, getSortEngine) with CachedResolutionResolveEngine {
|
||||||
override private[sbt] val fileToStore: File => CacheStore = self.fileToStore
|
val cachedResolutionResolveCache = IvySbt.cachedResolutionResolveCache
|
||||||
val cachedResolutionResolveCache = IvySbt.cachedResolutionResolveCache(fileToStore)
|
|
||||||
val projectResolver = prOpt
|
val projectResolver = prOpt
|
||||||
def makeInstance = mkIvy
|
def makeInstance = mkIvy
|
||||||
})
|
})
|
||||||
|
|
@ -141,7 +139,7 @@ final class IvySbt(val configuration: IvyConfiguration, fileToStore: File => Cac
|
||||||
withIvy(log) { i =>
|
withIvy(log) { i =>
|
||||||
val prOpt = Option(i.getSettings.getResolver(ProjectResolver.InterProject)) map { case pr: ProjectResolver => pr }
|
val prOpt = Option(i.getSettings.getResolver(ProjectResolver.InterProject)) map { case pr: ProjectResolver => pr }
|
||||||
if (configuration.updateOptions.cachedResolution) {
|
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 DefaultIvyFilename = "ivy.xml"
|
||||||
val DefaultMavenFilename = "pom.xml"
|
val DefaultMavenFilename = "pom.xml"
|
||||||
val DefaultChecksums = Vector("sha1", "md5")
|
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 defaultIvyFile(project: File) = new File(project, DefaultIvyFilename)
|
||||||
def defaultIvyConfiguration(project: File) = new File(project, DefaultIvyConfigFilename)
|
def defaultIvyConfiguration(project: File) = new File(project, DefaultIvyConfigFilename)
|
||||||
|
|
|
||||||
|
|
@ -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.plugins.resolver.util.ResolvedResource
|
||||||
import org.apache.ivy.util.FileUtil
|
import org.apache.ivy.util.FileUtil
|
||||||
import sbt.io.Path
|
import sbt.io.Path
|
||||||
import sbt.util.Logger
|
|
||||||
import sbt.librarymanagement._
|
import sbt.librarymanagement._
|
||||||
|
import sbt.util.Logger
|
||||||
import sbt.internal.util.{ CacheStore, FileBasedStore }
|
|
||||||
|
|
||||||
import scala.json.ast.unsafe._
|
import scala.json.ast.unsafe._
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
import jawn.{ SupportParser, MutableFacade }
|
import jawn.{ SupportParser, MutableFacade }
|
||||||
import sjsonnew.IsoString
|
|
||||||
import sjsonnew.support.scalajson.unsafe.{ CompactPrinter, Converter }
|
|
||||||
|
|
||||||
class NotInCache(val id: ModuleID, cause: Throwable)
|
class NotInCache(val id: ModuleID, cause: Throwable)
|
||||||
extends RuntimeException(NotInCache(id, cause), cause) {
|
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.*/
|
/** 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) {
|
class IvyCache(val ivyHome: Option[File]) {
|
||||||
def this(ivyHome: Option[File]) = this(ivyHome, DefaultFileToStore)
|
|
||||||
|
|
||||||
def lockFile = new File(ivyHome getOrElse Path.userHome, ".sbt.cache.lock")
|
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.*/
|
/** 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 = {
|
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 local = Resolver.defaultLocal
|
||||||
val paths = IvyPaths(new File("."), ivyHome)
|
val paths = IvyPaths(new File("."), ivyHome)
|
||||||
val conf = new InlineIvyConfiguration(paths, Vector(local), Vector.empty, Vector.empty, false, lock, IvySbt.DefaultChecksums, None, UpdateOptions(), log)
|
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.*/
|
/** Creates a default jar artifact based on the given ID.*/
|
||||||
private def defaultArtifact(moduleID: ModuleID): IvyArtifact =
|
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)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -3,22 +3,18 @@ package sbt.internal.librarymanagement
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import org.apache.ivy.core
|
import org.apache.ivy.core
|
||||||
import core.module.descriptor.ModuleDescriptor
|
import core.module.descriptor.ModuleDescriptor
|
||||||
import sbt.util.Logger
|
import sbt.util.{ CacheStore, Logger }
|
||||||
import sbt.internal.util.CacheStore
|
|
||||||
import sbt.librarymanagement._
|
import sbt.librarymanagement._
|
||||||
import sbt.librarymanagement.LibraryManagementCodec._
|
import sbt.librarymanagement.LibraryManagementCodec._
|
||||||
import JsonUtil._
|
|
||||||
|
|
||||||
private[sbt] object JsonUtil {
|
private[sbt] object JsonUtil {
|
||||||
def sbtOrgTemp = "org.scala-sbt.temp"
|
def sbtOrgTemp = "org.scala-sbt.temp"
|
||||||
def fakeCallerOrganization = "org.scala-sbt.temp-callers"
|
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 =
|
def parseUpdateReport(md: ModuleDescriptor, path: File, cachedDescriptor: File, log: Logger): UpdateReport =
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
val lite = fileToStore(path).read[UpdateReportLite]
|
val lite = CacheStore(path).read[UpdateReportLite]
|
||||||
fromLite(lite, cachedDescriptor)
|
fromLite(lite, cachedDescriptor)
|
||||||
} catch {
|
} catch {
|
||||||
case e: Throwable =>
|
case e: Throwable =>
|
||||||
|
|
@ -29,7 +25,7 @@ private[sbt] class JsonUtil(fileToStore: File => CacheStore) {
|
||||||
def writeUpdateReport(ur: UpdateReport, graphPath: File): Unit =
|
def writeUpdateReport(ur: UpdateReport, graphPath: File): Unit =
|
||||||
{
|
{
|
||||||
sbt.io.IO.createDirectory(graphPath.getParentFile)
|
sbt.io.IO.createDirectory(graphPath.getParentFile)
|
||||||
fileToStore(graphPath).write(toLite(ur))
|
CacheStore(graphPath).write(toLite(ur))
|
||||||
}
|
}
|
||||||
def toLite(ur: UpdateReport): UpdateReportLite =
|
def toLite(ur: UpdateReport): UpdateReportLite =
|
||||||
UpdateReportLite(ur.configurations map { cr =>
|
UpdateReportLite(ur.configurations map { cr =>
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,8 @@ import org.apache.ivy.plugins.matcher.{ MapMatcher, PatternMatcher }
|
||||||
import annotation.tailrec
|
import annotation.tailrec
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
import sbt.io.{ DirectoryFilter, Hash, IO }
|
import sbt.io.{ DirectoryFilter, Hash, IO }
|
||||||
import sbt.util.Logger
|
|
||||||
import sbt.librarymanagement._, syntax._
|
import sbt.librarymanagement._, syntax._
|
||||||
import sbt.internal.util.CacheStore
|
import sbt.util.Logger
|
||||||
|
|
||||||
private[sbt] object CachedResolutionResolveCache {
|
private[sbt] object CachedResolutionResolveCache {
|
||||||
def createID(organization: String, name: String, revision: String) =
|
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")
|
lazy val yyyymmdd: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd")
|
||||||
}
|
}
|
||||||
|
|
||||||
private[sbt] class CachedResolutionResolveCache(fileToStore: File => CacheStore) {
|
private[sbt] class CachedResolutionResolveCache {
|
||||||
import CachedResolutionResolveCache._
|
import CachedResolutionResolveCache._
|
||||||
val jsonUtil = new JsonUtil(fileToStore)
|
|
||||||
val updateReportCache: concurrent.Map[ModuleRevisionId, Either[ResolveException, UpdateReport]] = concurrent.TrieMap()
|
val updateReportCache: concurrent.Map[ModuleRevisionId, Either[ResolveException, UpdateReport]] = concurrent.TrieMap()
|
||||||
// Used for subproject
|
// Used for subproject
|
||||||
val projectReportCache: concurrent.Map[(ModuleRevisionId, LogicalClock), Either[ResolveException, UpdateReport]] = concurrent.TrieMap()
|
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 {
|
else None) match {
|
||||||
case Some(path) =>
|
case Some(path) =>
|
||||||
log.debug(s"parsing ${path.getAbsolutePath.toString}")
|
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 }) {
|
if (ur.allFiles forall { _.exists }) {
|
||||||
updateReportCache(md.getModuleRevisionId) = Right(ur)
|
updateReportCache(md.getModuleRevisionId) = Right(ur)
|
||||||
Some(Right(ur))
|
Some(Right(ur))
|
||||||
|
|
@ -199,7 +197,7 @@ private[sbt] class CachedResolutionResolveCache(fileToStore: File => CacheStore)
|
||||||
if (changing) {
|
if (changing) {
|
||||||
cleanDynamicGraph()
|
cleanDynamicGraph()
|
||||||
}
|
}
|
||||||
jsonUtil.writeUpdateReport(ur, gp)
|
JsonUtil.writeUpdateReport(ur, gp)
|
||||||
// limit the update cache size
|
// limit the update cache size
|
||||||
if (updateReportCache.size > maxUpdateReportCacheSize) {
|
if (updateReportCache.size > maxUpdateReportCacheSize) {
|
||||||
updateReportCache.remove(updateReportCache.head._1)
|
updateReportCache.remove(updateReportCache.head._1)
|
||||||
|
|
@ -258,9 +256,6 @@ private[sbt] trait CachedResolutionResolveEngine extends ResolveEngine {
|
||||||
private[sbt] def makeInstance: Ivy
|
private[sbt] def makeInstance: Ivy
|
||||||
private[sbt] val ignoreTransitiveForce: Boolean = true
|
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 =
|
def withIvy[A](log: Logger)(f: Ivy => A): A =
|
||||||
withIvy(new IvyLoggerInterface(log))(f)
|
withIvy(new IvyLoggerInterface(log))(f)
|
||||||
def withIvy[A](log: MessageLogger)(f: Ivy => A): A =
|
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
|
if (mr.evicted || mr.problem.nonEmpty) None
|
||||||
else
|
else
|
||||||
// https://github.com/sbt/sbt/issues/1763
|
// https://github.com/sbt/sbt/issues/1763
|
||||||
Some(mr.withCallers(jsonUtil.filterOutArtificialCallers(mr.callers)))
|
Some(mr.withCallers(JsonUtil.filterOutArtificialCallers(mr.callers)))
|
||||||
} match {
|
} match {
|
||||||
case Vector() => None
|
case Vector() => None
|
||||||
case ms => Some(OrganizationArtifactReport(report0.organization, report0.name, ms))
|
case ms => Some(OrganizationArtifactReport(report0.organization, report0.name, ms))
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import sbt.util.Logger
|
||||||
import sbt.io.Hash
|
import sbt.io.Hash
|
||||||
|
|
||||||
class DefaultLibraryManagement(ivyConfiguration: IvyConfiguration, log: Logger) extends LibraryManagement {
|
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 sbtOrgTemp = JsonUtil.sbtOrgTemp
|
||||||
private val modulePrefixTemp = "temp-module-"
|
private val modulePrefixTemp = "temp-module-"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,6 @@ import sbt.internal.util.ConsoleLogger
|
||||||
import sbt.librarymanagement._
|
import sbt.librarymanagement._
|
||||||
import Configurations._
|
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 {
|
trait BaseIvySpecification extends UnitSpec {
|
||||||
def currentBase: File = new File(".")
|
def currentBase: File = new File(".")
|
||||||
def currentTarget: File = currentBase / "target" / "ivyhome"
|
def currentTarget: File = currentBase / "target" / "ivyhome"
|
||||||
|
|
@ -22,8 +15,6 @@ trait BaseIvySpecification extends UnitSpec {
|
||||||
def currentDependency: File = currentBase / "target" / "dependency"
|
def currentDependency: File = currentBase / "target" / "dependency"
|
||||||
def defaultModuleId: ModuleID = ModuleID("com.example", "foo", "0.1.0").withConfigurations(Some("compile"))
|
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()
|
lazy val log = ConsoleLogger()
|
||||||
|
|
||||||
def configurations = Vector(Compile, Test, Runtime)
|
def configurations = Vector(Compile, Test, Runtime)
|
||||||
|
|
@ -47,7 +38,7 @@ trait BaseIvySpecification extends UnitSpec {
|
||||||
moduleInfo = ModuleInfo("foo"),
|
moduleInfo = ModuleInfo("foo"),
|
||||||
dependencies = deps
|
dependencies = deps
|
||||||
).withConfigurations(configurations)
|
).withConfigurations(configurations)
|
||||||
val ivySbt = new IvySbt(mkIvyConfiguration(uo), fileToStore)
|
val ivySbt = new IvySbt(mkIvyConfiguration(uo))
|
||||||
new ivySbt.Module(moduleSetting)
|
new ivySbt.Module(moduleSetting)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class CustomPomParserTest extends UnitSpec {
|
||||||
val local = MavenRepository("Test Repo", repoUrl.toExternalForm)
|
val local = MavenRepository("Test Repo", repoUrl.toExternalForm)
|
||||||
val paths = IvyPaths(new File("."), Some(cacheDir))
|
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 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 resolveOpts = new ResolveOptions().setConfs(Array("default"))
|
||||||
val mrid = ModuleRevisionId.newInstance("com.test", "test-artifact", "1.0.0-SNAPSHOT")
|
val mrid = ModuleRevisionId.newInstance("com.test", "test-artifact", "1.0.0-SNAPSHOT")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ object Dependencies {
|
||||||
val scala211 = "2.11.8"
|
val scala211 = "2.11.8"
|
||||||
val scala212 = "2.12.1"
|
val scala212 = "2.12.1"
|
||||||
|
|
||||||
private val ioVersion = "1.0.0-M10"
|
private val ioVersion = "1.0.0-M11"
|
||||||
private val utilVersion = "1.0.0-M22"
|
private val utilVersion = "1.0.0-M23"
|
||||||
|
|
||||||
private val sbtIO = "org.scala-sbt" %% "io" % ioVersion
|
private val sbtIO = "org.scala-sbt" %% "io" % ioVersion
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
sbt.version=0.13.13
|
sbt.version=0.13.15
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue