Search in sources :

Example 6 with ModuleComponentSelector

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);
    }
}
Also used : DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector)

Example 7 with ModuleComponentSelector

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(""));
}
Also used : ExternalModuleDependency(org.gradle.api.artifacts.ExternalModuleDependency) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) LocalOriginDependencyMetadata(org.gradle.internal.component.model.LocalOriginDependencyMetadata) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) Test(org.junit.Test)

Example 8 with ModuleComponentSelector

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();
    }
}
Also used : ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DependencyMetadata(org.gradle.internal.component.model.DependencyMetadata)

Example 9 with ModuleComponentSelector

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;
}
Also used : VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector)

Example 10 with ModuleComponentSelector

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);
    }
}
Also used : DefaultProjectDependencyMetadata(org.gradle.internal.component.local.model.DefaultProjectDependencyMetadata) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector)

Aggregations

ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)46 DefaultModuleComponentSelector (org.gradle.internal.component.external.model.DefaultModuleComponentSelector)21 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)10 ProjectComponentSelector (org.gradle.api.artifacts.component.ProjectComponentSelector)9 DefaultImmutableVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)8 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)7 ExcludeMetadata (org.gradle.internal.component.model.ExcludeMetadata)6 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)5 ModuleVersionSelector (org.gradle.api.artifacts.ModuleVersionSelector)5 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)5 IvyArtifactName (org.gradle.internal.component.model.IvyArtifactName)5 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)5 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)4 DefaultModuleVersionSelector (org.gradle.api.internal.artifacts.DefaultModuleVersionSelector)4 DefaultExclude (org.gradle.internal.component.external.descriptor.DefaultExclude)4 DefaultProjectComponentSelector (org.gradle.internal.component.local.model.DefaultProjectComponentSelector)4 ArrayList (java.util.ArrayList)3 ExternalModuleDependency (org.gradle.api.artifacts.ExternalModuleDependency)3 VersionConstraint (org.gradle.api.artifacts.VersionConstraint)3 MavenScope (org.gradle.internal.component.external.descriptor.MavenScope)3