Search in sources :

Example 31 with ProjectComponentIdentifier

use of org.gradle.api.artifacts.component.ProjectComponentIdentifier in project gradle by gradle.

the class ProjectDependencyForcingResolver method select.

@Override
public <T extends ComponentResolutionState> void select(ConflictResolverDetails<T> details) {
    // the collection will only be initialized if more than one project candidate is found
    Collection<T> projectCandidates = null;
    T foundProjectCandidate = null;
    // fine one or more project dependencies among conflicting modules
    for (T candidate : details.getCandidates()) {
        ComponentResolveMetadata metaData = candidate.getMetadata();
        if (metaData != null && metaData.getId() instanceof ProjectComponentIdentifier) {
            if (foundProjectCandidate == null) {
                // found the first project dependency
                foundProjectCandidate = candidate;
            } else {
                // found more than one
                if (projectCandidates == null) {
                    projectCandidates = new ArrayList<T>();
                    projectCandidates.add(foundProjectCandidate);
                }
                projectCandidates.add(candidate);
            }
        }
    }
    // let the delegate resolver select among them
    if (projectCandidates != null) {
        ConflictResolverDetails<T> projectDetails = new DefaultConflictResolverDetails<T>(Cast.<List<T>>uncheckedCast(projectCandidates));
        delegate.select(projectDetails);
        details.select(projectDetails.getSelected());
        return;
    }
    // if found only one project dependency - return it, otherwise call the next resolver
    if (foundProjectCandidate != null) {
        details.select(foundProjectCandidate);
    } else {
        delegate.select(details);
    }
}
Also used : DefaultConflictResolverDetails(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.conflicts.DefaultConflictResolverDetails) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 32 with ProjectComponentIdentifier

use of org.gradle.api.artifacts.component.ProjectComponentIdentifier in project gradle by gradle.

the class VcsDependencyResolver method resolve.

@Override
public void resolve(DependencyMetadata dependency, ResolvedVersionConstraint versionConstraint, 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) {
            VersionControlSystem versionControlSystem = versionControlSystemFactory.create(spec);
            VersionRef selectedVersion = selectVersion(depSelector, spec, versionControlSystem);
            if (selectedVersion == null) {
                result.failed(new ModuleVersionNotFoundException(depSelector, Collections.singleton(spec.getDisplayName())));
                return;
            }
            File dependencyWorkingDir = new File(populateWorkingDirectory(baseWorkingDir, spec, versionControlSystem, selectedVersion), spec.getRootDir());
            // TODO: This shouldn't rely on the service registry to find NestedBuildFactory
            IncludedBuildRegistry includedBuildRegistry = serviceRegistry.get(IncludedBuildRegistry.class);
            NestedBuildFactory nestedBuildFactory = serviceRegistry.get(NestedBuildFactory.class);
            IncludedBuildInternal includedBuild = includedBuildRegistry.addImplicitBuild(((AbstractVersionControlSpec) spec).getBuildDefinition(dependencyWorkingDir), nestedBuildFactory);
            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);
                if (componentMetaData == null) {
                    result.failed(new ModuleVersionResolveException(DefaultProjectComponentSelector.newSelector(includedBuild.getModel(), entry.right.getProjectPath()), spec.getDisplayName() + " could not be resolved into a usable project."));
                } else {
                    result.resolved(componentMetaData);
                }
                return;
            }
        }
    }
    projectDependencyResolver.resolve(dependency, versionConstraint, result);
}
Also used : VersionRef(org.gradle.vcs.internal.VersionRef) ModuleVersionNotFoundException(org.gradle.internal.resolve.ModuleVersionNotFoundException) VersionControlSystem(org.gradle.vcs.internal.VersionControlSystem) NestedBuildFactory(org.gradle.initialization.NestedBuildFactory) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) IncludedBuildInternal(org.gradle.composite.internal.IncludedBuildInternal) IncludedBuildRegistry(org.gradle.composite.internal.IncludedBuildRegistry) 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) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) File(java.io.File) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) Pair(org.gradle.internal.Pair)

