use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class DefaultDependencyResolveDetails method useVersion.
@Override
public void useVersion(VersionConstraint version, ComponentSelectionDescriptorInternal selectionReason) {
assert selectionReason != null;
if (version == null) {
throw new IllegalArgumentException("Configuring the dependency resolve details with 'null' version is not allowed.");
}
useSelector = null;
useVersion = version;
if (delegate.getTarget() instanceof ModuleComponentSelector) {
ModuleComponentSelector target = (ModuleComponentSelector) delegate.getTarget();
if (!version.equals(target.getVersionConstraint())) {
delegate.useTarget(DefaultModuleComponentSelector.newSelector(target.getGroup(), target.getModule(), version), selectionReason);
} else {
// Still 'updated' with reason when version remains the same.
delegate.useTarget(delegate.getTarget(), selectionReason);
}
} else {
// If the current target is a project component, it must be unmodified from the requested
ModuleComponentSelector newTarget = DefaultModuleComponentSelector.newSelector(requested.getGroup(), requested.getName(), version);
delegate.useTarget(newTarget, selectionReason);
}
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class ExternalModuleDependencyDescriptorFactoryTest method testAddWithNullGroupAndNullVersionShouldHaveEmptyStringModuleRevisionValues.
@Test
public void testAddWithNullGroupAndNullVersionShouldHaveEmptyStringModuleRevisionValues() {
ModuleDependency dependency = new DefaultExternalModuleDependency(null, "gradle-core", null, TEST_DEP_CONF);
LocalOriginDependencyMetadata dependencyMetaData = externalModuleDependencyDescriptorFactory.createDependencyDescriptor(componentId, TEST_CONF, null, dependency);
ModuleComponentSelector selector = (ModuleComponentSelector) dependencyMetaData.getSelector();
assertThat(selector.getGroup(), equalTo(""));
assertThat(selector.getModule(), equalTo("gradle-core"));
assertThat(selector.getVersion(), equalTo(""));
assertThat(selector.getVersionConstraint().getPreferredVersion(), equalTo(""));
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class IncompatibleDependencyAttributesMessageBuilder method formatAttributeQuery.
private static String formatAttributeQuery(SelectorState state, Attribute<?> attribute) {
DependencyMetadata dependencyMetadata = state.getDependencyMetadata();
ComponentSelector selector = dependencyMetadata.getSelector();
if (selector instanceof ModuleComponentSelector) {
StringBuilder sb = new StringBuilder("wants '" + state.getRequested() + "' with attribute " + attribute.getName() + " = ");
sb.append(selector.getAttributes().getAttribute(attribute));
return sb.toString();
} else {
// that for a specific module resolve state, all selectors are of the same type
return "doesn't provide any value for attribute " + attribute.getName();
}
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector in project gradle by gradle.
the class DefaultIvyModulePublishMetadata method normalizeVersionForIvy.
/**
* [1.0] is a valid version in maven, but not in Ivy: strip the surrounding '[' and ']' characters for ivy publish.
*/
private static LocalOriginDependencyMetadata normalizeVersionForIvy(LocalOriginDependencyMetadata dependency) {
if (dependency.getSelector() instanceof ModuleComponentSelector) {
ModuleComponentSelector selector = (ModuleComponentSelector) dependency.getSelector();
VersionConstraint versionConstraint = selector.getVersionConstraint();
DefaultImmutableVersionConstraint transformedConstraint = new DefaultImmutableVersionConstraint(VERSION_TRANSFORMER.transform(versionConstraint.getPreferredVersion()), VERSION_TRANSFORMER.transform(versionConstraint.getRequiredVersion()), VERSION_TRANSFORMER.transform(versionConstraint.getStrictVersion()), CollectionUtils.collect(versionConstraint.getRejectedVersions(), VERSION_TRANSFORMER), versionConstraint.getBranch());
ModuleComponentSelector newSelector = DefaultModuleComponentSelector.newSelector(selector.getModuleIdentifier(), transformedConstraint, selector.getAttributes(), selector.getRequestedCapabilities());
return dependency.withTarget(newSelector);
}
return dependency;
}
use of org.gradle.api.artifacts.component.ModuleComponentSelector 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);
}
}
Aggregations