mirror of https://github.com/sbt/sbt.git
detailed UpdateReport replaces Map[String,Seq[File]]
the information included is: configuration -> module -> artifact -> file
This commit is contained in:
parent
c0f3677844
commit
39a6475b2e
|
|
@ -105,44 +105,14 @@ object IvyActions
|
|||
}
|
||||
/** Resolves and retrieves dependencies. 'ivyConfig' is used to produce an Ivy file and configuration.
|
||||
* 'updateConfig' configures the actual resolution and retrieval process. */
|
||||
def update(module: IvySbt#Module, configuration: UpdateConfiguration) =
|
||||
def update(module: IvySbt#Module, configuration: UpdateConfiguration): UpdateReport =
|
||||
{
|
||||
module.withModule { case (ivy, md, default) =>
|
||||
import configuration.{retrieve => rConf, logging}
|
||||
val report = resolve(logging)(ivy, md, default)
|
||||
rConf match
|
||||
{
|
||||
case None => IvyRetrieve.cachePaths(report)
|
||||
case Some(conf) => retrieve(ivy, md, conf, logging)
|
||||
}
|
||||
IvyRetrieve.updateReport(report)
|
||||
}
|
||||
}
|
||||
// doesn't work. perhaps replace retrieve/determineArtifactsToCopy with custom code
|
||||
private def retrieve(ivy: Ivy, md: ModuleDescriptor, conf: RetrieveConfiguration, logging: UpdateLogging.Value) =
|
||||
{
|
||||
import conf._
|
||||
val retrieveOptions = new RetrieveOptions
|
||||
retrieveOptions.setSync(synchronize)
|
||||
val patternBase = retrieveDirectory.getAbsolutePath
|
||||
val pattern =
|
||||
if(patternBase.endsWith(File.separator))
|
||||
patternBase + outputPattern
|
||||
else
|
||||
patternBase + File.separatorChar + outputPattern
|
||||
|
||||
val engine = ivy.getRetrieveEngine
|
||||
engine.retrieve(md.getModuleRevisionId, pattern, retrieveOptions)
|
||||
|
||||
//TODO: eliminate the duplication for better efficiency (retrieve already calls determineArtifactsToCopy once)
|
||||
val rawMap = engine.determineArtifactsToCopy(md.getModuleRevisionId, pattern, retrieveOptions)
|
||||
val map = rawMap.asInstanceOf[java.util.Map[ArtifactDownloadReport,java.util.Set[String]]]
|
||||
val confMap = new collection.mutable.HashMap[String, Seq[File]]
|
||||
|
||||
import collection.JavaConversions._
|
||||
for( (report, all) <- map; retrieved <- all; val file = new File(retrieved); conf <- report.getArtifact.getConfigurations)
|
||||
confMap.put(conf, file +: confMap.getOrElse(conf, Nil))
|
||||
confMap.toMap
|
||||
}
|
||||
private def resolve(logging: UpdateLogging.Value)(ivy: Ivy, module: DefaultModuleDescriptor, defaultConf: String): ResolveReport =
|
||||
{
|
||||
val resolveOptions = new ResolveOptions
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package sbt
|
|||
import java.io.File
|
||||
|
||||
import org.apache.ivy.core.{module, report}
|
||||
import module.descriptor.{Artifact => IvyArtifact}
|
||||
import module.id.ModuleRevisionId
|
||||
import report.{ArtifactDownloadReport, ConfigurationResolveReport, ResolveReport}
|
||||
|
||||
|
|
@ -14,21 +15,49 @@ object IvyRetrieve
|
|||
def reports(report: ResolveReport): Map[String, ConfigurationResolveReport] =
|
||||
( for( conf <- report.getConfigurations) yield (conf, report.getConfigurationReport(conf)) ).toMap
|
||||
|
||||
def artifactReports(confReport: ConfigurationResolveReport): Seq[ArtifactDownloadReport] =
|
||||
def moduleReports(confReport: ConfigurationResolveReport): Map[ModuleID, ModuleReport] =
|
||||
moduleReportMap(confReport) map { case (mid, arts) => (mid, new ModuleReport(mid, artifactReports(arts)) ) }
|
||||
|
||||
def moduleReportMap(confReport: ConfigurationResolveReport): Map[ModuleID, Seq[ArtifactDownloadReport]] =
|
||||
{
|
||||
val all = new scala.collection.mutable.HashSet[ArtifactDownloadReport]
|
||||
for( revId <- confReport.getModuleRevisionIds.toArray collect { case revId: ModuleRevisionId => revId })
|
||||
all ++= confReport.getDownloadReports(revId)
|
||||
all.toSeq
|
||||
val modules =
|
||||
for( revId <- confReport.getModuleRevisionIds.toArray collect { case revId: ModuleRevisionId => revId }) yield
|
||||
(toModuleID(revId), (confReport getDownloadReports revId).toSeq)
|
||||
modules.toMap
|
||||
}
|
||||
def artifactReports(artReport: Seq[ArtifactDownloadReport]): Map[Artifact, File] =
|
||||
artReport map { r =>
|
||||
val art = r.getArtifact
|
||||
val file0 = r.getLocalFile
|
||||
val file = if(file0 eq null) error("No file for " + art) else file0
|
||||
(toArtifact(art), file)
|
||||
} toMap;
|
||||
|
||||
def toModuleID(revID: ModuleRevisionId): ModuleID =
|
||||
ModuleID(revID.getOrganisation, revID.getName, revID.getRevision)
|
||||
|
||||
def toArtifact(art: IvyArtifact): Artifact =
|
||||
{
|
||||
import art._
|
||||
Artifact(getName, getType, getExt, Option(getExtraAttribute("classifier")), getConfigurations map Configurations.config, Option(getUrl))
|
||||
}
|
||||
|
||||
def cachePath(reports: Seq[ArtifactDownloadReport]): Seq[File] =
|
||||
for(r <- reports) yield
|
||||
{
|
||||
val file = r.getLocalFile
|
||||
if(file eq null) error("No file for " + r.getArtifact) else file
|
||||
}
|
||||
def updateReport(report: ResolveReport): UpdateReport =
|
||||
new UpdateReport(reports(report) mapValues configurationReport)
|
||||
|
||||
def cachePaths(report: ResolveReport): Map[String, Seq[File]] =
|
||||
reports(report).mapValues(confReport => cachePath(artifactReports(confReport)))
|
||||
def configurationReport(confReport: ConfigurationResolveReport): ConfigurationReport =
|
||||
new ConfigurationReport(confReport.getConfiguration, moduleReports(confReport))
|
||||
}
|
||||
|
||||
final class UpdateReport(val configurations: Map[String, ConfigurationReport])
|
||||
{
|
||||
override def toString = "Update report:\n" + configurations.values.mkString
|
||||
}
|
||||
final class ConfigurationReport(val configuration: String, val modules: Map[ModuleID, ModuleReport])
|
||||
{
|
||||
override def toString = "\t" + configuration + ":\n" + modules.values.mkString
|
||||
}
|
||||
final class ModuleReport(val module: ModuleID, val artifacts: Map[Artifact, File])
|
||||
{
|
||||
override def toString = "\t\t" + module + ": " + (if(artifacts.size <= 1) "" else "\n") + artifacts.mkString("\n\t\t\t") + "\n"
|
||||
}
|
||||
Loading…
Reference in New Issue