use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class ModuleForcingResolveRule method execute.
@Override
public void execute(DependencySubstitutionInternal details) {
if (forcedModules == null) {
return;
}
if (details.getRequested() instanceof ModuleComponentSelector) {
ModuleComponentSelector selector = (ModuleComponentSelector) details.getRequested();
ModuleIdentifier key = selector.getModuleIdentifier();
if (forcedModules.containsKey(key)) {
DefaultImmutableVersionConstraint versionConstraint = new DefaultImmutableVersionConstraint(forcedModules.get(key));
details.useTarget(newSelector(key, versionConstraint, selector.getAttributes(), selector.getRequestedCapabilities()), ComponentSelectionReasons.FORCED);
}
}
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector 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.component.ModuleComponentSelector in project gradle by gradle.
the class AbstractRenderableDependencyResult method getName.
@Override
public String getName() {
ComponentSelector requested = getRequested();
ComponentIdentifier selected = getActual();
if (exactMatch(requested, selected)) {
return getSimpleName();
}
if (requested instanceof ModuleComponentSelector && selected instanceof ModuleComponentIdentifier) {
ModuleComponentSelector requestedModuleComponentSelector = (ModuleComponentSelector) requested;
ModuleComponentIdentifier selectedModuleComponentedIdentifier = (ModuleComponentIdentifier) selected;
if (requestedModuleComponentSelector.getModuleIdentifier().equals(selectedModuleComponentedIdentifier.getModuleIdentifier())) {
return getSimpleName() + " -> " + selectedModuleComponentedIdentifier.getVersion();
}
}
return getSimpleName() + " -> " + selected.getDisplayName();
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class VcsDependencyResolver method resolve.
@Override
public void resolve(DependencyMetadata dependency, VersionSelector acceptor, VersionSelector rejector, BuildableComponentIdResolveResult result) {
if (dependency.getSelector() instanceof ModuleComponentSelector) {
final ModuleComponentSelector depSelector = (ModuleComponentSelector) dependency.getSelector();
VersionControlSpec spec = vcsResolver.locateVcsFor(depSelector);
// TODO: Need failure handling, e.g., cannot clone repository
if (spec != null) {
VersionControlRepositoryConnection repository = versionControlSystemFactory.create(spec);
File dependencyWorkingDir;
try {
dependencyWorkingDir = workingDirResolver.selectVersion(depSelector, repository);
} catch (ModuleVersionResolveException e) {
result.failed(e);
return;
}
if (dependencyWorkingDir == null) {
result.failed(new ModuleVersionNotFoundException(depSelector, Collections.singleton(spec.getDisplayName())));
return;
}
File buildRootDir = new File(dependencyWorkingDir, spec.getRootDir());
BuildDefinition buildDefinition = toBuildDefinition((AbstractVersionControlSpec) spec, buildRootDir);
IncludedBuildState includedBuild = buildRegistry.addImplicitIncludedBuild(buildDefinition);
Collection<Pair<ModuleVersionIdentifier, ProjectComponentIdentifier>> moduleToProject = includedBuild.getAvailableModules();
Pair<ModuleVersionIdentifier, ProjectComponentIdentifier> entry = CollectionUtils.findFirst(moduleToProject, new Spec<Pair<ModuleVersionIdentifier, ProjectComponentIdentifier>>() {
@Override
public boolean isSatisfiedBy(Pair<ModuleVersionIdentifier, ProjectComponentIdentifier> entry) {
ModuleVersionIdentifier possibleMatch = entry.left;
return depSelector.getGroup().equals(possibleMatch.getGroup()) && depSelector.getModule().equals(possibleMatch.getName());
}
});
if (entry == null) {
result.failed(new ModuleVersionResolveException(depSelector, () -> spec.getDisplayName() + " did not contain a project publishing the specified dependency."));
} else {
LocalComponentMetadata componentMetaData = localComponentRegistry.getComponent(entry.right);
result.resolved(componentMetaData);
}
}
}
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class DefaultLibraryLocalComponentMetadata method moduleDependencyMetadata.
private LocalOriginDependencyMetadata moduleDependencyMetadata(ModuleDependencySpec moduleDependency, String usageConfigurationName) {
ModuleVersionSelector requested = moduleVersionSelectorFrom(moduleDependency);
ModuleComponentSelector selector = DefaultModuleComponentSelector.newSelector(requested);
// Instead, we should be creating an API configuration for each resolved module
return dependencyMetadataFor(selector, requested, usageConfigurationName, CONFIGURATION_COMPILE);
}
Aggregations