Remove previous custom offline implementation

The previous custom offline implementation was not working on 100% of
the cases and relied on the TTL of ivy. As the previous commit
enabled the native offline implementation provided by ivy as of 2.3.0,
this functionality is not useful anymore.

The current place to specify offline is `UpdateConfiguration`, and not
`InlineIvyConfiguration` that is required to instantiate sbt. With the
current approach, we can be online or offline without having to
instantiate ivy sbt twice.

I will provide a Scalafix rewrite for this change.
This commit is contained in:
jvican 2017-05-05 20:41:32 +02:00
parent 67d9012a17
commit 96c775c445
No known key found for this signature in database
GPG Key ID: 42DAFA0F112E8050
7 changed files with 52 additions and 67 deletions

View File

@ -729,7 +729,6 @@
{ "name": "resolvers", "type": "sbt.librarymanagement.Resolver*" },
{ "name": "otherResolvers", "type": "sbt.librarymanagement.Resolver*" },
{ "name": "moduleConfigurations", "type": "sbt.librarymanagement.ModuleConfiguration*" },
{ "name": "localOnly", "type": "boolean" },
{ "name": "checksums", "type": "String*" },
{ "name": "resolutionCacheDir", "type": "java.io.File?" }
],
@ -739,7 +738,6 @@
" resolvers: Vector[sbt.librarymanagement.Resolver],",
" otherResolvers: Vector[sbt.librarymanagement.Resolver],",
" moduleConfigurations: Vector[sbt.librarymanagement.ModuleConfiguration],",
" localOnly: Boolean,",
" lock: Option[xsbti.GlobalLock],",
" checksums: Vector[String],",
" resolutionCacheDir: Option[java.io.File],",
@ -747,7 +745,7 @@
" log: xsbti.Logger",
") =",
" this(lock, paths.baseDirectory, log, updateOptions, paths, resolvers, otherResolvers,",
" moduleConfigurations, localOnly, checksums, resolutionCacheDir)"
" moduleConfigurations, checksums, resolutionCacheDir)"
]
},
{

View File

@ -202,7 +202,7 @@ private[sbt] object ConvertResolver {
resolver
}
case repo: ChainedResolver =>
IvySbt.resolverChain(repo.name, repo.resolvers, false, settings, log)
IvySbt.resolverChain(repo.name, repo.resolvers, settings, log)
case repo: RawRepository => repo.resolver
}
}

View File

