Search in sources :

Example 1 with VersionControlRepositoryConnection

use of org.gradle.vcs.internal.VersionControlRepositoryConnection in project gradle by gradle.

the class VcsDependencyResolver method resolve.

@Override
public void resolve(DependencyMetadata dependency, VersionSelector acceptor, VersionSelector rejector, BuildableComponentIdResolveResult result) {
    if (dependency.getSelector() instanceof ModuleComponentSelector) {
        final ModuleComponentSelector depSelector = (ModuleComponentSelector) dependency.getSelector();
        VersionControlSpec spec = vcsResolver.locateVcsFor(depSelector);
        // TODO: Need failure handling, e.g., cannot clone repository
        if (spec != null) {
            VersionControlRepositoryConnection repository = versionControlSystemFactory.create(spec);
            File dependencyWorkingDir;
            try {
                dependencyWorkingDir = workingDirResolver.selectVersion(depSelector, repository);
            } catch (ModuleVersionResolveException e) {
                result.failed(e);
                return;
            }
            if (dependencyWorkingDir == null) {
                result.failed(new ModuleVersionNotFoundException(depSelector, Collections.singleton(spec.getDisplayName())));
                return;
            }
            File buildRootDir = new File(dependencyWorkingDir, spec.getRootDir());
            BuildDefinition buildDefinition = toBuildDefinition((AbstractVersionControlSpec) spec, buildRootDir);
            IncludedBuildState includedBuild = buildRegistry.addImplicitIncludedBuild(buildDefinition);
            Collection<Pair<ModuleVersionIdentifier, ProjectComponentIdentifier>> moduleToProject = includedBuild.getAvailableModules();
            Pair<ModuleVersionIdentifier, ProjectComponentIdentifier> entry = CollectionUtils.findFirst(moduleToProject, new Spec<Pair<ModuleVersionIdentifier, ProjectComponentIdentifier>>() {

                @Override
                public boolean isSatisfiedBy(Pair<ModuleVersionIdentifier, ProjectComponentIdentifier> entry) {
                    ModuleVersionIdentifier possibleMatch = entry.left;
                    return depSelector.getGroup().equals(possibleMatch.getGroup()) && depSelector.getModule().equals(possibleMatch.getName());
                }
            });
            if (entry == null) {
                result.failed(new ModuleVersionResolveException(depSelector, () -> spec.getDisplayName() + " did not contain a project publishing the specified dependency."));
            } else {
                LocalComponentMetadata componentMetaData = localComponentRegistry.getComponent(entry.right);
                result.resolved(componentMetaData);
            }
        }
    }
}
Also used : VersionControlRepositoryConnection(org.gradle.vcs.internal.VersionControlRepositoryConnection) ModuleVersionNotFoundException(org.gradle.internal.resolve.ModuleVersionNotFoundException) BuildDefinition(org.gradle.api.internal.BuildDefinition) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) VersionControlSpec(org.gradle.vcs.VersionControlSpec) AbstractVersionControlSpec(org.gradle.vcs.internal.spec.AbstractVersionControlSpec) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) LocalComponentMetadata(org.gradle.internal.component.local.model.LocalComponentMetadata) IncludedBuildState(org.gradle.internal.build.IncludedBuildState) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) File(java.io.File) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) Pair(org.gradle.internal.Pair)

Aggregations

File (java.io.File)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)1 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)1 BuildDefinition (org.gradle.api.internal.BuildDefinition)1 Pair (org.gradle.internal.Pair)1 IncludedBuildState (org.gradle.internal.build.IncludedBuildState)1 LocalComponentMetadata (org.gradle.internal.component.local.model.LocalComponentMetadata)1 ModuleVersionNotFoundException (org.gradle.internal.resolve.ModuleVersionNotFoundException)1 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)1 VersionControlSpec (org.gradle.vcs.VersionControlSpec)1 VersionControlRepositoryConnection (org.gradle.vcs.internal.VersionControlRepositoryConnection)1 AbstractVersionControlSpec (org.gradle.vcs.internal.spec.AbstractVersionControlSpec)1