Search in sources :

Example 11 with ImmutableAttributes

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

the class RealisedMavenModuleResolveMetadataSerializationHelper method readDerivedVariant.

private ConfigurationMetadata readDerivedVariant(Decoder decoder, DefaultMavenModuleResolveMetadata resolveMetadata, Map<Integer, MavenDependencyDescriptor> deduplicationDependencyCache) throws IOException {
    String name = decoder.readString();
    ImmutableAttributes attributes = attributeContainerSerializer.read(decoder);
    ImmutableCapabilities immutableCapabilities = readCapabilities(decoder);
    boolean isExternalVariant = decoder.readBoolean();
    ImmutableList<? extends ModuleComponentArtifactMetadata> artifacts = readFiles(decoder, resolveMetadata.getId());
    boolean transitive = decoder.readBoolean();
    boolean visible = decoder.readBoolean();
    ImmutableSet<String> hierarchy = ImmutableSet.copyOf(readStringSet(decoder));
    List<ExcludeMetadata> excludeMetadata = readMavenExcludes(decoder);
    RealisedConfigurationMetadata realized = new RealisedConfigurationMetadata(resolveMetadata.getId(), name, transitive, visible, hierarchy, artifacts, ImmutableList.copyOf(excludeMetadata), attributes, immutableCapabilities, false, isExternalVariant);
    ImmutableList<ModuleDependencyMetadata> dependencies = readDependencies(decoder, resolveMetadata, realized, deduplicationDependencyCache);
    realized.setDependencies(dependencies);
    return realized;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ImmutableCapabilities(org.gradle.internal.component.external.model.ImmutableCapabilities) ModuleDependencyMetadata(org.gradle.internal.component.external.model.ModuleDependencyMetadata) ExcludeMetadata(org.gradle.internal.component.model.ExcludeMetadata) RealisedConfigurationMetadata(org.gradle.internal.component.external.model.RealisedConfigurationMetadata)

Example 12 with ImmutableAttributes

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

the class RealisedMavenModuleResolveMetadataSerializationHelper method readMavenConfigurations.

private Map<String, ConfigurationMetadata> readMavenConfigurations(Decoder decoder, DefaultMavenModuleResolveMetadata metadata, Map<Integer, MavenDependencyDescriptor> deduplicationDependencyCache) throws IOException {
    ImmutableMap<String, Configuration> configurationDefinitions = metadata.getConfigurationDefinitions();
    int configurationsCount = decoder.readSmallInt();
    Map<String, ConfigurationMetadata> configurations = Maps.newHashMapWithExpectedSize(configurationsCount);
    for (int i = 0; i < configurationsCount; i++) {
        String configurationName = decoder.readString();
        Configuration configuration = configurationDefinitions.get(configurationName);
        ImmutableSet<String> hierarchy = LazyToRealisedModuleComponentResolveMetadataHelper.constructHierarchy(configuration, configurationDefinitions);
        ImmutableAttributes attributes = getAttributeContainerSerializer().read(decoder);
        ImmutableCapabilities capabilities = readCapabilities(decoder);
        boolean isExternalVariant = decoder.readBoolean();
        ImmutableList<? extends ModuleComponentArtifactMetadata> artifacts = readFiles(decoder, metadata.getId());
        RealisedConfigurationMetadata configurationMetadata = new RealisedConfigurationMetadata(metadata.getId(), configurationName, configuration.isTransitive(), configuration.isVisible(), hierarchy, artifacts, ImmutableList.of(), attributes, capabilities, false, isExternalVariant);
        ImmutableList<ModuleDependencyMetadata> dependencies = readDependencies(decoder, metadata, configurationMetadata, deduplicationDependencyCache);
        configurationMetadata.setDependencies(dependencies);
        configurations.put(configurationName, configurationMetadata);
    }
    return configurations;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) Configuration(org.gradle.internal.component.external.descriptor.Configuration) ImmutableCapabilities(org.gradle.internal.component.external.model.ImmutableCapabilities) ModuleDependencyMetadata(org.gradle.internal.component.external.model.ModuleDependencyMetadata) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) RealisedConfigurationMetadata(org.gradle.internal.component.external.model.RealisedConfigurationMetadata) RealisedConfigurationMetadata(org.gradle.internal.component.external.model.RealisedConfigurationMetadata)

Example 13 with ImmutableAttributes

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

the class ComponentAttributeMatcher method match.

/**
 * Selects the candidates from the given set that are compatible with the requested criteria, according to the given schema.
 */
