Search in sources :

Example 1 with DependencySubstitutionInternal

use of org.gradle.api.internal.artifacts.DependencySubstitutionInternal in project gradle by gradle.

the class DependencySubstitutionResolver method resolve.

public void resolve(DependencyMetadata dependency, BuildableComponentIdResolveResult result) {
    ComponentSelector selector = dependency.getSelector();
    DependencySubstitutionInternal details = new DefaultDependencySubstitution(selector, dependency.getRequested());
    try {
        rule.execute(details);
    } catch (Throwable e) {
        result.failed(new ModuleVersionResolveException(selector, e));
        return;
    }
    if (details.isUpdated()) {
        resolver.resolve(dependency.withTarget(details.getTarget()), result);
        result.setSelectionReason(details.getSelectionReason());
        return;
    }
    resolver.resolve(dependency, result);
}
Also used : ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) DependencySubstitutionInternal(org.gradle.api.internal.artifacts.DependencySubstitutionInternal)

Example 2 with DependencySubstitutionInternal

use of org.gradle.api.internal.artifacts.DependencySubstitutionInternal in project gradle by gradle.

the class NodeState method maybeSubstitute.

/**
 * Execute any dependency substitution rules that apply to this dependency.
 *
 * This may be better done as a decorator on ConfigurationMetadata.getDependencies()
 */
static DependencyState maybeSubstitute(DependencyState dependencyState, DependencySubstitutionApplicator dependencySubstitutionApplicator) {
    DependencySubstitutionApplicator.SubstitutionResult substitutionResult = dependencySubstitutionApplicator.apply(dependencyState.getDependency());
    if (substitutionResult.hasFailure()) {
        dependencyState.failure = new ModuleVersionResolveException(dependencyState.getRequested(), substitutionResult.getFailure());
        return dependencyState;
    }
    DependencySubstitutionInternal details = substitutionResult.getResult();
    if (details != null && details.isUpdated()) {
        ArtifactSelectionDetailsInternal artifactSelectionDetails = details.getArtifactSelectionDetails();
        if (artifactSelectionDetails.isUpdated()) {
            return dependencyState.withTargetAndArtifacts(details.getTarget(), artifactSelectionDetails.getTargetSelectors(), details.getRuleDescriptors());
        }
        return dependencyState.withTarget(details.getTarget(), details.getRuleDescriptors());
    }
    return dependencyState;
}
Also used : ArtifactSelectionDetailsInternal(org.gradle.api.internal.artifacts.ivyservice.dependencysubstitution.ArtifactSelectionDetailsInternal) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) DependencySubstitutionApplicator(org.gradle.api.internal.artifacts.ivyservice.dependencysubstitution.DependencySubstitutionApplicator) DependencySubstitutionInternal(org.gradle.api.internal.artifacts.DependencySubstitutionInternal)

Example 3 with DependencySubstitutionInternal

use of org.gradle.api.internal.artifacts.DependencySubstitutionInternal in project gradle by gradle.

the class NodeState method maybeSubstitute.

/**
 * Execute any dependency substitution rules that apply to this dependency.
 *
 * This may be better done as a decorator on ConfigurationMetadata.getDependencies()
 */
private DependencyState maybeSubstitute(DependencyState dependencyState) {
    DependencySubstitutionApplicator.SubstitutionResult substitutionResult = resolveState.getDependencySubstitutionApplicator().apply(dependencyState.getDependency());
    if (substitutionResult.hasFailure()) {
        dependencyState.failure = new ModuleVersionResolveException(dependencyState.getRequested(), substitutionResult.getFailure());
        return dependencyState;
    }
    DependencySubstitutionInternal details = substitutionResult.getResult();
    if (details != null && details.isUpdated()) {
        return dependencyState.withTarget(details.getTarget(), details.getSelectionDescription());
    }
    return dependencyState;
}
Also used : ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) DependencySubstitutionApplicator(org.gradle.api.internal.artifacts.ivyservice.dependencysubstitution.DependencySubstitutionApplicator) DependencySubstitutionInternal(org.gradle.api.internal.artifacts.DependencySubstitutionInternal)

Example 4 with DependencySubstitutionInternal

use of org.gradle.api.internal.artifacts.DependencySubstitutionInternal in project gradle by gradle.

the class CompositeBuildDependencySubstitutions method execute.

@Override
public void execute(DependencySubstitution sub) {
    DependencySubstitutionInternal dependencySubstitution = (DependencySubstitutionInternal) sub;
    // Use the result of previous rules as the input for dependency substitution
    ComponentSelector requested = dependencySubstitution.getTarget();
    if (requested instanceof ModuleComponentSelector) {
        ModuleComponentSelector selector = (ModuleComponentSelector) requested;
        ProjectComponentIdentifier replacement = getReplacementFor(selector);
        if (replacement != null) {
            ProjectComponentSelector targetProject = DefaultProjectComponentSelector.newSelector(replacement, ((AttributeContainerInternal) requested.getAttributes()).asImmutable(), requested.getRequestedCapabilities());
            dependencySubstitution.useTarget(targetProject, ComponentSelectionReasons.COMPOSITE_BUILD);
        }
    }
}
Also used : ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) DefaultProjectComponentSelector(org.gradle.internal.component.local.model.DefaultProjectComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) DefaultProjectComponentSelector(org.gradle.internal.component.local.model.DefaultProjectComponentSelector) DependencySubstitutionInternal(org.gradle.api.internal.artifacts.DependencySubstitutionInternal) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Aggregations

DependencySubstitutionInternal (org.gradle.api.internal.artifacts.DependencySubstitutionInternal)4 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)3 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)2 DependencySubstitutionApplicator (org.gradle.api.internal.artifacts.ivyservice.dependencysubstitution.DependencySubstitutionApplicator)2 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)1 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)1 ProjectComponentSelector (org.gradle.api.artifacts.component.ProjectComponentSelector)1 ArtifactSelectionDetailsInternal (org.gradle.api.internal.artifacts.ivyservice.dependencysubstitution.ArtifactSelectionDetailsInternal)1 DefaultProjectComponentSelector (org.gradle.internal.component.local.model.DefaultProjectComponentSelector)1