Search in sources :

Example 31 with ModuleComponentSelector

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);
    }
}
Also used : ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ArrayList(java.util.ArrayList) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException)

Example 32 with ModuleComponentSelector

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();
    }
}
Also used : DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) VirtualComponentIdentifier(org.gradle.internal.component.external.model.VirtualComponentIdentifier)

Example 33 with ModuleComponentSelector

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);
    }
}
Also used : ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) GradleException(org.gradle.api.GradleException)

Example 34 with ModuleComponentSelector

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);
    }
}
Also used : ImmutableVersionConstraint(org.gradle.api.internal.artifacts.ImmutableVersionConstraint) VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) DefaultProjectComponentSelector(org.gradle.internal.component.local.model.DefaultProjectComponentSelector) LibraryComponentSelector(org.gradle.api.artifacts.component.LibraryComponentSelector) DefaultLibraryComponentSelector(org.gradle.internal.component.local.model.DefaultLibraryComponentSelector)

Example 35 with ModuleComponentSelector

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())));
    }
}
Also used : ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector) UnresolvedDependency(org.gradle.api.artifacts.UnresolvedDependency) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) DefaultResolvedComponentResult(org.gradle.api.internal.artifacts.result.DefaultResolvedComponentResult)

Aggregations

ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)46 DefaultModuleComponentSelector (org.gradle.internal.component.external.model.DefaultModuleComponentSelector)21 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)10 ProjectComponentSelector (org.gradle.api.artifacts.component.ProjectComponentSelector)9 DefaultImmutableVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)8 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)7 ExcludeMetadata (org.gradle.internal.component.model.ExcludeMetadata)6 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)5 ModuleVersionSelector (org.gradle.api.artifacts.ModuleVersionSelector)5 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)5 IvyArtifactName (org.gradle.internal.component.model.IvyArtifactName)5 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)5 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)4 DefaultModuleVersionSelector (org.gradle.api.internal.artifacts.DefaultModuleVersionSelector)4 DefaultExclude (org.gradle.internal.component.external.descriptor.DefaultExclude)4 DefaultProjectComponentSelector (org.gradle.internal.component.local.model.DefaultProjectComponentSelector)4 ArrayList (java.util.ArrayList)3 ExternalModuleDependency (org.gradle.api.artifacts.ExternalModuleDependency)3 VersionConstraint (org.gradle.api.artifacts.VersionConstraint)3 MavenScope (org.gradle.internal.component.external.descriptor.MavenScope)3