Search in sources :

Example 11 with ComponentResolveMetadata

use of org.gradle.internal.component.model.ComponentResolveMetadata in project gradle by gradle.

the class EdgeState method calculateTargetConfigurations.

private void calculateTargetConfigurations() {
    targetNodes.clear();
    targetNodeSelectionFailure = null;
    ComponentResolveMetadata targetModuleVersion = targetModuleRevision.getMetadata();
    if (targetModuleVersion == null) {
        // Broken version
        return;
    }
    ImmutableAttributes attributes = resolveState.getRoot().getMetadata().getAttributes();
    List<ConfigurationMetadata> targetConfigurations;
    try {
        targetConfigurations = dependencyMetadata.selectConfigurations(attributes, targetModuleVersion, resolveState.getAttributesSchema());
    } catch (Throwable t) {
        // Failure to select the target variant/configurations from this component, given the dependency attributes/metadata.
        targetNodeSelectionFailure = new ModuleVersionResolveException(dependencyState.getRequested(), t);
        return;
    }
    for (ConfigurationMetadata targetConfiguration : targetConfigurations) {
        NodeState targetNodeState = resolveState.getNode(targetModuleRevision, targetConfiguration);
        this.targetNodes.add(targetNodeState);
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 12 with ComponentResolveMetadata

use of org.gradle.internal.component.model.ComponentResolveMetadata 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 13 with ComponentResolveMetadata

use of org.gradle.internal.component.model.ComponentResolveMetadata in project gradle by gradle.

the class NodeState method addPlatformEdges.

private void addPlatformEdges(Collection<EdgeState> discoveredEdges, ModuleComponentIdentifier platformComponentIdentifier, ModuleComponentSelector platformSelector) {
    PotentialEdge potentialEdge = PotentialEdge.of(resolveState, this, platformComponentIdentifier, platformSelector, platformComponentIdentifier);
    ComponentResolveMetadata metadata = potentialEdge.metadata;
    VirtualPlatformState virtualPlatformState = null;
    if (metadata == null || metadata instanceof LenientPlatformResolveMetadata) {
        virtualPlatformState = potentialEdge.component.getModule().getPlatformState();
        virtualPlatformState.participatingModule(component.getModule());
    }
    if (metadata == null) {
        // the platform doesn't exist, so we're building a lenient one
        metadata = new LenientPlatformResolveMetadata(platformComponentIdentifier, potentialEdge.toModuleVersionId, virtualPlatformState, this, resolveState);
        potentialEdge.component.setMetadata(metadata);
        // And now let's make sure we do not have another version of that virtual platform missing its metadata
        potentialEdge.component.getModule().maybeCreateVirtualMetadata(resolveState);
    }
    if (virtualEdges == null) {
        virtualEdges = Lists.newArrayList();
    }
    EdgeState edge = potentialEdge.edge;
    virtualEdges.add(edge);
    edge.markUsed();
    discoveredEdges.add(edge);
    edge.getSelector().use(false);
}
Also used : ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata)

Example 14 with ComponentResolveMetadata

use of org.gradle.internal.component.model.ComponentResolveMetadata in project gradle by gradle.

the class EdgeState method calculateTargetConfigurations.

private void calculateTargetConfigurations(ComponentState targetComponent) {
    ComponentResolveMetadata targetModuleVersion = targetComponent.getMetadata();
    targetNodes.clear();
    targetNodeSelectionFailure = null;
    if (targetModuleVersion == null) {
        targetComponent.getModule().getPlatformState().addOrphanEdge(this);
        // Broken version
        return;
    }
    if (isConstraint && !isVirtualDependency()) {
        List<NodeState> nodes = targetComponent.getNodes();
        for (NodeState node : nodes) {
            if (node.isSelected()) {
                targetNodes.add(node);
            }
        }
        if (targetNodes.isEmpty()) {
            // There is a chance we could not attach target configurations previously
            List<EdgeState> unattachedDependencies = targetComponent.getModule().getUnattachedDependencies();
            if (!unattachedDependencies.isEmpty()) {
                for (EdgeState otherEdge : unattachedDependencies) {
                    if (otherEdge != this && !otherEdge.isConstraint()) {
                        otherEdge.attachToTargetConfigurations();
                        if (otherEdge.targetNodeSelectionFailure != null) {
                            // Copy selection failure
                            this.targetNodeSelectionFailure = otherEdge.targetNodeSelectionFailure;
                            return;
                        }
                        break;
                    }
                }
            }
            for (NodeState node : nodes) {
                if (node.isSelected()) {
                    targetNodes.add(node);
                }
            }
        }
        return;
    }
    List<ConfigurationMetadata> targetConfigurations;
    try {
        ImmutableAttributes attributes = resolveState.getRoot().getMetadata().getAttributes();
        attributes = resolveState.getAttributesFactory().concat(attributes, safeGetAttributes());
        targetConfigurations = dependencyMetadata.selectConfigurations(attributes, targetModuleVersion, resolveState.getAttributesSchema(), dependencyState.getDependency().getSelector().getRequestedCapabilities());
    } catch (AttributeMergingException mergeError) {
        targetNodeSelectionFailure = new ModuleVersionResolveException(dependencyState.getRequested(), () -> {
            Attribute<?> attribute = mergeError.getAttribute();
            Object constraintValue = mergeError.getLeftValue();
            Object dependencyValue = mergeError.getRightValue();
            return "Inconsistency between attributes of a constraint and a dependency, on attribute '" + attribute + "' : dependency requires '" + dependencyValue + "' while constraint required '" + constraintValue + "'";
        });
        return;
    } catch (Exception t) {
        // Failure to select the target variant/configurations from this component, given the dependency attributes/metadata.
        targetNodeSelectionFailure = new ModuleVersionResolveException(dependencyState.getRequested(), t);
        return;
    }
    for (ConfigurationMetadata targetConfiguration : targetConfigurations) {
        NodeState targetNodeState = resolveState.getNode(targetComponent, targetConfiguration);
        this.targetNodes.add(targetNodeState);
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) AttributeMergingException(org.gradle.api.internal.attributes.AttributeMergingException) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) AttributeMergingException(org.gradle.api.internal.attributes.AttributeMergingException)

Example 15 with ComponentResolveMetadata

use of org.gradle.internal.component.model.ComponentResolveMetadata in project gradle by gradle.

the class DefaultArtifactResolutionQuery method buildComponentResult.

private ComponentArtifactsResult buildComponentResult(ComponentIdentifier componentId, ComponentMetaDataResolver componentMetaDataResolver, ArtifactResolver artifactResolver) {
    BuildableComponentResolveResult moduleResolveResult = new DefaultBuildableComponentResolveResult();
    componentMetaDataResolver.resolve(componentId, DefaultComponentOverrideMetadata.EMPTY, moduleResolveResult);
    ComponentResolveMetadata component = moduleResolveResult.getMetadata();
    DefaultComponentArtifactsResult componentResult = new DefaultComponentArtifactsResult(component.getId());
    for (Class<? extends Artifact> artifactType : artifactTypes) {
        addArtifacts(componentResult, artifactType, component, artifactResolver);
    }
    return componentResult;
}
Also used : DefaultBuildableComponentResolveResult(org.gradle.internal.resolve.result.DefaultBuildableComponentResolveResult) BuildableComponentResolveResult(org.gradle.internal.resolve.result.BuildableComponentResolveResult) DefaultBuildableComponentResolveResult(org.gradle.internal.resolve.result.DefaultBuildableComponentResolveResult) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) DefaultComponentArtifactsResult(org.gradle.api.internal.artifacts.result.DefaultComponentArtifactsResult)

Aggregations

ComponentResolveMetadata (org.gradle.internal.component.model.ComponentResolveMetadata)16 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)3 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)3 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)3 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)2 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)2 Version (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.Version)2 ExcludeSpec (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Nullable (javax.annotation.Nullable)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)1 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)1 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)1 DefaultModuleVersionIdentifier (org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier)1 DefaultConflictResolverDetails (org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.conflicts.DefaultConflictResolverDetails)1 MavenUniqueSnapshotComponentIdentifier (org.gradle.api.internal.artifacts.repositories.resolver.MavenUniqueSnapshotComponentIdentifier)1 DefaultComponentArtifactsResult (org.gradle.api.internal.artifacts.result.DefaultComponentArtifactsResult)1 AttributeMergingException (org.gradle.api.internal.attributes.AttributeMergingException)1