mirror of https://github.com/sbt/sbt.git
ProjectResolver for inter-project dependencies
This commit is contained in:
parent
82e53d2528
commit
6deb83ded3
|
|
@ -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") }
|
||||
}
|
||||
|
|
@ -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]; }
|
||||
}
|
||||
Loading…
Reference in New Issue