Search in sources :

Example 6 with ProjectComponentSelector

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

the class ConfigurationBoundExternalDependencyMetadata method withTargetAndArtifacts.

@Override
public DependencyMetadata withTargetAndArtifacts(ComponentSelector target, List<IvyArtifactName> artifacts) {
    if (target instanceof ModuleComponentSelector) {
        ModuleComponentSelector moduleTarget = (ModuleComponentSelector) target;
        ModuleComponentSelector newSelector = DefaultModuleComponentSelector.newSelector(moduleTarget.getModuleIdentifier(), moduleTarget.getVersionConstraint(), moduleTarget.getAttributes(), moduleTarget.getRequestedCapabilities());
        if (newSelector.equals(getSelector()) && getArtifacts().equals(artifacts)) {
            return this;
        }
        return withRequestedAndArtifacts(newSelector, artifacts);
    } else if (target instanceof ProjectComponentSelector) {
        ProjectComponentSelector projectTarget = (ProjectComponentSelector) target;
        return new DefaultProjectDependencyMetadata(projectTarget, this);
    } else {
        throw new IllegalArgumentException("Unexpected selector provided: " + target);
    }
}
Also used : DefaultProjectDependencyMetadata(org.gradle.internal.component.local.model.DefaultProjectDependencyMetadata) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector)

Example 7 with ProjectComponentSelector

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

the class ConfigurationBoundExternalDependencyMetadata method withTarget.

@Override
public DependencyMetadata withTarget(ComponentSelector target) {
    if (target instanceof ModuleComponentSelector) {
        ModuleComponentSelector moduleTarget = (ModuleComponentSelector) target;
        ModuleComponentSelector newSelector = DefaultModuleComponentSelector.newSelector(moduleTarget.getModuleIdentifier(), moduleTarget.getVersionConstraint(), moduleTarget.getAttributes(), moduleTarget.getRequestedCapabilities());
        if (newSelector.equals(getSelector())) {
            return this;
        }
        return withRequested(newSelector);
    } else if (target instanceof ProjectComponentSelector) {
        ProjectComponentSelector projectTarget = (ProjectComponentSelector) target;
        return new DefaultProjectDependencyMetadata(projectTarget, this);
    } else {
        throw new IllegalArgumentException("Unexpected selector provided: " + target);
    }
}
Also used : DefaultProjectDependencyMetadata(org.gradle.internal.component.local.model.DefaultProjectDependencyMetadata) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector)

Example 8 with ProjectComponentSelector

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

the class DefaultComponentSelectorConverter method getSelector.

@Override
public ModuleVersionSelector getSelector(ComponentSelector selector) {
    if (selector instanceof ModuleComponentSelector) {
        return DefaultModuleVersionSelector.newSelector((ModuleComponentSelector) selector);
    }
    if (selector instanceof ProjectComponentSelector) {
        ProjectComponentSelector projectSelector = (ProjectComponentSelector) selector;
        ProjectComponentIdentifier projectId = componentIdentifierFactory.createProjectComponentIdentifier(projectSelector);
        LocalComponentMetadata projectComponent = localComponentRegistry.getComponent(projectId);
        if (projectComponent != null) {
            ModuleVersionIdentifier moduleVersionId = projectComponent.getModuleVersionId();
            return DefaultModuleVersionSelector.newSelector(moduleVersionId.getModule(), moduleVersionId.getVersion());
        }
    }
    if (selector instanceof LibraryComponentSelector) {
        LibraryComponentSelector libraryComponentSelector = (LibraryComponentSelector) selector;
        String libraryName = GUtil.elvis(libraryComponentSelector.getLibraryName(), "");
        return DefaultModuleVersionSelector.newSelector(DefaultModuleIdentifier.newId(libraryComponentSelector.getProjectPath(), libraryName), "undefined");
    }
    return UNKNOWN_MODULE_VERSION_SELECTOR;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) LocalComponentMetadata(org.gradle.internal.component.local.model.LocalComponentMetadata) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) LibraryComponentSelector(org.gradle.api.artifacts.component.LibraryComponentSelector)