@ -88,16 +88,10 @@ final class IvySbt(val configuration: IvyConfiguration) { self =>
case i: InlineIvyConfiguration =>
is.setVariable("ivy.checksums", i.checksums mkString ",")
i.paths.ivyHome foreach is.setDefaultIvyUserDir
IvySbt.configureCache(is, i.localOnly, i.resolutionCacheDir)
IvySbt.setResolvers(
is,
i.resolvers,
i.otherResolvers,
i.localOnly,
configuration.updateOptions,
configuration.log
)
IvySbt.setModuleConfigurations(is, i.moduleConfigurations, configuration.log)
val log = configuration.log
IvySbt.configureCache(is, i.resolutionCacheDir)
IvySbt.setResolvers(is, i.resolvers, i.otherResolvers, configuration.updateOptions, log)
IvySbt.setModuleConfigurations(is, i.moduleConfigurations, log)
}
is
}
@ -342,13 +336,12 @@ private[sbt] object IvySbt {
settings: IvySettings,
resolvers: Seq[Resolver],
other: Seq[Resolver],
localOnly: Boolean,
updateOptions: UpdateOptions,
log: Logger
): Unit = {
def makeChain(label: String, name: String, rs: Seq[Resolver]) = {
log.debug(label + " repositories:")
val chain = resolverChain(name, rs, localOnly, settings, updateOptions, log)
val chain = resolverChain(name, rs, settings, updateOptions, log)
settings.addResolver(chain)
chain
}
@ -362,18 +355,17 @@ private[sbt] object IvySbt {
module.revision endsWith "-SNAPSHOT"
private[sbt] def isChanging(mrid: ModuleRevisionId): Boolean =
mrid.getRevision endsWith "-SNAPSHOT"
def resolverChain(
name: String,
resolvers: Seq[Resolver],
localOnly: Boolean,
settings: IvySettings,
log: Logger
): DependencyResolver =
resolverChain(name, resolvers, localOnly, settings, UpdateOptions(), log)
): DependencyResolver = resolverChain(name, resolvers, settings, UpdateOptions(), log)
def resolverChain(
name: String,
resolvers: Seq[Resolver],
localOnly: Boolean,
settings: IvySettings,
updateOptions: UpdateOptions,
log: Logger
@ -446,19 +438,12 @@ private[sbt] object IvySbt {
)
}
}
private def configureCache(
settings: IvySettings,
localOnly: Boolean,
resCacheDir: Option[File]
): Unit = {
configureResolutionCache(settings, localOnly, resCacheDir)
configureRepositoryCache(settings, localOnly)
private def configureCache(settings: IvySettings, resCacheDir: Option[File]): Unit = {
configureResolutionCache(settings, resCacheDir)
configureRepositoryCache(settings)
}
private[this] def configureResolutionCache(
settings: IvySettings,
localOnly: Boolean,
resCacheDir: Option[File]
): Unit = {
private[this] def configureResolutionCache(settings: IvySettings, resCacheDir: Option[File]) = {
val base = resCacheDir getOrElse settings.getDefaultResolutionCacheBasedir
settings.setResolutionCacheManager(new ResolutionCache(base, settings))
}
@ -485,7 +470,7 @@ private[sbt] object IvySbt {
)
}
private[this] def configureRepositoryCache(settings: IvySettings, localOnly: Boolean): Unit = {
private[this] def configureRepositoryCache(settings: IvySettings): Unit = {
val cacheDir = settings.getDefaultRepositoryCacheBasedir()
val manager = new DefaultRepositoryCacheManager("default-cache", settings, cacheDir) {
override def findModuleInCache(
@ -529,12 +514,8 @@ private[sbt] object IvySbt {
manager.setDataFilePattern(PluginPattern + manager.getDataFilePattern)
manager.setIvyPattern(PluginPattern + manager.getIvyPattern)
manager.setUseOrigin(true)
if (localOnly)
manager.setDefaultTTL(java.lang.Long.MAX_VALUE)
else {
manager.setChangingMatcher(PatternMatcher.REGEXP)
manager.setChangingPattern(".*-SNAPSHOT")
}
manager.setChangingMatcher(PatternMatcher.REGEXP)
manager.setChangingPattern(".*-SNAPSHOT")
settings.addRepositoryCacheManager(manager)
settings.setDefaultRepositoryCacheManager(manager)
}

View File

@ -108,7 +108,6 @@ class IvyCache(val ivyHome: Option[File]) {
Vector(local),
Vector.empty,
Vector.empty,
false,
lock,
IvySbt.DefaultChecksums,
None,

View File

@ -54,14 +54,12 @@ trait BaseIvySpecification extends UnitSpec {
val paths = IvyPaths(currentBase, Some(currentTarget))
val other = Vector.empty
val moduleConfs = Vector(ModuleConfiguration("*", chainResolver))
val off = false
val check = Vector.empty
val resCacheDir = currentTarget / "resolution-cache"
new InlineIvyConfiguration(paths,
resolvers,
other,
moduleConfs,
off,
None,
check,
Some(resCacheDir),

View File

@ -19,7 +19,6 @@ class CustomPomParserTest extends UnitSpec {
Vector(local),
Vector.empty,
Vector.empty,
false,
None,
Vector("sha1", "md5"),
None,

View File

@ -3,24 +3,35 @@ package sbt.librarymanagement
import org.scalatest.Assertion
import sbt.internal.librarymanagement._
import sbt.internal.librarymanagement.impl.DependencyBuilders
import sbt.io.IO
class OfflineModeSpec extends BaseIvySpecification with DependencyBuilders {
private final val targetDir = Some(currentDependency)
private final val onlineConf = makeUpdateConfiguration(false)
private final val offlineConf = makeUpdateConfiguration(true)
private final val noClock = LogicalClock.unknown
private final val warningConf = UnresolvedWarningConfiguration()
private final val normalOptions = UpdateOptions()
private final val cachedOptions = UpdateOptions().withCachedResolution(true)
private final def targetDir = Some(currentDependency)
private final def onlineConf = makeUpdateConfiguration(false)
private final def offlineConf = makeUpdateConfiguration(true)
private final def warningConf = UnresolvedWarningConfiguration()
private final def normalOptions = UpdateOptions()
private final def cachedOptions = UpdateOptions().withCachedResolution(true)
private final def noClock = LogicalClock.unknown
final val scalaCompiler = Vector("org.scala-lang" % "scala-compiler" % "2.12.2" % "compile")
def avro177 = ModuleID("org.apache.avro", "avro", "1.7.7")
def dataAvro1940 = ModuleID("com.linkedin.pegasus", "data-avro", "1.9.40")
def netty320 = ModuleID("org.jboss.netty", "netty", "3.2.0.Final")
final def dependencies: Vector[ModuleID] =
Vector(avro177, dataAvro1940, netty320).map(_.withConfigurations(Some("compile")))
def cleanAll(): Unit = {
cleanIvyCache()
IO.delete(currentTarget)
IO.delete(currentManaged)
IO.delete(currentDependency)
}
def checkOnlineAndOfflineResolution(updateOptions: UpdateOptions): Assertion = {
cleanIvyCache()
val toResolve = module(defaultModuleId, scalaCompiler, None, updateOptions)
val isCachedResolution = updateOptions.cachedResolution
if (isCachedResolution) cleanCachedResolutionCache(toResolve)
cleanAll()
val toResolve = module(defaultModuleId, dependencies, None, updateOptions)
if (updateOptions.cachedResolution)
cleanCachedResolutionCache(toResolve)
val onlineResolution =
IvyActions.updateEither(toResolve, onlineConf, warningConf, noClock, targetDir, log)
@ -28,31 +39,30 @@ class OfflineModeSpec extends BaseIvySpecification with DependencyBuilders {
assert(onlineResolution.right.exists(report => report.stats.resolveTime > 0))
// Compute an estimate to ensure that the second resolution does indeed use the cache
val resolutionTime: Long = onlineResolution.right.map(_.stats.resolveTime).getOrElse(0L)
val estimatedCachedTime = resolutionTime * 0.15
val originalResolveTime = onlineResolution.right.get.stats.resolveTime
val estimatedCachedTime = originalResolveTime * 0.15
val offlineResolution =
IvyActions.updateEither(toResolve, offlineConf, warningConf, noClock, targetDir, log)
assert(offlineResolution.isRight)
if (!isCachedResolution) {
// Only check the estimate for the non cached resolution, otherwise resolution is cached
assert(offlineResolution.right.exists(_.stats.resolveTime <= estimatedCachedTime),
"Offline resolution took more than 15% of normal resolution's running time.")
} else assert(true) // We cannot check offline resolution if it's cached.
val resolveTime = offlineResolution.right.get.stats.resolveTime
// Only check the estimate for the non cached resolution, otherwise resolution is cached
assert(resolveTime <= estimatedCachedTime,
"Offline resolution took more than 15% of normal resolution's running time.")
}
"Offline update configuration" should "reuse the caches when it's enabled" in {
"Offline update configuration" should "reuse the caches when offline is enabled" in {
checkOnlineAndOfflineResolution(normalOptions)
}
it should "work with cached resolution" in {
it should "reuse the caches when offline and cached resolution are enabled" in {
checkOnlineAndOfflineResolution(cachedOptions)
}
def checkFailingResolution(updateOptions: UpdateOptions): Assertion = {
cleanIvyCache()
val toResolve = module(defaultModuleId, scalaCompiler, None, updateOptions)
cleanAll()
val toResolve = module(defaultModuleId, dependencies, None, updateOptions)
if (updateOptions.cachedResolution) cleanCachedResolutionCache(toResolve)
val failedOfflineResolution =
IvyActions.updateEither(toResolve, offlineConf, warningConf, noClock, targetDir, log)