use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class RepositoryChainDependencyToComponentIdResolver method resolve.
public void resolve(DependencyMetadata dependency, ResolvedVersionConstraint resolvedVersionConstraint, BuildableComponentIdResolveResult result) {
ComponentSelector componentSelector = dependency.getSelector();
if (componentSelector instanceof ModuleComponentSelector) {
ModuleComponentSelector module = (ModuleComponentSelector) componentSelector;
if (resolvedVersionConstraint == null) {
// TODO:DAZ This shouldn't be required, but `ExternalResourceResolverDescriptorParseContext` does not provide a resolved constraint
VersionConstraint raw = module.getVersionConstraint();
resolvedVersionConstraint = new DefaultResolvedVersionConstraint(raw, versionSelectorScheme);
}
VersionSelector preferredSelector = resolvedVersionConstraint.getPreferredSelector();
if (preferredSelector.isDynamic()) {
dynamicRevisionResolver.resolve(toModuleDependencyMetadata(dependency), preferredSelector, resolvedVersionConstraint.getRejectedSelector(), result);
} else {
String version = resolvedVersionConstraint.getPreferredVersion();
ModuleComponentIdentifier id = new DefaultModuleComponentIdentifier(module.getGroup(), module.getModule(), version);
ModuleVersionIdentifier mvId = moduleIdentifierFactory.moduleWithVersion(module.getGroup(), module.getModule(), version);
result.resolved(id, mvId);
}
}
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class VcsDependencyResolver method resolve.
@Override
public void resolve(DependencyMetadata dependency, ResolvedVersionConstraint versionConstraint, 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) {
VersionControlSystem versionControlSystem = versionControlSystemFactory.create(spec);
VersionRef selectedVersion = selectVersion(depSelector, spec, versionControlSystem);
if (selectedVersion == null) {
result.failed(new ModuleVersionNotFoundException(depSelector, Collections.singleton(spec.getDisplayName())));
return;
}
File dependencyWorkingDir = new File(populateWorkingDirectory(baseWorkingDir, spec, versionControlSystem, selectedVersion), spec.getRootDir());
// TODO: This shouldn't rely on the service registry to find NestedBuildFactory
IncludedBuildRegistry includedBuildRegistry = serviceRegistry.get(IncludedBuildRegistry.class);
NestedBuildFactory nestedBuildFactory = serviceRegistry.get(NestedBuildFactory.class);
IncludedBuildInternal includedBuild = includedBuildRegistry.addImplicitBuild(((AbstractVersionControlSpec) spec).getBuildDefinition(dependencyWorkingDir), nestedBuildFactory);
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);
if (componentMetaData == null) {
result.failed(new ModuleVersionResolveException(DefaultProjectComponentSelector.newSelector(includedBuild.getModel(), entry.right.getProjectPath()), spec.getDisplayName() + " could not be resolved into a usable project."));
} else {
result.resolved(componentMetaData);
}
return;
}
}
}
projectDependencyResolver.resolve(dependency, versionConstraint, result);
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class ExternalModuleDependencyDescriptorFactoryTest method testCreateFromModuleDependency.
@Test
public void testCreateFromModuleDependency() {
DefaultExternalModuleDependency moduleDependency = new DefaultExternalModuleDependency("org.gradle", "gradle-core", "1.0", TEST_DEP_CONF);
setUpDependency(moduleDependency);
LocalOriginDependencyMetadata dependencyMetaData = externalModuleDependencyDescriptorFactory.createDependencyDescriptor(componentId, TEST_CONF, null, moduleDependency);
ModuleComponentSelector selector = (ModuleComponentSelector) dependencyMetaData.getSelector();
assertEquals(moduleDependency.isChanging(), dependencyMetaData.isChanging());
assertEquals(moduleDependency.isForce(), dependencyMetaData.isForce());
assertEquals(moduleDependency.getGroup(), moduleDependency.getGroup());
assertEquals(moduleDependency.getName(), moduleDependency.getName());
assertEquals(moduleDependency.getVersion(), moduleDependency.getVersion());
assertEquals(moduleDependency.getGroup(), selector.getGroup());
assertEquals(moduleDependency.getName(), selector.getModule());
assertEquals(moduleDependency.getVersion(), selector.getVersion());
assertEquals(((VersionConstraintInternal) moduleDependency.getVersionConstraint()).asImmutable(), selector.getVersionConstraint());
assertDependencyDescriptorHasCommonFixtureValues(dependencyMetaData);
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class DefaultDependencySubstitutions method substitute.
@Override
public Substitution substitute(final ComponentSelector substituted) {
return new Substitution() {
Action<? super ArtifactSelectionDetails> artifactAction = Actions.doNothing();
ComponentSelectionDescriptorInternal substitutionReason = (ComponentSelectionDescriptorInternal) reason;
@Override
public Substitution because(String description) {
substitutionReason = substitutionReason.withDescription(Describables.of(description));
return this;
}
@Override
public Substitution withClassifier(String classifier) {
artifactAction = Actions.composite(artifactAction, new SetClassifier(classifier));
return this;
}
@Override
public Substitution withoutClassifier() {
artifactAction = Actions.composite(artifactAction, NoClassifier.INSTANCE);
return this;
}
@Override
public Substitution withoutArtifactSelectors() {
artifactAction = Actions.composite(artifactAction, NoArtifactSelector.INSTANCE);
return this;
}
@Override
public Substitution using(ComponentSelector notation) {
DefaultDependencySubstitution.validateTarget(notation);
boolean projectInvolved = false;
if (substituted instanceof ProjectComponentSelector || notation instanceof ProjectComponentSelector) {
// A project is involved, need to be aware of it
projectInvolved = true;
}
if (substituted instanceof UnversionedModuleComponentSelector) {
final ModuleIdentifier moduleId = ((UnversionedModuleComponentSelector) substituted).getModuleIdentifier();
if (notation instanceof ModuleComponentSelector) {
if (((ModuleComponentSelector) notation).getModuleIdentifier().equals(moduleId)) {
// This substitution is effectively a force
substitutionReason = substitutionReason.markAsEquivalentToForce();
}
}
addSubstitution(new ModuleMatchDependencySubstitutionAction(substitutionReason, moduleId, notation, () -> artifactAction), projectInvolved);
} else {
addSubstitution(new ExactMatchDependencySubstitutionAction(substitutionReason, substituted, notation, () -> artifactAction), projectInvolved);
}
return this;
}
@Override
@Deprecated
public void with(ComponentSelector substitute) {
// Do not nag for 7.1 as this introduces a performance regression with Android plugin
// Revisit when upgrading Android plugin
/*DeprecationLogger.deprecateMethod(Substitution.class, "with(ComponentSelector)")
.replaceWith("using(ComponentSelector)")
.willBeRemovedInGradle8()
.withUpgradeGuideSection(7, "dependency_substitutions_with")
.nagUser();*/
using(substitute);
}
};
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class GradlePomModuleDescriptorParser method doParsePom.
private void doParsePom(DescriptorParseContext parserSettings, GradlePomModuleDescriptorBuilder mdBuilder, PomReader pomReader) throws IOException, SAXException {
pomReader.resolveGAV();
String groupId = pomReader.getGroupId();
String artifactId = pomReader.getArtifactId();
String version = pomReader.getVersion();
if (pomReader.hasParent()) {
// Is there any other parent properties?
String parentGroupId = pomReader.getParentGroupId();
String parentArtifactId = pomReader.getParentArtifactId();
String parentVersion = pomReader.getParentVersion();
if (!(Objects.equals(parentGroupId, groupId) && Objects.equals(parentArtifactId, artifactId) && Objects.equals(parentVersion, version))) {
// Only attempt loading the parent if it has different coordinates
ModuleComponentSelector parentId = DefaultModuleComponentSelector.newSelector(DefaultModuleIdentifier.newId(parentGroupId, parentArtifactId), new DefaultImmutableVersionConstraint(parentVersion));
PomReader parentPomReader = parsePomForSelector(parserSettings, parentId, pomReader.getAllPomProperties());
pomReader.setPomParent(parentPomReader);
// Current POM can derive version/artifactId from parent. Resolve GAV and substitute values
pomReader.resolveGAV();
groupId = pomReader.getGroupId();
artifactId = pomReader.getArtifactId();
version = pomReader.getVersion();
}
}
mdBuilder.setModuleRevId(groupId, artifactId, version);
ModuleVersionIdentifier relocation = pomReader.getRelocation();
if (relocation != null) {
if (groupId != null && artifactId != null && artifactId.equals(relocation.getName()) && groupId.equals(relocation.getGroup())) {
LOGGER.error("POM relocation to an other version number is not fully supported in Gradle : {} relocated to {}.", mdBuilder.getComponentIdentifier(), relocation);
LOGGER.warn("Please update your dependency to directly use the correct version '{}'.", relocation);
LOGGER.warn("Resolution will only pick dependencies of the relocated element. Artifacts and other metadata will be ignored.");
PomReader relocatedModule = parsePomForId(parserSettings, DefaultModuleComponentIdentifier.newId(relocation), Maps.newHashMap());
addDependencies(mdBuilder, relocatedModule);
} else {
LOGGER.info(mdBuilder.getComponentIdentifier() + " is relocated to " + relocation + ". Please update your dependencies.");
LOGGER.debug("Relocated module will be considered as a dependency");
ModuleComponentSelector selector = DefaultModuleComponentSelector.newSelector(DefaultModuleIdentifier.newId(relocation.getGroup(), relocation.getName()), new DefaultMutableVersionConstraint(relocation.getVersion()));
mdBuilder.addDependencyForRelocation(selector);
}
} else {
overrideDependencyMgtsWithImported(parserSettings, pomReader);
addDependencies(mdBuilder, pomReader);
}
}
Aggregations