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