use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class DynamicVersionResolver method resolve.
public void resolve(ModuleDependencyMetadata dependency, VersionSelector versionSelector, @Nullable VersionSelector rejectedVersionSelector, AttributeContainer consumerAttributes, BuildableComponentIdResolveResult result) {
ModuleComponentSelector requested = dependency.getSelector();
LOGGER.debug("Attempting to resolve version for {} using repositories {}", requested, repositoryNames);
List<Throwable> errors = new ArrayList<>();
List<RepositoryResolveState> resolveStates = Lists.newArrayListWithCapacity(repositories.size());
for (ModuleComponentRepository repository : repositories) {
resolveStates.add(new RepositoryResolveState(versionedComponentChooser, dependency, repository, versionSelector, rejectedVersionSelector, versionParser, consumerAttributes, attributesFactory, componentMetadataProcessor, componentMetadataSupplierRuleExecutor, cachePolicy));
}
final RepositoryChainModuleResolution latestResolved = findLatestModule(resolveStates, errors);
if (latestResolved != null) {
LOGGER.debug("Using {} from {}", latestResolved.module.getModuleVersionId(), latestResolved.repository);
for (Throwable error : errors) {
LOGGER.debug("Discarding resolve failure.", error);
}
found(result, resolveStates, latestResolved);
return;
}
if (!errors.isEmpty()) {
result.failed(new ModuleVersionResolveException(requested, errors));
} else {
notFound(result, requested, resolveStates);
}
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class NodeState method visitOwners.
/**
* If a component declares that it belongs to a platform, we add an edge to the platform.
*
* @param discoveredEdges the collection of edges for this component
*/
private void visitOwners(Collection<EdgeState> discoveredEdges) {
ImmutableList<? extends VirtualComponentIdentifier> owners = component.getMetadata().getPlatformOwners();
if (!owners.isEmpty()) {
PendingDependenciesVisitor visitor = resolveState.newPendingDependenciesVisitor();
for (VirtualComponentIdentifier owner : owners) {
if (owner instanceof ModuleComponentIdentifier) {
ModuleComponentIdentifier platformId = (ModuleComponentIdentifier) owner;
final ModuleComponentSelector cs = DefaultModuleComponentSelector.newSelector(platformId.getModuleIdentifier(), platformId.getVersion());
// There are 2 possibilities here:
// 1. the "platform" referenced is a real module, in which case we directly add it to the graph
// 2. the "platform" is a virtual, constructed thing, in which case we add virtual edges to the graph
addPlatformEdges(discoveredEdges, platformId, cs);
visitor.markNotPending(platformId.getModuleIdentifier());
}
}
visitor.complete();
}
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class DependencyGraphBuilder method attachMultipleForceOnPlatformFailureToEdges.
private void attachMultipleForceOnPlatformFailureToEdges(ModuleResolveState module) {
List<EdgeState> forcedEdges = null;
boolean hasMultipleVersions = false;
String currentVersion = module.maybeFindForcedPlatformVersion();
Set<ModuleResolveState> participatingModules = module.getPlatformState().getParticipatingModules();
for (ModuleResolveState participatingModule : participatingModules) {
for (EdgeState incomingEdge : participatingModule.getIncomingEdges()) {
SelectorState selector = incomingEdge.getSelector();
if (isPlatformForcedEdge(selector)) {
ComponentSelector componentSelector = selector.getSelector();
if (componentSelector instanceof ModuleComponentSelector) {
ModuleComponentSelector mcs = (ModuleComponentSelector) componentSelector;
if (!incomingEdge.getFrom().getComponent().getModule().equals(module)) {
if (forcedEdges == null) {
forcedEdges = Lists.newArrayList();
}
forcedEdges.add(incomingEdge);
if (currentVersion == null) {
currentVersion = mcs.getVersion();
} else {
if (!currentVersion.equals(mcs.getVersion())) {
hasMultipleVersions = true;
}
}
}
}
}
}
}
if (hasMultipleVersions) {
attachFailureToEdges(new GradleException("Multiple forces on different versions for virtual platform " + module.getId()), forcedEdges);
}
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class ComponentSelectorSerializer method write.
@Override
public void write(Encoder encoder, ComponentSelector value) throws IOException {
if (value == null) {
throw new IllegalArgumentException("Provided component selector may not be null");
}
Implementation implementation = resolveImplementation(value);
encoder.writeByte(implementation.getId());
if (implementation == Implementation.MODULE) {
ModuleComponentSelector moduleComponentSelector = (ModuleComponentSelector) value;
encoder.writeString(moduleComponentSelector.getGroup());
encoder.writeString(moduleComponentSelector.getModule());
VersionConstraint versionConstraint = moduleComponentSelector.getVersionConstraint();
writeVersionConstraint(encoder, versionConstraint);
writeAttributes(encoder, moduleComponentSelector.getAttributes());
writeCapabilities(encoder, moduleComponentSelector.getRequestedCapabilities());
} else if (implementation == Implementation.ROOT_PROJECT) {
DefaultProjectComponentSelector projectComponentSelector = (DefaultProjectComponentSelector) value;
buildIdentifierSerializer.write(encoder, projectComponentSelector.getBuildIdentifier());
encoder.writeString(projectComponentSelector.getProjectName());
writeAttributes(encoder, projectComponentSelector.getAttributes());
writeCapabilities(encoder, projectComponentSelector.getRequestedCapabilities());
} else if (implementation == Implementation.ROOT_BUILD_PROJECT) {
DefaultProjectComponentSelector projectComponentSelector = (DefaultProjectComponentSelector) value;
buildIdentifierSerializer.write(encoder, projectComponentSelector.getBuildIdentifier());
encoder.writeString(projectComponentSelector.getProjectPath());
writeAttributes(encoder, projectComponentSelector.getAttributes());
writeCapabilities(encoder, projectComponentSelector.getRequestedCapabilities());
} else if (implementation == Implementation.OTHER_BUILD_ROOT_PROJECT) {
DefaultProjectComponentSelector projectComponentSelector = (DefaultProjectComponentSelector) value;
buildIdentifierSerializer.write(encoder, projectComponentSelector.getBuildIdentifier());
encoder.writeString(projectComponentSelector.getIdentityPath().getPath());
writeAttributes(encoder, projectComponentSelector.getAttributes());
writeCapabilities(encoder, projectComponentSelector.getRequestedCapabilities());
} else if (implementation == Implementation.OTHER_BUILD_PROJECT) {
DefaultProjectComponentSelector projectComponentSelector = (DefaultProjectComponentSelector) value;
buildIdentifierSerializer.write(encoder, projectComponentSelector.getBuildIdentifier());
encoder.writeString(projectComponentSelector.getIdentityPath().getPath());
encoder.writeString(projectComponentSelector.getProjectPath());
writeAttributes(encoder, projectComponentSelector.getAttributes());
writeCapabilities(encoder, projectComponentSelector.getRequestedCapabilities());
} else if (implementation == Implementation.LIBRARY) {
LibraryComponentSelector libraryComponentSelector = (LibraryComponentSelector) value;
encoder.writeString(libraryComponentSelector.getProjectPath());
encoder.writeNullableString(libraryComponentSelector.getLibraryName());
encoder.writeNullableString(libraryComponentSelector.getVariant());
} else {
throw new IllegalStateException("Unsupported implementation type: " + implementation);
}
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class DefaultResolutionResultBuilder method addExtraFailures.
public void addExtraFailures(Long rootId, Set<UnresolvedDependency> extraFailures) {
DefaultResolvedComponentResult root = modules.get(rootId);
for (UnresolvedDependency failure : extraFailures) {
ModuleVersionSelector failureSelector = failure.getSelector();
ModuleComponentSelector failureComponentSelector = DefaultModuleComponentSelector.newSelector(failureSelector.getModule(), failureSelector.getVersion());
root.addDependency(dependencyResultFactory.createUnresolvedDependency(failureComponentSelector, root, true, ComponentSelectionReasons.of(DEPENDENCY_LOCKING), new ModuleVersionResolveException(failureComponentSelector, () -> "Dependency lock state out of date", failure.getProblem())));
}
}
Aggregations