From bb6e3e34e6f5c058cbf4ba5e870235939f10ed77 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Fri, 18 Jul 2014 16:27:11 -0400 Subject: [PATCH] Fixing NullPointerError caused by reading String from Ivy directly --- ivy/src/main/scala/sbt/IvyRetrieve.scala | 10 ++--- ivy/src/main/scala/sbt/UpdateReport.scala | 47 +++++++++++++++++++---- main/src/main/scala/sbt/Defaults.scala | 12 +++--- 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/ivy/src/main/scala/sbt/IvyRetrieve.scala b/ivy/src/main/scala/sbt/IvyRetrieve.scala index 5998f2a22..e9dba98ee 100644 --- a/ivy/src/main/scala/sbt/IvyRetrieve.scala +++ b/ivy/src/main/scala/sbt/IvyRetrieve.scala @@ -71,13 +71,13 @@ object IvyRetrieve { } val revId = dep.getResolvedId val moduleId = toModuleID(revId) - val branch = Some(revId.getBranch) + val branch = Option(revId.getBranch) val (status, publicationDate, resolver, artifactResolver) = dep.isLoaded match { case true => - (Some(dep.getDescriptor.getStatus), + (Option(dep.getDescriptor.getStatus), Some(new ju.Date(dep.getPublication)), - Some(dep.getModuleRevision.getResolver.getName), - Some(dep.getModuleRevision.getArtifactResolver.getName)) + Option(dep.getModuleRevision.getResolver.getName), + Option(dep.getModuleRevision.getArtifactResolver.getName)) case _ => (None, None, None, None) } val (evicted, evictedData, evictedReason) = dep.isEvicted(confReport.getConfiguration) match { @@ -89,7 +89,7 @@ object IvyRetrieve { case _ => (false, None, None) } val problem = dep.hasProblem match { - case true => Some(dep.getProblem.getMessage) + case true => Option(dep.getProblem.getMessage) case _ => None } val mdOpt = for { diff --git a/ivy/src/main/scala/sbt/UpdateReport.scala b/ivy/src/main/scala/sbt/UpdateReport.scala index 39ad7357b..f8c2804d5 100644 --- a/ivy/src/main/scala/sbt/UpdateReport.scala +++ b/ivy/src/main/scala/sbt/UpdateReport.scala @@ -48,10 +48,12 @@ final class ConfigurationReport( val modules: Seq[ModuleReport], val details: Seq[ModuleDetailReport], val evicted: Seq[ModuleID]) { - // def this(configuration: String, modules: Seq[ModuleReport], evicted: Seq[ModuleID]) = - // this(configuration, modules, Nil, evicted) + def this(configuration: String, modules: Seq[ModuleReport], evicted: Seq[ModuleID]) = + this(configuration, modules, Nil, evicted) - override def toString = "\t" + configuration + ":\n" + modules.mkString + evicted.map("\t\t(EVICTED) " + _ + "\n").mkString + override def toString = s"\t$configuration:\n" + + (if (details.isEmpty) modules.mkString + evicted.map("\t\t(EVICTED) " + _ + "\n").mkString + else details.mkString) /** * All resolved modules for this configuration. @@ -73,8 +75,10 @@ final class ModuleDetailReport( val organization: String, val name: String, val modules: Seq[ModuleReport]) { - override def toString: String = - { s"$organization:$name" } + override def toString: String = { + val details = modules map { _.detailReport } + s"\t$organization:$name\n${details.mkString}\n" + } } /** @@ -104,11 +108,40 @@ final class ModuleReport( val licenses: Seq[(String, URL)], val callers: Seq[Caller]) { - override def toString = { - val arts = artifacts.map(_.toString) ++ missingArtifacts.map(art => "(MISSING) " + art) + private[this] lazy val arts: Seq[String] = artifacts.map(_.toString) ++ missingArtifacts.map(art => "(MISSING) " + art) + override def toString: String = { s"\t\t$module: " + (if (arts.size <= 1) "" else "\n\t\t\t") + arts.mkString("\n\t\t\t") + "\n" } + private[sbt] def detailReport: String = + s"\t\t- ${module.revision}\n" + + (if (arts.size <= 1) "" else arts.mkString("\t\t\t", "\n\t\t\t", "\n")) + + reportStr("status", status) + + reportStr("publicationDate", publicationDate map { _.toString }) + + reportStr("resolver", resolver) + + reportStr("artifactResolver", artifactResolver) + + reportStr("evicted", Some(evicted.toString)) + + reportStr("evictedData", evictedData) + + reportStr("evictedReason", evictedReason) + + reportStr("problem", problem) + + reportStr("homepage", homepage) + + reportStr("textraAttributes", + if (extraAttributes.isEmpty) None + else { Some(extraAttributes.toString) }) + + reportStr("isDefault", isDefault map { _.toString }) + + reportStr("branch", branch) + + reportStr("configurations", + if (configurations.isEmpty) None + else { Some(configurations.mkString(", ")) }) + + reportStr("licenses", + if (licenses.isEmpty) None + else { Some(licenses.mkString(", ")) }) + + reportStr("callers", + if (callers.isEmpty) None + else { Some(callers.mkString(", ")) }) + private[sbt] def reportStr(key: String, value: Option[String]): String = + value map { x => s"\t\t\t$key: $x\n" } getOrElse "" + def retrieve(f: (ModuleID, Artifact, File) => File): ModuleReport = copy(artifacts = artifacts.map { case (art, file) => (art, f(module, art, file)) }) diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index c3ade184b..75b53216e 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -1269,13 +1269,11 @@ object Classpaths { } def doWork: In => UpdateReport = Tracked.inputChanged(cacheFile / "inputs") { (inChanged: Boolean, in: In) => - // TODO FIX THIS! - // val outCache = Tracked.lastOutput[In, UpdateReport](outCacheFile) { - // case (_, Some(out)) if uptodate(inChanged, out) => out - // case _ => work(in) - // } - // outCache(in) - work(in) + val outCache = Tracked.lastOutput[In, UpdateReport](outCacheFile) { + case (_, Some(out)) if uptodate(inChanged, out) => out + case _ => work(in) + } + outCache(in) } val f = if (skip && !force) skipWork else doWork f(module.owner.configuration :+: module.moduleSettings :+: config :+: HNil)