diff --git a/ivy/ProjectResolver.scala b/ivy/ProjectResolver.scala new file mode 100644 index 000000000..1282808ee --- /dev/null +++ b/ivy/ProjectResolver.scala @@ -0,0 +1,83 @@ +package sbt + + import java.io.File + import java.util.Date + + import org.apache.ivy.{core,plugins} + import core.{cache,module, report, resolve,search} + import cache.{ArtifactOrigin,RepositoryCacheManager} + import search.{ModuleEntry, OrganisationEntry, RevisionEntry} + import module.id.ModuleRevisionId + import module.descriptor.{Artifact => IArtifact, DefaultArtifact, DependencyDescriptor, ModuleDescriptor} + import plugins.namespace.Namespace + import plugins.resolver.{DependencyResolver,ResolverSettings} + import report.{ArtifactDownloadReport, DownloadReport, DownloadStatus, MetadataArtifactDownloadReport} + import resolve.{DownloadOptions, ResolveData, ResolvedModuleRevision} + +/**A Resolver that uses a predefined mapping from module ids to in-memory descriptors. +* It does not handle artifacts.*/ +class ProjectResolver(name: String, map: Map[ModuleRevisionId, ModuleDescriptor]) extends ResolverAdapter +{ + def getName = name + def setName(name: String) = error("Setting name not supported by ProjectResolver") + + def getDependency(dd: DependencyDescriptor, data: ResolveData): ResolvedModuleRevision = + { + val revisionId = dd.getDependencyRevisionId + def constructResult(descriptor: ModuleDescriptor) = new ResolvedModuleRevision(this, this, descriptor, report(revisionId), true) + val dep = (map get revisionId map constructResult).orNull + dep + } + + def report(revisionId: ModuleRevisionId): MetadataArtifactDownloadReport = + { + val artifact = DefaultArtifact.newIvyArtifact(revisionId, new Date) + val r = new MetadataArtifactDownloadReport(artifact) + r.setSearched(false) + r.setDownloadStatus(DownloadStatus.NO) + r + } + + def findIvyFileRef(dd: DependencyDescriptor, data: ResolveData) = null + + // this resolver nevers locates artifacts, only resolves dependencies + def exists(artifact: IArtifact) = false + def locate(artifact: IArtifact) = null + + def notDownloaded(artifact: IArtifact): ArtifactDownloadReport= + { + val r = new ArtifactDownloadReport(artifact) + r.setDownloadStatus(DownloadStatus.NO) + r + } + def download(artifacts: Array[IArtifact], options: DownloadOptions): DownloadReport = + { + val r = new DownloadReport + for(artifact <- artifacts) + r addArtifactReport notDownloaded(artifact) + r + } + def download(artifact: ArtifactOrigin, options: DownloadOptions): ArtifactDownloadReport = + notDownloaded(artifact.getArtifact) + + // doesn't support publishing + def publish(artifact: IArtifact, src: File, overwrite: Boolean) = error("Publish not supported by ProjectResolver") + def beginPublishTransaction(module: ModuleRevisionId, overwrite: Boolean) {} + def abortPublishTransaction() {} + def commitPublishTransaction() {} + + def reportFailure() {} + def reportFailure(art: IArtifact) {} + + def listOrganisations() = new Array[OrganisationEntry](0) + def listModules(org: OrganisationEntry) = new Array[ModuleEntry](0) + def listRevisions(module: ModuleEntry) = new Array[RevisionEntry](0) + + def getNamespace = Namespace.SYSTEM_NAMESPACE + + private[this] var settings: Option[ResolverSettings] = None + + def dumpSettings() {} + def setSettings(settings: ResolverSettings) { this.settings = Some(settings) } + def getRepositoryCacheManager = settings match { case Some(s) => s.getDefaultRepositoryCacheManager; case None => error("No settings defined for ProjectResolver") } +} diff --git a/ivy/ResolverAdapter.java b/ivy/ResolverAdapter.java new file mode 100644 index 000000000..40b1b6268 --- /dev/null +++ b/ivy/ResolverAdapter.java @@ -0,0 +1,12 @@ +package sbt; + + import java.util.Map; + import org.apache.ivy.plugins.resolver.DependencyResolver; + +// implements the methods with raw types +public abstract class ResolverAdapter implements DependencyResolver +{ + public String[] listTokenValues(String token, Map otherTokenValues) { return new String[0]; } + + public Map[] listTokenValues(String[] tokens, Map criteria) { return new Map[0]; } +} \ No newline at end of file