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;
}
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;
});
}
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;
}
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<>());
}
}
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;
}
Aggregations