public <T extends HasAttributes> List<T> match(AttributeSelectionSchema schema, Collection<? extends T> candidates, AttributeContainerInternal requested, @Nullable T fallback, AttributeMatchingExplanationBuilder explanationBuilder) {
    if (candidates.size() == 0) {
        if (fallback != null && isMatching(schema, (AttributeContainerInternal) fallback.getAttributes(), requested)) {
            explanationBuilder.selectedFallbackConfiguration(requested, fallback);
            return ImmutableList.of(fallback);
        }
        explanationBuilder.noCandidates(requested, fallback);
        return ImmutableList.of();
    }
    if (candidates.size() == 1) {
        T candidate = candidates.iterator().next();
        if (isMatching(schema, (AttributeContainerInternal) candidate.getAttributes(), requested)) {
            explanationBuilder.singleMatch(candidate, candidates, requested);
            return Collections.singletonList(candidate);
        }
        explanationBuilder.candidateDoesNotMatchAttributes(candidate, requested);
        return ImmutableList.of();
    }
    ImmutableAttributes requestedAttributes = requested.asImmutable();
    CachedQuery query = null;
    if (explanationBuilder.canSkipExplanation()) {
        query = CachedQuery.of(schema, requestedAttributes, candidates);
        int[] index = cachedQueries.get(query);
        if (index != null) {
            return CachedQuery.select(index, candidates);
        }
    }
    List<T> matches = new MultipleCandidateMatcher<T>(schema, candidates, requestedAttributes, explanationBuilder).getMatches();
    if (query != null) {
        LOGGER.debug("Selected matches {} from candidates {} for {}", matches, candidates, requested);
        cacheMatchingResult(candidates, query, matches);
    }
    return matches;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal)

Example 14 with ImmutableAttributes

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

the class ComponentAttributeMatcher method describeMatching.

@SuppressWarnings({ "unchecked", "rawtypes" })
public List<AttributeMatcher.MatchingDescription<?>> describeMatching(AttributeSelectionSchema schema, AttributeContainerInternal candidate, AttributeContainerInternal requested) {
    if (requested.isEmpty() || candidate.isEmpty()) {
        return Collections.emptyList();
    }
    ImmutableAttributes requestedAttributes = requested.asImmutable();
    ImmutableAttributes candidateAttributes = candidate.asImmutable();
    ImmutableSet<Attribute<?>> attributes = requestedAttributes.keySet();
    List<AttributeMatcher.MatchingDescription<?>> result = Lists.newArrayListWithCapacity(attributes.size());
    for (Attribute<?> attribute : attributes) {
        AttributeValue<?> requestedValue = requestedAttributes.findEntry(attribute);
        AttributeValue<?> candidateValue = candidateAttributes.findEntry(attribute.getName());
        if (candidateValue.isPresent()) {
            Object coercedValue = candidateValue.coerce(attribute);
            boolean match = schema.matchValue(attribute, requestedValue.get(), coercedValue);
            result.add(new AttributeMatcher.MatchingDescription(attribute, requestedValue, candidateValue, match));
        } else {
            result.add(new AttributeMatcher.MatchingDescription(attribute, requestedValue, candidateValue, false));
        }
    }
    return result;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) Attribute(org.gradle.api.attributes.Attribute)

Example 15 with ImmutableAttributes

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

the class DefaultLocalComponentMetadataBuilder method addConfiguration.

@Override
public BuildableLocalConfigurationMetadata addConfiguration(BuildableLocalComponentMetadata metaData, ConfigurationInternal configuration) {
    BuildableLocalConfigurationMetadata configurationMetadata = createConfiguration(metaData, configuration);
    metaData.addDependenciesAndExcludesForConfiguration(configuration, configurationMetadataBuilder);
    ComponentConfigurationIdentifier configurationIdentifier = new ComponentConfigurationIdentifier(metaData.getId(), configuration.getName());
    configuration.collectVariants(new ConfigurationInternal.VariantVisitor() {

        @Override
        public void visitArtifacts(Collection<? extends PublishArtifact> artifacts) {
            metaData.addArtifacts(configuration.getName(), artifacts);
        }

        @Override
        public void visitOwnVariant(DisplayName displayName, ImmutableAttributes attributes, Collection<? extends Capability> capabilities, Collection<? extends PublishArtifact> artifacts) {
            metaData.addVariant(configuration.getName(), configuration.getName(), configurationIdentifier, displayName, attributes, ImmutableCapabilities.of(capabilities), artifacts);
        }

        @Override
        public void visitChildVariant(String name, DisplayName displayName, ImmutableAttributes attributes, Collection<? extends Capability> capabilities, Collection<? extends PublishArtifact> artifacts) {
            metaData.addVariant(configuration.getName(), configuration.getName() + "-" + name, new NestedVariantIdentifier(configurationIdentifier, name), displayName, attributes, ImmutableCapabilities.of(capabilities), artifacts);
        }
    });
    return configurationMetadata;
}
Also used : ComponentConfigurationIdentifier(org.gradle.internal.component.model.ComponentConfigurationIdentifier) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) DisplayName(org.gradle.internal.DisplayName) BuildableLocalConfigurationMetadata(org.gradle.internal.component.local.model.BuildableLocalConfigurationMetadata) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal)

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