2010-09-04 14:42:37 +02:00
|
|
|
/* sbt -- Simple Build Tool
|
|
|
|
|
* Copyright 2010 Mark Harrah
|
|
|
|
|
*/
|
|
|
|
|
package sbt
|
|
|
|
|
|
|
|
|
|
import java.io.File
|
2011-03-16 01:35:43 +01:00
|
|
|
import collection.mutable
|
2010-09-04 14:42:37 +02:00
|
|
|
|
|
|
|
|
import org.apache.ivy.core.{module, report}
|
2011-03-14 02:40:49 +01:00
|
|
|
import module.descriptor.{Artifact => IvyArtifact}
|
2010-09-04 14:42:37 +02:00
|
|
|
import module.id.ModuleRevisionId
|
|
|
|
|
import report.{ArtifactDownloadReport, ConfigurationResolveReport, ResolveReport}
|
|
|
|
|
|
|
|
|
|
object IvyRetrieve
|
|
|
|
|
{
|
|
|
|
|
def reports(report: ResolveReport): Map[String, ConfigurationResolveReport] =
|
|
|
|
|
( for( conf <- report.getConfigurations) yield (conf, report.getConfigurationReport(conf)) ).toMap
|
|
|
|
|
|
2011-03-14 02:40:49 +01:00
|
|
|
def moduleReports(confReport: ConfigurationResolveReport): Map[ModuleID, ModuleReport] =
|
2011-03-16 01:35:43 +01:00
|
|
|
moduleReportMap(confReport) map { case (mid, arts) => (mid, artifactReports(mid, arts) ) }
|
2011-03-14 02:40:49 +01:00
|
|
|
|
|
|
|
|
def moduleReportMap(confReport: ConfigurationResolveReport): Map[ModuleID, Seq[ArtifactDownloadReport]] =
|
|
|
|
|
{
|
|
|
|
|
val modules =
|
|
|
|
|
for( revId <- confReport.getModuleRevisionIds.toArray collect { case revId: ModuleRevisionId => revId }) yield
|
|
|
|
|
(toModuleID(revId), (confReport getDownloadReports revId).toSeq)
|
|
|
|
|
modules.toMap
|
|
|
|
|
}
|
2011-03-16 01:35:43 +01:00
|
|
|
def artifactReports(mid: ModuleID, artReport: Seq[ArtifactDownloadReport]): ModuleReport =
|
|
|
|
|
{
|
|
|
|
|
val missing = new mutable.ListBuffer[Artifact]
|
|
|
|
|
val resolved = new mutable.ListBuffer[(Artifact,File)]
|
|
|
|
|
for(r <- artReport) {
|
|
|
|
|
val file = r.getLocalFile
|
|
|
|
|
val art = toArtifact(r.getArtifact)
|
|
|
|
|
if(file eq null)
|
|
|
|
|
missing += art
|
|
|
|
|
else
|
|
|
|
|
resolved += ((art,file))
|
|
|
|
|
}
|
|
|
|
|
new ModuleReport(mid, resolved.toMap, missing.toSet)
|
|
|
|
|
}
|
2011-03-14 02:40:49 +01:00
|
|
|
|
|
|
|
|
def toModuleID(revID: ModuleRevisionId): ModuleID =
|
|
|
|
|
ModuleID(revID.getOrganisation, revID.getName, revID.getRevision)
|
|
|
|
|
|
|
|
|
|
def toArtifact(art: IvyArtifact): Artifact =
|
2010-09-04 14:42:37 +02:00
|
|
|
{
|
2011-03-14 02:40:49 +01:00
|
|
|
import art._
|
|
|
|
|
Artifact(getName, getType, getExt, Option(getExtraAttribute("classifier")), getConfigurations map Configurations.config, Option(getUrl))
|
2010-09-04 14:42:37 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-14 02:40:49 +01:00
|
|
|
def updateReport(report: ResolveReport): UpdateReport =
|
|
|
|
|
new UpdateReport(reports(report) mapValues configurationReport)
|
|
|
|
|
|
|
|
|
|
def configurationReport(confReport: ConfigurationResolveReport): ConfigurationReport =
|
|
|
|
|
new ConfigurationReport(confReport.getConfiguration, moduleReports(confReport))
|
|
|
|
|
}
|
2010-09-04 14:42:37 +02:00
|
|
|
|
2011-03-14 02:40:49 +01:00
|
|
|
final class UpdateReport(val configurations: Map[String, ConfigurationReport])
|
|
|
|
|
{
|
|
|
|
|
override def toString = "Update report:\n" + configurations.values.mkString
|
2011-03-16 01:35:43 +01:00
|
|
|
def allModules: Seq[ModuleID] = configurations.values.toSeq.flatMap(_.allModules).distinct
|
|
|
|
|
def retrieve(f: (String, ModuleID, Artifact, File) => File): UpdateReport =
|
|
|
|
|
new UpdateReport(configurations map { case (k,v) => (k, v retrieve f)} )
|
2011-03-14 02:40:49 +01:00
|
|
|
}
|
|
|
|
|
final class ConfigurationReport(val configuration: String, val modules: Map[ModuleID, ModuleReport])
|
|
|
|
|
{
|
|
|
|
|
override def toString = "\t" + configuration + ":\n" + modules.values.mkString
|
2011-03-16 01:35:43 +01:00
|
|
|
def allModules: Seq[ModuleID] = modules.keys.toSeq
|
|
|
|
|
def retrieve(f: (String, ModuleID, Artifact, File) => File): ConfigurationReport =
|
|
|
|
|
new ConfigurationReport(configuration, modules map { case (k,v) => (k, v.retrieve( (mid,art,file) => f(configuration, mid, art, file)) ) })
|
2011-03-14 02:40:49 +01:00
|
|
|
}
|
2011-03-16 01:35:43 +01:00
|
|
|
final class ModuleReport(val module: ModuleID, val artifacts: Map[Artifact, File], val missingArtifacts: Set[Artifact])
|
2011-03-14 02:40:49 +01:00
|
|
|
{
|
2011-03-16 01:35:43 +01:00
|
|
|
override def toString =
|
|
|
|
|
{
|
|
|
|
|
val arts = artifacts.map(_.toString) ++ missingArtifacts.map(art => "(MISSING) " + art)
|
|
|
|
|
"\t\t" + module + ": " +
|
|
|
|
|
(if(arts.size <= 1) "" else "\n\t\t\t") + arts.mkString("\n\t\t\t") + "\n"
|
|
|
|
|
}
|
|
|
|
|
def retrieve(f: (ModuleID, Artifact, File) => File): ModuleReport =
|
|
|
|
|
new ModuleReport(module, artifacts.map { case (art,file) => (art, f(module, art, file)) }, missingArtifacts)
|
2010-09-04 14:42:37 +02:00
|
|
|
}
|