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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations