Search in sources :

Example 1 with ComponentIdResolveResult

use of org.gradle.internal.resolve.result.ComponentIdResolveResult in project gradle by gradle.

the class DependencyGraphBuilder method performSelection.

/**
 * Attempts to resolve a target `ComponentState` for the given dependency.
 * On successful resolve, a `ComponentState` is constructed for the identifier, recorded as {@link SelectorState#selected},
 * and added to the graph.
 * On resolve failure, the failure is recorded and no `ComponentState` is selected.
 */
private void performSelection(ResolveState resolveState, EdgeState dependency, SelectorState selector) {
    // Selector already resolved: just attach the edge.
    if (selector.selected != null) {
        dependency.start(selector.selected);
        return;
    }
    ComponentIdResolveResult idResolveResult = selector.resolve();
    if (idResolveResult.getFailure() != null) {
        // Resolve failure, nothing more to do.
        return;
    }
    ComponentState candidate = resolveState.getRevision(idResolveResult.getId(), idResolveResult.getModuleVersionId(), idResolveResult.getMetadata());
    ModuleResolveState module = selector.getTargetModule();
    ComponentState currentSelection = module.getSelected();
    // TODO:DAZ Should not need to select the candidate if the current selection ends up being chosen.
    // But some of the logic to choose between currentSelection and candidate requires that these be set.
    dependency.start(candidate);
    selector.select(candidate);
    // If no current selection for module, just use the candidate.
    if (currentSelection == null) {
        // This is the first time we've seen the module, so register with conflict resolver.
        if (!moduleHasConflicts(resolveState, module)) {
            // No conflicting modules. Select it for now
            LOGGER.debug("Selecting new module {}", module.getId());
            module.select(candidate);
        }
        return;
    }
    // Choose the best option from the current selection and the new candidate.
    // This choice is made considering _all_ selectors registered for this module.
    ComponentState selected = chooseBest(module, selector, currentSelection, candidate);
    // If current selection is still the best choice, then only need to point new edge/selector at current selection.
    if (selected == currentSelection) {
        dependency.start(currentSelection);
        selector.select(currentSelection);
        // Since we have a new selector for the current selection, check if it's now rejected.
        // TODO:DAZ It's wasteful to recheck all of the existing selectors. Should only check the new one.
        maybeMarkRejected(currentSelection);
        return;
    }
    // New candidate is a preferred choice over current selection. Reset the module state and reselect.
    assert selected == candidate;
    resolveState.getDeselectVersionAction().execute(module.getId());
    module.restart(candidate);
    // Check the candidate against all selectors to see if it's rejected.
    maybeMarkRejected(candidate);
}
Also used : ComponentIdResolveResult(org.gradle.internal.resolve.result.ComponentIdResolveResult)

Example 2 with ComponentIdResolveResult

use of org.gradle.internal.resolve.result.ComponentIdResolveResult in project gradle by gradle.

the class SelectorStateResolver method integratePreferResults.

/**
 * Given the result of resolving any 'prefer' constraints, see if these can be used to further refine the results
 *  of resolving the 'require' constraints.
 */
private void integratePreferResults(ModuleSelectors<? extends ResolvableSelectorState> selectors, SelectorStateResolverResults results, TreeSet<ComponentIdResolveResult> preferResults) {
    if (preferResults == null) {
        return;
    }
    // If no result from 'require', just use the highest preferred version (no range merging)
    if (results.isEmpty()) {
        ComponentIdResolveResult highestPreferredVersion = preferResults.first();
        results.register(selectors.first(), highestPreferredVersion);
        return;
    }
    for (ComponentIdResolveResult preferResult : preferResults) {
        // Use the highest preferred version that refines the chosen 'require' selector
        if (results.replaceExistingResolutionsWithBetterResult(preferResult, false)) {
            break;
        }
    }
}
Also used : ComponentIdResolveResult(org.gradle.internal.resolve.result.ComponentIdResolveResult)

Example 3 with ComponentIdResolveResult

use of org.gradle.internal.resolve.result.ComponentIdResolveResult in project gradle by gradle.

the class SelectorStateResolver method resolveRequireConstraint.

/**
 * Resolve the 'require' constraint of the selector.
 * A version will be registered for this selector, and it will participate in conflict resolution.
 */
private void resolveRequireConstraint(SelectorStateResolverResults results, ResolvableSelectorState selector, VersionSelector allRejects) {
    // Check already resolved results for a compatible version, and use it for this dependency rather than re-resolving.
    if (results.alreadyHaveResolutionForSelector(selector)) {
        return;
    }
    // Need to perform the actual resolve
    ComponentIdResolveResult result = selector.resolve(allRejects);
    if (result.getFailure() != null) {
        results.register(selector, result);
        return;
    }
    results.replaceExistingResolutionsWithBetterResult(result, selector.isFromLock());
    results.register(selector, result);
}
Also used : ComponentIdResolveResult(org.gradle.internal.resolve.result.ComponentIdResolveResult)

Example 4 with ComponentIdResolveResult

use of org.gradle.internal.resolve.result.ComponentIdResolveResult in project gradle by gradle.

the class SelectorStateResolver method maybeResolvePreferConstraint.

/**
 * Collect the result of the 'prefer' constraint of the selector, if present and not failing.
 * These results are integrated with the 'require' results in the second phase.
 */
private TreeSet<ComponentIdResolveResult> maybeResolvePreferConstraint(TreeSet<ComponentIdResolveResult> previousResults, ResolvableSelectorState selector, VersionSelector allRejects) {
    TreeSet<ComponentIdResolveResult> preferResults = previousResults;
    ComponentIdResolveResult resolvedPreference = selector.resolvePrefer(allRejects);
    if (resolvedPreference != null && resolvedPreference.getFailure() == null) {
        if (preferResults == null) {
            preferResults = Sets.newTreeSet(new DescendingResolveResultComparator());
        }
        preferResults.add(resolvedPreference);
    }
    return preferResults;
}
Also used : ComponentIdResolveResult(org.gradle.internal.resolve.result.ComponentIdResolveResult)

Example 5 with ComponentIdResolveResult

use of org.gradle.internal.resolve.result.ComponentIdResolveResult in project gradle by gradle.

the class SelectorStateResolver method resolveSingleSelector.

private List<T> resolveSingleSelector(ResolvableSelectorState selectorState, VersionSelector allRejects) {
    assert selectorState.getVersionConstraint() == null || selectorState.getVersionConstraint().getPreferredSelector() == null;
    ComponentIdResolveResult resolved = selectorState.resolve(allRejects);
    T selected = SelectorStateResolverResults.componentForIdResolveResult(componentFactory, resolved, selectorState);
    return Collections.singletonList(selected);
}
Also used : ComponentIdResolveResult(org.gradle.internal.resolve.result.ComponentIdResolveResult)

Aggregations

ComponentIdResolveResult (org.gradle.internal.resolve.result.ComponentIdResolveResult)9 ComponentSelectionDescriptorInternal (org.gradle.api.internal.artifacts.ivyservice.resolveengine.result.ComponentSelectionDescriptorInternal)1 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)1 RejectedByAttributesVersion (org.gradle.internal.resolve.RejectedByAttributesVersion)1 RejectedByRuleVersion (org.gradle.internal.resolve.RejectedByRuleVersion)1 RejectedBySelectorVersion (org.gradle.internal.resolve.RejectedBySelectorVersion)1 RejectedVersion (org.gradle.internal.resolve.RejectedVersion)1 BuildableComponentIdResolveResult (org.gradle.internal.resolve.result.BuildableComponentIdResolveResult)1 DefaultBuildableComponentIdResolveResult (org.gradle.internal.resolve.result.DefaultBuildableComponentIdResolveResult)1