Search in sources :

Example 1 with NodeState

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.NodeState in project gradle by gradle.

the class DefaultCapabilitiesConflictHandler method registerCandidate.

@Override
public PotentialConflict registerCandidate(CapabilitiesConflictHandler.Candidate candidate) {
    CapabilityInternal capability = (CapabilityInternal) candidate.getCapability();
    String group = capability.getGroup();
    String name = capability.getName();
    final Set<NodeState> nodes = findNodesFor(capability);
    Collection<NodeState> implicitCapabilityProviders = candidate.getImplicitCapabilityProviders();
    nodes.addAll(implicitCapabilityProviders);
    NodeState node = candidate.getNode();
    if (nodes.add(node) && nodes.size() > 1) {
        // The registered nodes may contain nodes which are no longer selected.
        // We don't remove them from the list in the first place because it proved to be
        // slower than filtering as needed.
        ModuleIdentifier rootId = null;
        final List<NodeState> candidatesForConflict = Lists.newArrayListWithCapacity(nodes.size());
        for (NodeState ns : nodes) {
            if (ns.isSelected()) {
                candidatesForConflict.add(ns);
                if (ns.isRoot()) {
                    rootId = ns.getComponent().getId().getModule();
                }
            }
        }
        if (rootId != null && candidatesForConflict.size() > 1) {
            // This is a special case for backwards compatibility: it is possible to have
            // a cycle where the root component depends on a library which transitively
            // depends on a different version of the root module. In this case, we effectively
            // allow 2 modules to have the same capability, so we filter the nodes coming
            // from transitive dependencies
            ModuleIdentifier rootModuleId = rootId;
            candidatesForConflict.removeIf(n -> !n.isRoot() && n.getComponent().getId().getModule().equals(rootModuleId));
        }
        if (candidatesForConflict.size() > 1) {
            PotentialConflict conflict = new PotentialConflict() {

                @Override
                public void withParticipatingModules(Action<ModuleIdentifier> action) {
                    for (NodeState node : candidatesForConflict) {
                        action.execute(node.getComponent().getId().getModule());
                    }
                }

                @Override
                public boolean conflictExists() {
                    return true;
                }
            };
            conflicts.add(new CapabilityConflict(group, name, candidatesForConflict));
            return conflict;
        }
    }
    return PotentialConflictFactory.noConflict();
}
Also used : Action(org.gradle.api.Action) NodeState(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.NodeState) CapabilityInternal(org.gradle.internal.component.external.model.CapabilityInternal) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Aggregations

Action (org.gradle.api.Action)1 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)1 NodeState (org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.NodeState)1 CapabilityInternal (org.gradle.internal.component.external.model.CapabilityInternal)1