From 607b686cb2321778ab43db1297dd420f550a933d Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Thu, 4 Dec 2014 12:34:30 -0500 Subject: [PATCH] Fixes #1752. Fixes cached resolution too verbose. - Fixes cached resolution being too verbose - Adds new UpdateLogging named "Default" - When global logLevel or logLevel in update is Debug, Default will bump up to Full UpdateLogging. --- ivy/src/main/scala/sbt/IvyActions.scala | 15 ++++++++-- .../CachedResolutionResolveEngine.scala | 28 +++++++++++++++++-- main/src/main/scala/sbt/Defaults.scala | 14 ++++++++-- notes/0.13.8/cached-resolution-fixes.markdown | 13 +++++++++ project/build.properties | 2 +- 5 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 notes/0.13.8/cached-resolution-fixes.markdown diff --git a/ivy/src/main/scala/sbt/IvyActions.scala b/ivy/src/main/scala/sbt/IvyActions.scala index a6754b138..3db09e636 100644 --- a/ivy/src/main/scala/sbt/IvyActions.scala +++ b/ivy/src/main/scala/sbt/IvyActions.scala @@ -24,7 +24,13 @@ final class PublishConfiguration(val ivyFile: Option[File], val resolverName: St this(ivyFile, resolverName, artifacts, checksums, logging, false) } -final class UpdateConfiguration(val retrieve: Option[RetrieveConfiguration], val missingOk: Boolean, val logging: UpdateLogging.Value) +final class UpdateConfiguration(val retrieve: Option[RetrieveConfiguration], val missingOk: Boolean, val logging: UpdateLogging.Value) { + private[sbt] def copy( + retrieve: Option[RetrieveConfiguration] = this.retrieve, + missingOk: Boolean = this.missingOk, + logging: UpdateLogging.Value = this.logging): UpdateConfiguration = + new UpdateConfiguration(retrieve, missingOk, logging) +} final class RetrieveConfiguration(val retrieveDirectory: File, val outputPattern: String) final case class MakePomConfiguration(file: File, moduleInfo: ModuleInfo, configurations: Option[Seq[Configuration]] = None, extra: NodeSeq = NodeSeq.Empty, process: XNode => XNode = n => n, filterRepositories: MavenRepository => Boolean = _ => true, allRepositories: Boolean, includeTypes: Set[String] = Set(Artifact.DefaultType, Artifact.PomType)) // exclude is a map on a restricted ModuleID @@ -44,9 +50,10 @@ object UnresolvedWarningConfiguration { * `Full` is the default and logs the most. * `DownloadOnly` only logs what is downloaded. * `Quiet` only displays errors. + * `Default` uses the current log level of `update` task. */ object UpdateLogging extends Enumeration { - val Full, DownloadOnly, Quiet = Value + val Full, DownloadOnly, Quiet, Default = Value } object IvyActions { @@ -161,6 +168,7 @@ object IvyActions { val resolveOptions = new ResolveOptions val resolveId = ResolveOptions.getDefaultResolveId(md) resolveOptions.setResolveId(resolveId) + resolveOptions.setLog(ivyLogLevel(configuration.logging)) x.customResolve(md, configuration.missingOk, logicalClock, resolveOptions, depDir getOrElse { sys.error("dependency base directory is not specified") }, log) match { case Left(x) => Left(UnresolvedWarning(x, uwconfig)) @@ -303,13 +311,14 @@ object IvyActions { IvyPatternHelper.substitute(pattern, mid.organization, mid.name, mid.revision, art.name, art.`type`, art.extension, conf, mextra, aextra) } - import UpdateLogging.{ Quiet, Full, DownloadOnly } + import UpdateLogging.{ Quiet, Full, DownloadOnly, Default } import LogOptions.{ LOG_QUIET, LOG_DEFAULT, LOG_DOWNLOAD_ONLY } private def ivyLogLevel(level: UpdateLogging.Value) = level match { case Quiet => LOG_QUIET case DownloadOnly => LOG_DOWNLOAD_ONLY case Full => LOG_DEFAULT + case Default => LOG_DOWNLOAD_ONLY } def publish(module: ModuleDescriptor, artifacts: Seq[(IArtifact, File)], resolver: DependencyResolver, overwrite: Boolean): Unit = diff --git a/ivy/src/main/scala/sbt/ivyint/CachedResolutionResolveEngine.scala b/ivy/src/main/scala/sbt/ivyint/CachedResolutionResolveEngine.scala index 32442167a..87ad6e23c 100644 --- a/ivy/src/main/scala/sbt/ivyint/CachedResolutionResolveEngine.scala +++ b/ivy/src/main/scala/sbt/ivyint/CachedResolutionResolveEngine.scala @@ -14,7 +14,7 @@ import core.report.{ ResolveReport, ConfigurationResolveReport, DownloadReport } import core.module.descriptor.{ DefaultModuleDescriptor, ModuleDescriptor, DefaultDependencyDescriptor, DependencyDescriptor, Configuration => IvyConfiguration, ExcludeRule, IncludeRule } import core.module.descriptor.{ OverrideDependencyDescriptorMediator, DependencyArtifactDescriptor, DefaultDependencyArtifactDescriptor } import core.{ IvyPatternHelper, LogOptions } -import org.apache.ivy.util.Message +import org.apache.ivy.util.{ Message, MessageLogger } import org.apache.ivy.plugins.latest.{ ArtifactInfo => IvyArtifactInfo } import org.apache.ivy.plugins.matcher.{ MapMatcher, PatternMatcher } @@ -297,6 +297,27 @@ private[sbt] trait CachedResolutionResolveEngine extends ResolveEngine { private[sbt] def makeInstance: Ivy private[sbt] val ignoreTransitiveForce: Boolean = true + def withIvy[A](log: Logger)(f: Ivy => A): A = + withIvy(new IvyLoggerInterface(log))(f) + def withIvy[A](log: MessageLogger)(f: Ivy => A): A = + withDefaultLogger(log) { + val ivy = makeInstance + ivy.pushContext() + ivy.getLoggerEngine.pushLogger(log) + try { f(ivy) } + finally { + ivy.getLoggerEngine.popLogger() + ivy.popContext() + } + } + def withDefaultLogger[A](log: MessageLogger)(f: => A): A = + { + val originalLogger = Message.getDefaultLogger + Message.setDefaultLogger(log) + try { f } + finally { Message.setDefaultLogger(originalLogger) } + } + /** * This returns sbt's UpdateReport structure. * missingOk allows sbt to call this with classifiers that may or may not exist, and grab the JARs. @@ -314,8 +335,9 @@ private[sbt] trait CachedResolutionResolveEngine extends ResolveEngine { def doWork(md: ModuleDescriptor): Either[ResolveException, UpdateReport] = { val options1 = new ResolveOptions(options0) - val i = makeInstance - var rr = i.resolve(md, options1) + var rr = withIvy(log) { ivy => + ivy.resolve(md, options1) + } if (!rr.hasError || missingOk) Right(IvyRetrieve.updateReport(rr, cachedDescriptor)) else { val messages = rr.getAllProblemMessages.toArray.map(_.toString).distinct diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 40645e4fe..5c5bee72f 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -1027,7 +1027,7 @@ object Classpaths { defaultConfiguration :== Some(Configurations.Compile), dependencyOverrides :== Set.empty, libraryDependencies :== Nil, - ivyLoggingLevel :== UpdateLogging.DownloadOnly, + ivyLoggingLevel :== UpdateLogging.Default, ivyXML :== NodeSeq.Empty, ivyValidate :== false, moduleConfigurations :== Nil, @@ -1297,7 +1297,17 @@ object Classpaths { val st = state.value val logicalClock = LogicalClock(st.hashCode) val depDir = dependencyCacheDirectory.value - cachedUpdate(s.cacheDirectory / updateCacheName.value, show, ivyModule.value, updateConfiguration.value, transform, + val uc0 = updateConfiguration.value + // Normally, log would capture log messages at all levels. + // Ivy logs are treated specially using sbt.UpdateConfiguration.logging. + // This code bumps up the sbt.UpdateConfiguration.logging to Full when logLevel is Debug. + import UpdateLogging.{ Full, DownloadOnly, Default } + val uc = (logLevel in update).?.value orElse st.get(logLevel.key) match { + case Some(Level.Debug) if uc0.logging == Default => uc0.copy(logging = Full) + case Some(x) if uc0.logging == Default => uc0.copy(logging = DownloadOnly) + case _ => uc0 + } + cachedUpdate(s.cacheDirectory / updateCacheName.value, show, ivyModule.value, uc0, transform, skip = (skip in update).value, force = isRoot, depsUpdated = depsUpdated, uwConfig = uwConfig, logicalClock = logicalClock, depDir = Some(depDir), log = s.log) } diff --git a/notes/0.13.8/cached-resolution-fixes.markdown b/notes/0.13.8/cached-resolution-fixes.markdown new file mode 100644 index 000000000..730f2ec75 --- /dev/null +++ b/notes/0.13.8/cached-resolution-fixes.markdown @@ -0,0 +1,13 @@ + [@cunei]: https://github.com/cunei + [@eed3si9n]: https://github.com/eed3si9n + [@gkossakowski]: https://github.com/gkossakowski + [@jsuereth]: https://github.com/jsuereth + [1752]: https://github.com/sbt/sbt/pull/1752 + +### Fixes with compatibility implications + +### Improvements + +### Bug fixes + +- Fixes cached resolution being too verbose. [#1752][1752] diff --git a/project/build.properties b/project/build.properties index be6c454fb..748703f77 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.5 +sbt.version=0.13.7