Search in sources :

Example 11 with ProjectComponentSelector

use of org.gradle.api.artifacts.component.ProjectComponentSelector in project gradle by gradle.

the class DefaultDependencySubstitutions method substitute.

@Override
public Substitution substitute(final ComponentSelector substituted) {
    return new Substitution() {

        Action<? super ArtifactSelectionDetails> artifactAction = Actions.doNothing();

        ComponentSelectionDescriptorInternal substitutionReason = (ComponentSelectionDescriptorInternal) reason;

        @Override
        public Substitution because(String description) {
            substitutionReason = substitutionReason.withDescription(Describables.of(description));
            return this;
        }

        @Override
        public Substitution withClassifier(String classifier) {
            artifactAction = Actions.composite(artifactAction, new SetClassifier(classifier));
            return this;
        }

        @Override
        public Substitution withoutClassifier() {
            artifactAction = Actions.composite(artifactAction, NoClassifier.INSTANCE);
            return this;
        }

        @Override
        public Substitution withoutArtifactSelectors() {
            artifactAction = Actions.composite(artifactAction, NoArtifactSelector.INSTANCE);
            return this;
        }

        @Override
        public Substitution using(ComponentSelector notation) {
            DefaultDependencySubstitution.validateTarget(notation);
            boolean projectInvolved = false;
            if (substituted instanceof ProjectComponentSelector || notation instanceof ProjectComponentSelector) {
                // A project is involved, need to be aware of it
                projectInvolved = true;
            }
            if (substituted instanceof UnversionedModuleComponentSelector) {
                final ModuleIdentifier moduleId = ((UnversionedModuleComponentSelector) substituted).getModuleIdentifier();
                if (notation instanceof ModuleComponentSelector) {
                    if (((ModuleComponentSelector) notation).getModuleIdentifier().equals(moduleId)) {
                        // This substitution is effectively a force
                        substitutionReason = substitutionReason.markAsEquivalentToForce();
                    }
                }
                addSubstitution(new ModuleMatchDependencySubstitutionAction(substitutionReason, moduleId, notation, () -> artifactAction), projectInvolved);
            } else {
                addSubstitution(new ExactMatchDependencySubstitutionAction(substitutionReason, substituted, notation, () -> artifactAction), projectInvolved);
            }
            return this;
        }

        @Override
        @Deprecated
        public void with(ComponentSelector substitute) {
            // Do not nag for 7.1 as this introduces a performance regression with Android plugin
            // Revisit when upgrading Android plugin
            /*DeprecationLogger.deprecateMethod(Substitution.class, "with(ComponentSelector)")
                    .replaceWith("using(ComponentSelector)")
                    .willBeRemovedInGradle8()
                    .withUpgradeGuideSection(7, "dependency_substitutions_with")
                    .nagUser();*/
            using(substitute);
        }
    };
}
Also used : Action(org.gradle.api.Action) ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) DefaultProjectComponentSelector(org.gradle.internal.component.local.model.DefaultProjectComponentSelector) ArtifactSelectionDetails(org.gradle.api.artifacts.ArtifactSelectionDetails) DependencySubstitution(org.gradle.api.artifacts.DependencySubstitution) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) DefaultProjectComponentSelector(org.gradle.internal.component.local.model.DefaultProjectComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) ComponentSelectionDescriptorInternal(org.gradle.api.internal.artifacts.ivyservice.resolveengine.result.ComponentSelectionDescriptorInternal) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 12 with ProjectComponentSelector

use of org.gradle.api.artifacts.component.ProjectComponentSelector in project gradle by gradle.

the class ProjectDependencyResolver method resolve.

@Override
public void resolve(DependencyMetadata dependency, VersionSelector acceptor, @Nullable VersionSelector rejector, BuildableComponentIdResolveResult result) {
    if (dependency.getSelector() instanceof ProjectComponentSelector) {
        ProjectComponentSelector selector = (ProjectComponentSelector) dependency.getSelector();
        ProjectComponentIdentifier projectId = componentIdentifierFactory.createProjectComponentIdentifier(selector);
        LocalComponentMetadata componentMetaData = localComponentRegistry.getComponent(projectId);
        if (componentMetaData == null) {
            result.failed(new ModuleVersionResolveException(selector, () -> projectId + " not found."));
        } else {
            if (rejector != null && rejector.accept(componentMetaData.getModuleVersionId().getVersion())) {
                result.rejected(projectId, componentMetaData.getModuleVersionId());
            } else {
                result.resolved(componentMetaData);
            }
        }
    }
}
Also used : ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) DefaultProjectComponentSelector(org.gradle.internal.component.local.model.DefaultProjectComponentSelector) LocalComponentMetadata(org.gradle.internal.component.local.model.LocalComponentMetadata) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 13 with ProjectComponentSelector

use of org.gradle.api.artifacts.component.ProjectComponentSelector in project gradle by gradle.

the class DependencyResultSpec method matchesRequested.

private boolean matchesRequested(DependencyResult candidate) {
    ComponentSelector requested = candidate.getRequested();
    if (requested instanceof ModuleComponentSelector) {
        ModuleComponentSelector requestedModule = (ModuleComponentSelector) requested;
        String requestedCandidate = requestedModule.getGroup() + ":" + requestedModule.getModule() + ":" + requestedModule.getVersion();
        return requestedCandidate.contains(stringNotation);
    }
    if (requested instanceof ProjectComponentSelector) {
        ProjectComponentSelector project = (ProjectComponentSelector) requested;
        String requestedCandidate = project.getProjectPath();
        return requestedCandidate.contains(stringNotation);
    }
    return false;
}
Also used : ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector)

Example 14 with ProjectComponentSelector

use of org.gradle.api.artifacts.component.ProjectComponentSelector 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

ProjectComponentSelector (org.gradle.api.artifacts.component.ProjectComponentSelector)14 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)9 DefaultProjectComponentSelector (org.gradle.internal.component.local.model.DefaultProjectComponentSelector)7 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)6 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)5 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)4 LocalComponentMetadata (org.gradle.internal.component.local.model.LocalComponentMetadata)4 DefaultModuleComponentSelector (org.gradle.internal.component.external.model.DefaultModuleComponentSelector)3 DefaultProjectDependencyMetadata (org.gradle.internal.component.local.model.DefaultProjectDependencyMetadata)3 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)2 ModuleVersionSelector (org.gradle.api.artifacts.ModuleVersionSelector)2 BuildIdentifier (org.gradle.api.artifacts.component.BuildIdentifier)2 DefaultModuleVersionSelector (org.gradle.api.internal.artifacts.DefaultModuleVersionSelector)2 Action (org.gradle.api.Action)1 ArtifactSelectionDetails (org.gradle.api.artifacts.ArtifactSelectionDetails)1 DependencySubstitution (org.gradle.api.artifacts.DependencySubstitution)1 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)1 LibraryComponentSelector (org.gradle.api.artifacts.component.LibraryComponentSelector)1 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)1 ResolutionResult (org.gradle.api.artifacts.result.ResolutionResult)1