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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,24 +3,35 @@ package sbt.librarymanagement
import org.scalatest.Assertion import org.scalatest.Assertion
import sbt.internal.librarymanagement._ import sbt.internal.librarymanagement._
import sbt.internal.librarymanagement.impl.DependencyBuilders import sbt.internal.librarymanagement.impl.DependencyBuilders
import sbt.io.IO
class OfflineModeSpec extends BaseIvySpecification with DependencyBuilders { class OfflineModeSpec extends BaseIvySpecification with DependencyBuilders {
private final val targetDir = Some(currentDependency) private final def targetDir = Some(currentDependency)
private final val onlineConf = makeUpdateConfiguration(false) private final def onlineConf = makeUpdateConfiguration(false)
private final val offlineConf = makeUpdateConfiguration(true) private final def offlineConf = makeUpdateConfiguration(true)
private final val noClock = LogicalClock.unknown private final def warningConf = UnresolvedWarningConfiguration()
private final val warningConf = UnresolvedWarningConfiguration() private final def normalOptions = UpdateOptions()
private final val normalOptions = UpdateOptions() private final def cachedOptions = UpdateOptions().withCachedResolution(true)
private final val 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 = { def checkOnlineAndOfflineResolution(updateOptions: UpdateOptions): Assertion = {
cleanIvyCache() cleanAll()
val toResolve = module(defaultModuleId, dependencies, None, updateOptions)
val toResolve = module(defaultModuleId, scalaCompiler, None, updateOptions) if (updateOptions.cachedResolution)
val isCachedResolution = updateOptions.cachedResolution cleanCachedResolutionCache(toResolve)
if (isCachedResolution) cleanCachedResolutionCache(toResolve)
val onlineResolution = val onlineResolution =
IvyActions.updateEither(toResolve, onlineConf, warningConf, noClock, targetDir, log) 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)) assert(onlineResolution.right.exists(report => report.stats.resolveTime > 0))
// Compute an estimate to ensure that the second resolution does indeed use the cache // 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 originalResolveTime = onlineResolution.right.get.stats.resolveTime
val estimatedCachedTime = resolutionTime * 0.15 val estimatedCachedTime = originalResolveTime * 0.15
val offlineResolution = val offlineResolution =
IvyActions.updateEither(toResolve, offlineConf, warningConf, noClock, targetDir, log) IvyActions.updateEither(toResolve, offlineConf, warningConf, noClock, targetDir, log)
assert(offlineResolution.isRight) assert(offlineResolution.isRight)
if (!isCachedResolution) { val resolveTime = offlineResolution.right.get.stats.resolveTime
// Only check the estimate for the non cached resolution, otherwise resolution is cached // Only check the estimate for the non cached resolution, otherwise resolution is cached
assert(offlineResolution.right.exists(_.stats.resolveTime <= estimatedCachedTime), assert(resolveTime <= estimatedCachedTime,
"Offline resolution took more than 15% of normal resolution's running time.") "Offline resolution took more than 15% of normal resolution's running time.")
} else assert(true) // We cannot check offline resolution if it's cached.
} }
"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) checkOnlineAndOfflineResolution(normalOptions)
} }
it should "work with cached resolution" in { it should "reuse the caches when offline and cached resolution are enabled" in {
checkOnlineAndOfflineResolution(cachedOptions) checkOnlineAndOfflineResolution(cachedOptions)
} }
def checkFailingResolution(updateOptions: UpdateOptions): Assertion = { def checkFailingResolution(updateOptions: UpdateOptions): Assertion = {
cleanIvyCache() cleanAll()
val toResolve = module(defaultModuleId, scalaCompiler, None, updateOptions) val toResolve = module(defaultModuleId, dependencies, None, updateOptions)
if (updateOptions.cachedResolution) cleanCachedResolutionCache(toResolve) if (updateOptions.cachedResolution) cleanCachedResolutionCache(toResolve)
val failedOfflineResolution = val failedOfflineResolution =
IvyActions.updateEither(toResolve, offlineConf, warningConf, noClock, targetDir, log) IvyActions.updateEither(toResolve, offlineConf, warningConf, noClock, targetDir, log)