Search in sources :

Example 36 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class ModuleMetadataFileGenerator method collectCoordinates.

private void collectCoordinates(Collection<? extends PublicationInternal> publications, Map<SoftwareComponent, ComponentData> coordinates) {
    for (PublicationInternal publication : publications) {
        if (publication.getComponent() != null) {
            ModuleVersionIdentifier moduleVersionIdentifier = publication.getCoordinates();
            ImmutableAttributes attributes = publication.getAttributes();
            coordinates.put(publication.getComponent(), new ComponentData(moduleVersionIdentifier, attributes));
        }
    }
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes)

Example 37 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class DefaultVersionMappingStrategy method createDefaultMappingStrategy.

private DefaultVariantVersionMappingStrategy createDefaultMappingStrategy(ImmutableAttributes variantAttributes) {
    DefaultVariantVersionMappingStrategy strategy = new DefaultVariantVersionMappingStrategy(configurations, projectResolver, projectRegistry);
    if (!defaultConfigurations.isEmpty()) {
        // First need to populate the default variant version mapping strategy with the default values
        // provided by plugins
        AttributeMatcher matcher = schema.matcher();
        Set<ImmutableAttributes> candidates = defaultConfigurations.keySet();
        List<ImmutableAttributes> matches = matcher.matches(candidates, variantAttributes, AttributeMatchingExplanationBuilder.NO_OP);
        for (ImmutableAttributes match : matches) {
            strategy.setTargetConfiguration(configurations.getByName(defaultConfigurations.get(match)));
        }
    }
    return strategy;
}
Also used : AttributeMatcher(org.gradle.internal.component.model.AttributeMatcher) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) DefaultVariantVersionMappingStrategy(org.gradle.api.publish.internal.versionmapping.DefaultVariantVersionMappingStrategy)

Example 38 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class MavenPomFileGenerator method addDependencyManagement.

private void addDependencyManagement(MavenDependencyInternal dependency, String scope) {
    Dependency mavenDependency = new Dependency();
    String groupId = dependency.getGroupId();
    String artifactId = dependency.getArtifactId();
    String projectPath = dependency.getProjectPath();
    ImmutableAttributes attributes = attributesForScope(scope);
    ModuleVersionIdentifier resolvedVersion = versionMappingStrategy.findStrategyForVariant(attributes).maybeResolveVersion(groupId, artifactId, projectPath);
    mavenDependency.setGroupId(resolvedVersion != null ? resolvedVersion.getGroup() : groupId);
    mavenDependency.setArtifactId(resolvedVersion != null ? resolvedVersion.getName() : artifactId);
    mavenDependency.setVersion(resolvedVersion == null ? mapToMavenSyntax(dependency.getVersion()) : resolvedVersion.getVersion());
    String type = dependency.getType();
    if (type != null) {
        mavenDependency.setType(type);
    }
    // Only publish the import scope, others have too different meanings than what Gradle expresses
    if ("import".equals(scope)) {
        mavenDependency.setScope(scope);
    }
    DependencyManagement dependencyManagement = model.getDependencyManagement();
    if (dependencyManagement == null) {
        dependencyManagement = new DependencyManagement();
        model.setDependencyManagement(dependencyManagement);
    }
    dependencyManagement.addDependency(mavenDependency);
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) MavenDependency(org.gradle.api.publish.maven.MavenDependency) Dependency(org.apache.maven.model.Dependency) DependencyManagement(org.apache.maven.model.DependencyManagement)

Example 39 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class DefaultVersionMappingStrategy method createDefaultMappingStrategy.

private DefaultVariantVersionMappingStrategy createDefaultMappingStrategy(ImmutableAttributes variantAttributes) {
    DefaultVariantVersionMappingStrategy strategy = new DefaultVariantVersionMappingStrategy(configurations, projectResolver, projectRegistry);
    if (!defaultConfigurations.isEmpty()) {
        // First need to populate the default variant version mapping strategy with the default values
        // provided by plugins
        AttributeMatcher matcher = schema.matcher();
        Set<ImmutableAttributes> candidates = defaultConfigurations.keySet();
        List<ImmutableAttributes> matches = matcher.matches(candidates, variantAttributes, AttributeMatchingExplanationBuilder.NO_OP);
        for (ImmutableAttributes match : matches) {
            strategy.setTargetConfiguration(configurations.getByName(defaultConfigurations.get(match)));
        }
    }
    return strategy;
}
Also used : AttributeMatcher(org.gradle.internal.component.model.AttributeMatcher) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes)

Example 40 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class DefaultConfiguration method artifactCollection.

private ConfigurationArtifactCollection artifactCollection(AttributeContainerInternal attributes, Spec<? super ComponentIdentifier> componentFilter, boolean lenient, boolean allowNoMatchingVariants) {
    ImmutableAttributes viewAttributes = attributes.asImmutable();
    DefaultResolutionHost failureHandler = new DefaultResolutionHost();
    ConfigurationFileCollection files = new ConfigurationFileCollection(new SelectedArtifactsProvider(), Specs.satisfyAll(), viewAttributes, componentFilter, lenient, allowNoMatchingVariants, failureHandler);
    return new ConfigurationArtifactCollection(files, lenient, failureHandler, calculatedValueContainerFactory);
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes)

Aggregations

ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)63 CoercingStringValueSnapshot (org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot)9 AttributeContainerInternal (org.gradle.api.internal.attributes.AttributeContainerInternal)8 ArrayList (java.util.ArrayList)7 Attribute (org.gradle.api.attributes.Attribute)7 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)7 ImmutableCapabilities (org.gradle.internal.component.external.model.ImmutableCapabilities)6 AttributeMatcher (org.gradle.internal.component.model.AttributeMatcher)6 ImmutableList (com.google.common.collect.ImmutableList)5 File (java.io.File)5 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)4 CapabilitiesMetadata (org.gradle.api.capabilities.CapabilitiesMetadata)4 ExcludeMetadata (org.gradle.internal.component.model.ExcludeMetadata)4 List (java.util.List)3 VersionConstraint (org.gradle.api.artifacts.VersionConstraint)3 DefaultImmutableVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)3 ModuleDependencyMetadata (org.gradle.internal.component.external.model.ModuleDependencyMetadata)3 MutableComponentVariant (org.gradle.internal.component.external.model.MutableComponentVariant)3 RealisedConfigurationMetadata (org.gradle.internal.component.external.model.RealisedConfigurationMetadata)3 VariantResolveMetadata (org.gradle.internal.component.model.VariantResolveMetadata)3