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);
}
}
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);
}
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));
}
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;
}
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;
}
Aggregations