sbt/ivy/IvyRetrieve.scala

57 lines
2.1 KiB
Scala
Raw Normal View History

2010-09-04 14:42:37 +02:00
/* sbt -- Simple Build Tool
* Copyright 2010 Mark Harrah
*/
package sbt
import java.io.File
import collection.mutable
2010-09-04 14:42:37 +02:00
import org.apache.ivy.core.{module, report}
import module.descriptor.{Artifact => IvyArtifact}
2010-09-04 14:42:37 +02:00
import module.id.ModuleRevisionId
import report.{ArtifactDownloadReport, ConfigurationResolveReport, ResolveReport}
object IvyRetrieve
{
2011-03-17 03:21:02 +01:00
def reports(report: ResolveReport): Seq[ConfigurationResolveReport] =
report.getConfigurations map report.getConfigurationReport
2010-09-04 14:42:37 +02:00
2011-03-17 03:21:02 +01:00
def moduleReports(confReport: ConfigurationResolveReport): Seq[ModuleReport] =
for( revId <- confReport.getModuleRevisionIds.toArray collect { case revId: ModuleRevisionId => revId }) yield
artifactReports(toModuleID(revId), confReport getDownloadReports revId)
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))
}
2011-03-17 03:21:02 +01:00
new ModuleReport(mid, resolved.toSeq, missing.toSeq)
}
def evicted(confReport: ConfigurationResolveReport): Seq[ModuleID] =
confReport.getEvictedNodes.map(node => toModuleID(node.getId))
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
{
import art._
Artifact(getName, getType, getExt, Option(getExtraAttribute("classifier")), getConfigurations map Configurations.config, Option(getUrl))
2010-09-04 14:42:37 +02:00
}
def updateReport(report: ResolveReport, cachedDescriptor: File): UpdateReport =
new UpdateReport(cachedDescriptor, reports(report) map configurationReport, updateStats(report))
def updateStats(report: ResolveReport): UpdateStats =
new UpdateStats(report.getResolveTime, report.getDownloadTime, report.getDownloadSize)
def configurationReport(confReport: ConfigurationResolveReport): ConfigurationReport =
new ConfigurationReport(confReport.getConfiguration, moduleReports(confReport), evicted(confReport))
}