Example 9 with ProjectComponentSelector

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

the class DefaultVariantVersionMappingStrategy method maybeResolveVersion.

@Override
public ModuleVersionIdentifier maybeResolveVersion(String group, String module, String projectPath) {
    if (usePublishedVersions && targetConfiguration != null) {
        ResolutionResult resolutionResult = targetConfiguration.getIncoming().getResolutionResult();
        Set<? extends ResolvedComponentResult> resolvedComponentResults = resolutionResult.getAllComponents();
        for (ResolvedComponentResult selected : resolvedComponentResults) {
            ModuleVersionIdentifier moduleVersion = selected.getModuleVersion();
            if (moduleVersion != null && group.equals(moduleVersion.getGroup()) && module.equals(moduleVersion.getName())) {
                return moduleVersion;
            }
        }
        // If we reach this point it means we have a dependency which doesn't belong to the resolution result
        // Which can mean two things:
        // 1. the graph used to get the resolved version has nothing to do with the dependencies we're trying to get versions for (likely user error)
        // 2. the graph contains first-level dependencies which have been substituted (likely) so we're going to iterate on dependencies instead
        Set<? extends DependencyResult> allDependencies = resolutionResult.getAllDependencies();
        for (DependencyResult dependencyResult : allDependencies) {
            if (dependencyResult instanceof ResolvedDependencyResult) {
                ComponentSelector rcs = dependencyResult.getRequested();
                ResolvedComponentResult selected = null;
                if (rcs instanceof ModuleComponentSelector) {
                    ModuleComponentSelector requested = (ModuleComponentSelector) rcs;
                    if (requested.getGroup().equals(group) && requested.getModule().equals(module)) {
                        selected = ((ResolvedDependencyResult) dependencyResult).getSelected();
                    }
                } else if (rcs instanceof ProjectComponentSelector) {
                    ProjectComponentSelector pcs = (ProjectComponentSelector) rcs;
                    if (pcs.getProjectPath().equals(projectPath)) {
                        selected = ((ResolvedDependencyResult) dependencyResult).getSelected();
                    }
                }
                // Match found - need to make sure that if the selection is a project, we use its publication identity
                if (selected != null) {
                    if (selected.getId() instanceof ProjectComponentIdentifier) {
                        ProjectComponentIdentifier projectId = (ProjectComponentIdentifier) selected.getId();
                        return projectResolver.resolve(ModuleVersionIdentifier.class, projectRegistry.getProject(projectId.getProjectPath()));
                    }
                    return selected.getModuleVersion();
                }
            }
        }
    }
    return null;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) ResolutionResult(org.gradle.api.artifacts.result.ResolutionResult) ResolvedComponentResult(org.gradle.api.artifacts.result.ResolvedComponentResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 10 with ProjectComponentSelector

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

the class DefaultIncludedBuildTaskGraph method checkNoCycles.

private void checkNoCycles(BuildIdentifier sourceBuild, BuildIdentifier targetBuild, List<BuildIdentifier> candidateCycle) {
    candidateCycle.add(targetBuild);
    for (BuildIdentifier nextTarget : buildDependencies.get(targetBuild)) {
        if (sourceBuild.equals(nextTarget)) {
            candidateCycle.add(nextTarget);
            ProjectComponentSelector selector = DefaultProjectComponentSelector.newSelector(candidateCycle.get(0), Path.ROOT.getPath());
            throw new ModuleVersionResolveException(selector, "Included build dependency cycle: " + reportCycle(candidateCycle));
        }
        checkNoCycles(sourceBuild, nextTarget, candidateCycle);
    }
    candidateCycle.remove(targetBuild);
}
Also used : DefaultProjectComponentSelector(org.gradle.internal.component.local.model.DefaultProjectComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) BuildIdentifier(org.gradle.api.artifacts.component.BuildIdentifier) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException)

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