From 8ddff28a9e0b564503b71b795ac24873b294e16b Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Fri, 10 Oct 2014 00:34:05 -0400 Subject: [PATCH] Fixes #1660 Provide overloads for transitiveScratch and updateClassifiers that work with IvyActions.updateEither. --- ivy/src/main/scala/sbt/IvyActions.scala | 24 ++++++++++-- ivy/src/main/scala/sbt/LogicalClock.scala | 5 +++ main/src/main/scala/sbt/Defaults.scala | 38 +++++++++++++------ .../cached-resolution/test | 2 + 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/ivy/src/main/scala/sbt/IvyActions.scala b/ivy/src/main/scala/sbt/IvyActions.scala index f5e57336d..d52bf23d6 100644 --- a/ivy/src/main/scala/sbt/IvyActions.scala +++ b/ivy/src/main/scala/sbt/IvyActions.scala @@ -198,17 +198,31 @@ object IvyActions { def grouped[T](grouping: ModuleID => T)(mods: Seq[ModuleID]): Map[T, Set[String]] = mods groupBy (grouping) mapValues (_.map(_.revision).toSet) + @deprecated("This is no longer public.", "0.13.6") def transitiveScratch(ivySbt: IvySbt, label: String, config: GetClassifiersConfiguration, log: Logger): UpdateReport = + transitiveScratch(ivySbt, label, config, UnresolvedWarningConfiguration(), LogicalClock.unknown, None, log) + + private[sbt] def transitiveScratch(ivySbt: IvySbt, label: String, config: GetClassifiersConfiguration, + uwconfig: UnresolvedWarningConfiguration, logicalClock: LogicalClock, depDir: Option[File], log: Logger): UpdateReport = { import config.{ configuration => c, ivyScala, module => mod } import mod.{ id, modules => deps } val base = restrictedCopy(id, true).copy(name = id.name + "$" + label) val module = new ivySbt.Module(InlineConfiguration(base, ModuleInfo(base.name), deps).copy(ivyScala = ivyScala)) - val report = update(module, c, log) + val report = updateEither(module, c, uwconfig, logicalClock, depDir, log) match { + case Right(r) => r + case Left(w) => + throw w.resolveException + } val newConfig = config.copy(module = mod.copy(modules = report.allModules)) - updateClassifiers(ivySbt, newConfig, log) + updateClassifiers(ivySbt, newConfig, uwconfig, logicalClock, depDir, log) } + @deprecated("This is no longer public.", "0.13.6") def updateClassifiers(ivySbt: IvySbt, config: GetClassifiersConfiguration, log: Logger): UpdateReport = + updateClassifiers(ivySbt, config, UnresolvedWarningConfiguration(), LogicalClock.unknown, None, log) + + private[sbt] def updateClassifiers(ivySbt: IvySbt, config: GetClassifiersConfiguration, + uwconfig: UnresolvedWarningConfiguration, logicalClock: LogicalClock, depDir: Option[File], log: Logger): UpdateReport = { import config.{ configuration => c, module => mod, _ } import mod.{ configurations => confs, _ } @@ -218,7 +232,11 @@ object IvyActions { val base = restrictedCopy(id, true).copy(name = id.name + classifiers.mkString("$", "_", "")) val module = new ivySbt.Module(InlineConfiguration(base, ModuleInfo(base.name), deps).copy(ivyScala = ivyScala, configurations = confs)) val upConf = new UpdateConfiguration(c.retrieve, true, c.logging) - update(module, upConf, log) + updateEither(module, upConf, uwconfig, logicalClock, depDir, log) match { + case Right(r) => r + case Left(w) => + throw w.resolveException + } } def classifiedArtifacts(classifiers: Seq[String], exclude: Map[ModuleID, Set[String]])(m: ModuleID): Option[ModuleID] = { diff --git a/ivy/src/main/scala/sbt/LogicalClock.scala b/ivy/src/main/scala/sbt/LogicalClock.scala index 1056f6560..d4e1d4cc3 100644 --- a/ivy/src/main/scala/sbt/LogicalClock.scala +++ b/ivy/src/main/scala/sbt/LogicalClock.scala @@ -9,6 +9,11 @@ trait LogicalClock { } object LogicalClock { + def apply(hashCode: Int): LogicalClock = { + def intToByteArray(x: Int): Array[Byte] = + Array((x >>> 24).toByte, (x >> 16 & 0xff).toByte, (x >> 8 & 0xff).toByte, (x & 0xff).toByte) + apply(Hash.toHex(intToByteArray(hashCode))) + } def apply(x: String): LogicalClock = new LogicalClock { override def toString: String = x } diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 077152859..91b888538 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -1135,10 +1135,20 @@ object Classpaths { val externalModules = update.value.allModules.filterNot(m => projectDeps contains key(m)) GetClassifiersModule(projectID.value, externalModules, ivyConfigurations.in(updateClassifiers).value, transitiveClassifiers.in(updateClassifiers).value) }, - updateClassifiers <<= (ivySbt, classifiersModule in updateClassifiers, updateConfiguration, ivyScala, appConfiguration, streams) map { (is, mod, c, ivyScala, app, s) => + updateClassifiers <<= Def.task { + val s = streams.value + val is = ivySbt.value + val mod = (classifiersModule in updateClassifiers).value + val c = updateConfiguration.value + val app = appConfiguration.value val out = is.withIvy(s.log)(_.getSettings.getDefaultIvyUserDir) + val uwConfig = (unresolvedWarningConfiguration in update).value + val depDir = dependencyCacheDirectory.value withExcludes(out, mod.classifiers, lock(app)) { excludes => - IvyActions.updateClassifiers(is, GetClassifiersConfiguration(mod, excludes, c, ivyScala), s.log) + val uwConfig = (unresolvedWarningConfiguration in update).value + val logicalClock = LogicalClock(state.value.hashCode) + val depDir = dependencyCacheDirectory.value + IvyActions.updateClassifiers(is, GetClassifiersConfiguration(mod, excludes, c, ivyScala.value), uwConfig, LogicalClock(state.value.hashCode), Some(depDir), s.log) } } tag (Tags.Update, Tags.Network) ) @@ -1203,13 +1213,19 @@ object Classpaths { val pluginIDs: Seq[ModuleID] = pluginJars.flatMap(_ get moduleID.key) GetClassifiersModule(pid, sbtDep +: pluginIDs, Configurations.Default :: Nil, classifiers) }, - updateSbtClassifiers in TaskGlobal <<= (ivySbt, classifiersModule, updateConfiguration, ivyScala, appConfiguration, streams) map { - (is, mod, c, ivyScala, app, s) => - val out = is.withIvy(s.log)(_.getSettings.getDefaultIvyUserDir) - withExcludes(out, mod.classifiers, lock(app)) { excludes => - val noExplicitCheck = ivyScala.map(_.copy(checkExplicit = false)) - IvyActions.transitiveScratch(is, "sbt", GetClassifiersConfiguration(mod, excludes, c, noExplicitCheck), s.log) - } + updateSbtClassifiers in TaskGlobal <<= Def.task { + val s = streams.value + val is = ivySbt.value + val mod = classifiersModule.value + val c = updateConfiguration.value + val app = appConfiguration.value + val out = is.withIvy(s.log)(_.getSettings.getDefaultIvyUserDir) + val uwConfig = (unresolvedWarningConfiguration in update).value + val depDir = dependencyCacheDirectory.value + withExcludes(out, mod.classifiers, lock(app)) { excludes => + val noExplicitCheck = ivyScala.value.map(_.copy(checkExplicit = false)) + IvyActions.transitiveScratch(is, "sbt", GetClassifiersConfiguration(mod, excludes, c, noExplicitCheck), uwConfig, LogicalClock(state.value.hashCode), Some(depDir), s.log) + } } tag (Tags.Update, Tags.Network) )) @@ -1259,8 +1275,6 @@ object Classpaths { case (Some(res), _, Some(decl)) if res == decl => jars case _ => Nil } - def intToByteArray(x: Int): Array[Byte] = - Array((x >>> 24).toByte, (x >> 16 & 0xff).toByte, (x >> 8 & 0xff).toByte, (x & 0xff).toByte) val subScalaJars: String => Seq[File] = Defaults.unmanagedScalaInstanceOnly.value match { case Some(si) => subUnmanaged(si.version, si.jars) case None => sv => if (scalaProvider.version == sv) scalaProvider.jars else Nil @@ -1269,7 +1283,7 @@ object Classpaths { val uwConfig = (unresolvedWarningConfiguration in update).value val show = Reference.display(thisProjectRef.value) val st = state.value - val logicalClock = LogicalClock(Hash.toHex(intToByteArray(st.hashCode))) + val logicalClock = LogicalClock(st.hashCode) val depDir = dependencyCacheDirectory.value cachedUpdate(s.cacheDirectory / updateCacheName.value, show, ivyModule.value, updateConfiguration.value, transform, skip = (skip in update).value, force = isRoot, depsUpdated = depsUpdated, diff --git a/sbt/src/sbt-test/dependency-management/cached-resolution/test b/sbt/src/sbt-test/dependency-management/cached-resolution/test index bd1a58183..684215c92 100644 --- a/sbt/src/sbt-test/dependency-management/cached-resolution/test +++ b/sbt/src/sbt-test/dependency-management/cached-resolution/test @@ -1,3 +1,5 @@ +> a/updateClassifiers + > a/publishLocal > check