Example 33 with ProjectComponentIdentifier

use of org.gradle.api.artifacts.component.ProjectComponentIdentifier in project gradle by gradle.

the class DefaultIncludedBuild method registerProject.

private void registerProject(Set<Pair<ModuleVersionIdentifier, ProjectComponentIdentifier>> availableModules, ProjectInternal project) {
    LocalComponentRegistry localComponentRegistry = project.getServices().get(LocalComponentRegistry.class);
    ProjectComponentIdentifier originalIdentifier = newProjectId(project);
    DefaultLocalComponentMetadata originalComponent = (DefaultLocalComponentMetadata) localComponentRegistry.getComponent(originalIdentifier);
    ProjectComponentIdentifier componentIdentifier = idForProjectInThisBuild(project.getPath());
    ModuleVersionIdentifier moduleId = originalComponent.getModuleVersionId();
    LOGGER.info("Registering " + project + " in composite build. Will substitute for module '" + moduleId.getModule() + "'.");
    availableModules.add(Pair.of(moduleId, componentIdentifier));
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DefaultLocalComponentMetadata(org.gradle.internal.component.local.model.DefaultLocalComponentMetadata) LocalComponentRegistry(org.gradle.api.internal.artifacts.ivyservice.projectmodule.LocalComponentRegistry) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) DefaultProjectComponentIdentifier(org.gradle.internal.component.local.model.DefaultProjectComponentIdentifier)

Example 34 with ProjectComponentIdentifier

use of org.gradle.api.artifacts.component.ProjectComponentIdentifier in project gradle by gradle.

the class IncludedBuildDependencyMetadataBuilder method build.

public Map<ProjectComponentIdentifier, RegisteredProject> build(IncludedBuildInternal build) {
    Map<ProjectComponentIdentifier, RegisteredProject> registeredProjects = Maps.newHashMap();
    Gradle gradle = build.getConfiguredBuild();
    for (Project project : gradle.getRootProject().getAllprojects()) {
        registerProject(registeredProjects, build, (ProjectInternal) project);
    }
    return registeredProjects;
}
Also used : Project(org.gradle.api.Project) Gradle(org.gradle.api.invocation.Gradle) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 35 with ProjectComponentIdentifier

use of org.gradle.api.artifacts.component.ProjectComponentIdentifier in project spring-boot by spring-projects.

the class AbstractBootArchiveTests method mockProjectArtifact.

private ResolvedArtifact mockProjectArtifact(String fileName, String group, String module, String version) {
    ProjectComponentIdentifier projectComponentIdentifier = mock(ProjectComponentIdentifier.class);
    ComponentArtifactIdentifier projectArtifactId = mock(ComponentArtifactIdentifier.class);
    given(projectArtifactId.getComponentIdentifier()).willReturn(projectComponentIdentifier);
    ResolvedArtifact projectArtifact = mockArtifact(fileName, group, module, version);
    given(projectArtifact.getId()).willReturn(projectArtifactId);
    return projectArtifact;
}
Also used : ComponentArtifactIdentifier(org.gradle.api.artifacts.component.ComponentArtifactIdentifier) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Aggregations

ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)52 File (java.io.File)12 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)12 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)9 LocalComponentMetadata (org.gradle.internal.component.local.model.LocalComponentMetadata)9 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)7 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)7 ProjectComponentSelector (org.gradle.api.artifacts.component.ProjectComponentSelector)6 DefaultLocalComponentMetadata (org.gradle.internal.component.local.model.DefaultLocalComponentMetadata)6 Project (org.gradle.api.Project)5 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)5 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)5 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)5 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)5 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)5 LocalComponentRegistry (org.gradle.api.internal.artifacts.ivyservice.projectmodule.LocalComponentRegistry)5 BuildIdentifier (org.gradle.api.artifacts.component.BuildIdentifier)4 DefaultProjectComponentSelector (org.gradle.internal.component.local.model.DefaultProjectComponentSelector)4 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)3 UnresolvedDependencyResult (org.gradle.api.artifacts.result.UnresolvedDependencyResult)3