Search in sources :

Example 1 with ConflictResolutionResult

use of org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.conflicts.ConflictResolutionResult in project gradle by gradle.

the class DependencyGraphBuilder method traverseGraph.

/**
     * Traverses the dependency graph, resolving conflicts and building the paths from the root configuration.
     */
private void traverseGraph(final ResolveState resolveState, final ConflictHandler conflictHandler) {
    resolveState.onMoreSelected(resolveState.root);
    List<DependencyEdge> dependencies = new ArrayList<DependencyEdge>();
    while (resolveState.peek() != null || conflictHandler.hasConflicts()) {
        if (resolveState.peek() != null) {
            ConfigurationNode node = resolveState.pop();
            LOGGER.debug("Visiting configuration {}.", node);
            // Calculate the outgoing edges of this configuration
            dependencies.clear();
            node.visitOutgoingDependencies(dependencies);
            for (DependencyEdge dependency : dependencies) {
                LOGGER.debug("Visiting dependency {}", dependency);
                // Resolve dependency to a particular revision
                ModuleVersionResolveState moduleRevision = dependency.resolveModuleRevisionId();
                if (moduleRevision == null) {
                    // Failed to resolve.
                    continue;
                }
                ModuleIdentifier moduleId = moduleRevision.id.getModule();
                // Check for a new conflict
                if (moduleRevision.state == ModuleState.New) {
                    ModuleResolveState module = resolveState.getModule(moduleId);
                    // A new module revision. Check for conflict
                    PotentialConflict c = conflictHandler.registerModule(module);
                    if (!c.conflictExists()) {
                        // No conflict. Select it for now
                        LOGGER.debug("Selecting new module version {}", moduleRevision);
                        module.select(moduleRevision);
                    } else {
                        // We have a conflict
                        LOGGER.debug("Found new conflicting module version {}", moduleRevision);
                        // Deselect the currently selected version, and remove all outgoing edges from the version
                        // This will propagate through the graph and prune configurations that are no longer required
                        // For each module participating in the conflict (many times there is only one participating module that has multiple versions)
                        c.withParticipatingModules(new Action<ModuleIdentifier>() {

                            public void execute(ModuleIdentifier module) {
                                ModuleVersionResolveState previouslySelected = resolveState.getModule(module).clearSelection();
                                if (previouslySelected != null) {
                                    for (ConfigurationNode configuration : previouslySelected.configurations) {
                                        configuration.deselect();
                                    }
                                }
                            }
                        });
                    }
                }
                dependency.attachToTargetConfigurations();
            }
        } else {
            // We have some batched up conflicts. Resolve the first, and continue traversing the graph
            conflictHandler.resolveNextConflict(new Action<ConflictResolutionResult>() {

                public void execute(final ConflictResolutionResult result) {
                    result.getConflict().withParticipatingModules(new Action<ModuleIdentifier>() {

                        public void execute(ModuleIdentifier moduleIdentifier) {
                            ModuleVersionResolveState selected = result.getSelected();
                            // Restart each configuration. For the evicted configuration, this means moving incoming dependencies across to the
                            // matching selected configuration. For the select configuration, this mean traversing its dependencies.
                            resolveState.getModule(moduleIdentifier).restart(selected);
                        }
                    });
                }
            });
        }
    }
}
Also used : ConflictResolutionResult(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.conflicts.ConflictResolutionResult) Action(org.gradle.api.Action) PotentialConflict(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.conflicts.PotentialConflict) ArrayList(java.util.ArrayList) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Aggregations

ArrayList (java.util.ArrayList)1 Action (org.gradle.api.Action)1 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)1 ConflictResolutionResult (org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.conflicts.ConflictResolutionResult)1 PotentialConflict (org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.conflicts.PotentialConflict)1