Search in sources :

Example 6 with ResolutionResult

use of org.gradle.api.artifacts.result.ResolutionResult 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 7 with ResolutionResult

use of org.gradle.api.artifacts.result.ResolutionResult in project gradle by gradle.

the class JsonProjectDependencyRenderer method createInsight.

private List<Object> createInsight(ModuleIdentifier module, final Configuration configuration) {
    final Spec<DependencyResult> dependencySpec = new StrictDependencyResultSpec(module);
    ResolutionResult result = configuration.getIncoming().getResolutionResult();
    final Set<DependencyResult> selectedDependencies = new LinkedHashSet<>();
    result.allDependencies(it -> {
        if (dependencySpec.isSatisfiedBy(it)) {
            selectedDependencies.add(it);
        }
    });
    Collection<RenderableDependency> sortedDeps = new DependencyInsightReporter(versionSelectorScheme, versionComparator, versionParser).convertToRenderableItems(selectedDependencies, false);
    return CollectionUtils.collect(sortedDeps, dependency -> {
        String name = replaceArrow(dependency.getName());
        LinkedHashMap<String, Object> map = new LinkedHashMap<>(5);
        map.put("name", replaceArrow(dependency.getName()));
        map.put("description", dependency.getDescription());
        map.put("resolvable", dependency.getResolutionState());
        map.put("hasConflict", !name.equals(dependency.getName()));
        map.put("children", createInsightDependencyChildren(dependency, new HashSet<>(), configuration));
        return map;
    });
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RenderableDependency(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) ResolutionResult(org.gradle.api.artifacts.result.ResolutionResult) LinkedHashMap(java.util.LinkedHashMap) DependencyInsightReporter(org.gradle.api.tasks.diagnostics.internal.insight.DependencyInsightReporter) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 8 with ResolutionResult

use of org.gradle.api.artifacts.result.ResolutionResult in project gradle by gradle.

the class JsonProjectDependencyRenderer method collectModules.

private Set<ModuleIdentifier> collectModules(Configuration configuration) {
    RenderableDependency root;
    if (canBeResolved(configuration)) {
        ResolutionResult result = configuration.getIncoming().getResolutionResult();
        root = new RenderableModuleResult(result.getRoot());
    } else {
        root = new UnresolvableConfigurationResult(configuration);
    }
    Set<ModuleIdentifier> modules = Sets.newHashSet();
    Set<ComponentIdentifier> visited = Sets.newHashSet();
    populateModulesWithChildDependencies(root, visited, modules);
    return modules;
}
Also used : RenderableDependency(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency) UnresolvableConfigurationResult(org.gradle.api.tasks.diagnostics.internal.graph.nodes.UnresolvableConfigurationResult) ResolutionResult(org.gradle.api.artifacts.result.ResolutionResult) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) RenderableModuleResult(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableModuleResult)

Example 9 with ResolutionResult

use of org.gradle.api.artifacts.result.ResolutionResult in project gradle by gradle.

the class JsonProjectDependencyRenderer method createDependencies.

private List<Map<String, Object>> createDependencies(Configuration configuration) {
    if (canBeResolved(configuration)) {
        ResolutionResult result = configuration.getIncoming().getResolutionResult();
        RenderableDependency root = new RenderableModuleResult(result.getRoot());
        return createDependencyChildren(root, new HashSet<>());
    } else {
        return createDependencyChildren(new UnresolvableConfigurationResult(configuration), new HashSet<>());
    }
}
Also used : RenderableDependency(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency) UnresolvableConfigurationResult(org.gradle.api.tasks.diagnostics.internal.graph.nodes.UnresolvableConfigurationResult) ResolutionResult(org.gradle.api.artifacts.result.ResolutionResult) RenderableModuleResult(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableModuleResult)

Example 10 with ResolutionResult

use of org.gradle.api.artifacts.result.ResolutionResult in project gradle by gradle.

the class DefaultIdeDependencyResolver method getIdeProjectDependencies.

/**
     * Gets IDE project dependencies.
     *
     * @param configuration Configuration
     * @param project Project
     * @return IDE project dependencies
     */
public List<IdeProjectDependency> getIdeProjectDependencies(Configuration configuration, Project project) {
    ResolutionResult result = getIncomingResolutionResult(configuration);
    final Set<ResolvedComponentResult> projectComponents = CollectionUtils.filter(result.getAllComponents(), new Spec<ResolvedComponentResult>() {

        @Override
        public boolean isSatisfiedBy(ResolvedComponentResult element) {
            return element.getId() instanceof ProjectComponentIdentifier;
        }
    });
    List<IdeProjectDependency> ideProjectDependencies = new ArrayList<IdeProjectDependency>();
    ProjectComponentIdentifier thisProjectId = DefaultProjectComponentIdentifier.newProjectId(project);
    for (ResolvedComponentResult projectComponent : projectComponents) {
        ProjectComponentIdentifier projectId = (ProjectComponentIdentifier) projectComponent.getId();
        if (thisProjectId.equals(projectId)) {
            continue;
        }
        if (!projectId.getBuild().isCurrentBuild()) {
            // Don't have access to the ProjectInstance: we can't use it to determine the name.
            ideProjectDependencies.add(new IdeProjectDependency(projectId));
        } else {
            Project resolvedProject = project.project(projectId.getProjectPath());
            ideProjectDependencies.add(new IdeProjectDependency(projectId, resolvedProject.getName()));
        }
    }
    return ideProjectDependencies;
}
Also used : IdeProjectDependency(org.gradle.plugins.ide.internal.resolver.model.IdeProjectDependency) Project(org.gradle.api.Project) ResolutionResult(org.gradle.api.artifacts.result.ResolutionResult) ArrayList(java.util.ArrayList) ResolvedComponentResult(org.gradle.api.artifacts.result.ResolvedComponentResult) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) DefaultProjectComponentIdentifier(org.gradle.internal.component.local.model.DefaultProjectComponentIdentifier)

Aggregations

ResolutionResult (org.gradle.api.artifacts.result.ResolutionResult)13 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)5 RenderableDependency (org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency)4 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)3 RenderableModuleResult (org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableModuleResult)3 UnresolvableConfigurationResult (org.gradle.api.tasks.diagnostics.internal.graph.nodes.UnresolvableConfigurationResult)3 ArrayList (java.util.ArrayList)2 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)2 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)2 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)2 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)2 Module (org.gradle.api.internal.artifacts.Module)2 ResolvedLocalComponentsResult (org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedLocalComponentsResult)2 ResolvedLocalComponentsResultGraphVisitor (org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedLocalComponentsResultGraphVisitor)2 File (java.io.File)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Incubating (org.gradle.api.Incubating)1 Project (org.gradle.api.Project)1