From 3d7051ad079d8f461f679db20dd15657760f21f7 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Sun, 2 May 2010 19:15:01 -0400 Subject: [PATCH] * can now set 'offline' property to 'true' to not refresh dynamic revisions (not needed if no -SNAPSHOT versions used) * more control over Ivy logging: override ivyUpdateLogging = UpdateLogging.Full,DownloadOnly (default), or Quiet --- ivy/Ivy.scala | 42 +++++++++++++++++++++++-------------- ivy/IvyActions.scala | 31 ++++++++++++++++++++------- ivy/IvyCache.scala | 2 +- ivy/IvyConfigurations.scala | 10 +++++---- 4 files changed, 57 insertions(+), 28 deletions(-) diff --git a/ivy/Ivy.scala b/ivy/Ivy.scala index 7065e5603..b2d59c60d 100644 --- a/ivy/Ivy.scala +++ b/ivy/Ivy.scala @@ -59,8 +59,8 @@ final class IvySbt(configuration: IvyConfiguration) { case e: ExternalIvyConfiguration => is.load(e.file) case i: InlineIvyConfiguration => - IvySbt.configureCache(is, i.paths.cacheDirectory) - IvySbt.setResolvers(is, i.resolvers, i.otherResolvers, log) + IvySbt.configureCache(is, i.paths.cacheDirectory, i.localOnly) + IvySbt.setResolvers(is, i.resolvers, i.otherResolvers, i.localOnly, log) IvySbt.setModuleConfigurations(is, i.moduleConfigurations) } is @@ -171,23 +171,28 @@ private object IvySbt /** Sets the resolvers for 'settings' to 'resolvers'. This is done by creating a new chain and making it the default. * 'other' is for resolvers that should be in a different chain. These are typically used for publishing or other actions. */ - private def setResolvers(settings: IvySettings, resolvers: Seq[Resolver], other: Seq[Resolver], log: IvyLogger) + private def setResolvers(settings: IvySettings, resolvers: Seq[Resolver], other: Seq[Resolver], localOnly: Boolean, log: IvyLogger) { - val otherChain = resolverChain("sbt-other", other) - settings.addResolver(otherChain) - val newDefault = resolverChain("sbt-chain", resolvers) - settings.addResolver(newDefault) - settings.setDefaultResolver(newDefault.getName) - log.debug("Using repositories:\n" + resolvers.mkString("\n\t")) - log.debug("Using other repositories:\n" + other.mkString("\n\t")) + def makeChain(label: String, name: String, rs: Seq[Resolver]) = { + log.debug(label + " repositories:") + val chain = resolverChain(name, rs, localOnly, log) + settings.addResolver(chain) + chain + } + val otherChain = makeChain("Other", "sbt-other", other) + val mainChain = makeChain("Default", "sbt-chain", resolvers) + settings.setDefaultResolver(mainChain.getName) } - private def resolverChain(name: String, resolvers: Seq[Resolver]): ChainResolver = + private def resolverChain(name: String, resolvers: Seq[Resolver], localOnly: Boolean, log: IvyLogger): ChainResolver = { val newDefault = new ChainResolver newDefault.setName(name) newDefault.setReturnFirst(true) - newDefault.setCheckmodified(true) - resolvers.foreach(r => newDefault.add(ConvertResolver(r))) + newDefault.setCheckmodified(!localOnly) + for(sbtResolver <- resolvers) { + log.debug("\t" + sbtResolver) + newDefault.add(ConvertResolver(sbtResolver)) + } newDefault } private def setModuleConfigurations(settings: IvySettings, moduleConfigurations: Seq[ModuleConfiguration]) @@ -204,13 +209,18 @@ private object IvySbt settings.addModuleConfiguration(attributes, settings.getMatcher(EXACT_OR_REGEXP), resolver.name, null, null, null) } } - private def configureCache(settings: IvySettings, dir: Option[File]) + private def configureCache(settings: IvySettings, dir: Option[File], localOnly: Boolean) { val cacheDir = dir.getOrElse(settings.getDefaultRepositoryCacheBasedir()) val manager = new DefaultRepositoryCacheManager("default-cache", settings, cacheDir) manager.setUseOrigin(true) - manager.setChangingMatcher(PatternMatcher.REGEXP); - manager.setChangingPattern(".*-SNAPSHOT"); + if(localOnly) + manager.setDefaultTTL(java.lang.Long.MAX_VALUE); + else + { + manager.setChangingMatcher(PatternMatcher.REGEXP); + manager.setChangingPattern(".*-SNAPSHOT"); + } settings.addRepositoryCacheManager(manager) settings.setDefaultRepositoryCacheManager(manager) dir.foreach(dir => settings.setDefaultResolutionCacheBasedir(dir.getAbsolutePath)) diff --git a/ivy/IvyActions.scala b/ivy/IvyActions.scala index e478df5eb..d80b12e13 100644 --- a/ivy/IvyActions.scala +++ b/ivy/IvyActions.scala @@ -19,7 +19,7 @@ import core.resolve.ResolveOptions import core.retrieve.RetrieveOptions import plugins.parser.m2.{PomModuleDescriptorParser,PomModuleDescriptorWriter} -final class UpdateConfiguration(val retrieveDirectory: File, val outputPattern: String, val synchronize: Boolean, val quiet: Boolean) extends NotNull +final class UpdateConfiguration(val retrieveDirectory: File, val outputPattern: String, val synchronize: Boolean, val logging: UpdateLogging.Value) extends NotNull final class MakePomConfiguration(val extraDependencies: Iterable[ModuleID], val configurations: Option[Iterable[Configuration]], val extra: NodeSeq, val process: Node => Node, val filterRepositories: MavenRepository => Boolean) extends NotNull object MakePomConfiguration @@ -27,6 +27,14 @@ object MakePomConfiguration def apply(extraDependencies: Iterable[ModuleID], configurations: Option[Iterable[Configuration]], extra: NodeSeq) = new MakePomConfiguration(extraDependencies, configurations, extra, identity, _ => true) } +/** Configures logging during an 'update'. `level` determines the amount of other information logged. +* `Full` is the default and logs the most. +* `DownloadOnly` only logs what is downloaded. +* `Quiet` only displays errors.*/ +object UpdateLogging extends Enumeration +{ + val Full, DownloadOnly, Quiet = Value +} object IvyActions { @@ -71,11 +79,11 @@ object IvyActions IvySbt.addDependencies(module, extraDependencies, parser) } - def deliver(module: IvySbt#Module, status: String, deliverIvyPattern: String, extraDependencies: Iterable[ModuleID], configurations: Option[Iterable[Configuration]], quiet: Boolean) + def deliver(module: IvySbt#Module, status: String, deliverIvyPattern: String, extraDependencies: Iterable[ModuleID], configurations: Option[Iterable[Configuration]], logging: UpdateLogging.Value) { module.withModule { case (ivy, md, default) => addLateDependencies(ivy, md, default, extraDependencies) - resolve(quiet)(ivy, md, default) // todo: set download = false for resolve + resolve(logging)(ivy, md, default) // todo: set download = false for resolve val revID = md.getModuleRevisionId val options = DeliverOptions.newInstance(ivy.getSettings).setStatus(status) options.setConfs(IvySbt.getConfigurations(md, configurations)) @@ -101,7 +109,7 @@ object IvyActions { module.withModule { case (ivy, md, default) => import configuration._ - resolve(quiet)(ivy, md, default) + resolve(logging)(ivy, md, default) val retrieveOptions = new RetrieveOptions retrieveOptions.setSync(synchronize) val patternBase = retrieveDirectory.getAbsolutePath @@ -113,14 +121,23 @@ object IvyActions ivy.retrieve(md.getModuleRevisionId, pattern, retrieveOptions) } } - private def resolve(quiet: Boolean)(ivy: Ivy, module: DefaultModuleDescriptor, defaultConf: String) = + private def resolve(logging: UpdateLogging.Value)(ivy: Ivy, module: DefaultModuleDescriptor, defaultConf: String) = { val resolveOptions = new ResolveOptions - if(quiet) - resolveOptions.setLog(LogOptions.LOG_DOWNLOAD_ONLY) + resolveOptions.setLog(ivyLogLevel(logging)) val resolveReport = ivy.resolve(module, resolveOptions) if(resolveReport.hasError) throw new ResolveException(resolveReport.getAllProblemMessages.toArray.map(_.toString).toList.removeDuplicates) } + + import UpdateLogging.{Quiet, Full, DownloadOnly} + 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 + } } final class ResolveException(messages: List[String]) extends RuntimeException(messages.mkString("\n")) \ No newline at end of file diff --git a/ivy/IvyCache.scala b/ivy/IvyCache.scala index b7c18c0ba..43b714231 100644 --- a/ivy/IvyCache.scala +++ b/ivy/IvyCache.scala @@ -86,7 +86,7 @@ object IvyCache { val local = Resolver.defaultLocal(None) val paths = new IvyPaths(new File("."), None) - val conf = new InlineIvyConfiguration(paths, Seq(local), Nil, Nil, lock, log) + val conf = new InlineIvyConfiguration(paths, Seq(local), Nil, Nil, false, lock, log) (new IvySbt(conf), local) } /** Creates a default jar artifact based on the given ID.*/ diff --git a/ivy/IvyConfigurations.scala b/ivy/IvyConfigurations.scala index 7b57364cd..c047f1dda 100644 --- a/ivy/IvyConfigurations.scala +++ b/ivy/IvyConfigurations.scala @@ -19,11 +19,13 @@ sealed trait IvyConfiguration extends NotNull def withBase(newBaseDirectory: File): This } final class InlineIvyConfiguration(val paths: IvyPaths, val resolvers: Seq[Resolver], val otherResolvers: Seq[Resolver], - val moduleConfigurations: Seq[ModuleConfiguration], val lock: Option[xsbti.GlobalLock], val log: IvyLogger) extends IvyConfiguration + val moduleConfigurations: Seq[ModuleConfiguration], val localOnly: Boolean, val lock: Option[xsbti.GlobalLock], + val log: IvyLogger) extends IvyConfiguration { type This = InlineIvyConfiguration def baseDirectory = paths.baseDirectory - def withBase(newBase: File) = new InlineIvyConfiguration(paths.withBase(newBase), resolvers, otherResolvers, moduleConfigurations, lock, log) + def withBase(newBase: File) = new InlineIvyConfiguration(paths.withBase(newBase), resolvers, otherResolvers, moduleConfigurations, localOnly, lock, log) + def changeResolvers(newResolvers: Seq[Resolver]) = new InlineIvyConfiguration(paths, newResolvers, otherResolvers, moduleConfigurations, localOnly, lock, log) } final class ExternalIvyConfiguration(val baseDirectory: File, val file: File, val lock: Option[xsbti.GlobalLock], val log: IvyLogger) extends IvyConfiguration { @@ -35,14 +37,14 @@ object IvyConfiguration { /** Called to configure Ivy when inline resolvers are not specified. * This will configure Ivy with an 'ivy-settings.xml' file if there is one or else use default resolvers.*/ - def apply(paths: IvyPaths, lock: Option[xsbti.GlobalLock], log: IvyLogger): IvyConfiguration = + def apply(paths: IvyPaths, lock: Option[xsbti.GlobalLock], localOnly: Boolean, log: IvyLogger): IvyConfiguration = { log.debug("Autodetecting configuration.") val defaultIvyConfigFile = IvySbt.defaultIvyConfiguration(paths.baseDirectory) if(defaultIvyConfigFile.canRead) new ExternalIvyConfiguration(paths.baseDirectory, defaultIvyConfigFile, lock, log) else - new InlineIvyConfiguration(paths, Resolver.withDefaultResolvers(Nil), Nil, Nil, lock, log) + new InlineIvyConfiguration(paths, Resolver.withDefaultResolvers(Nil), Nil, Nil, localOnly, lock, log) } }