use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class EdgeState method calculateTargetConfigurations.
private void calculateTargetConfigurations() {
targetNodes.clear();
targetNodeSelectionFailure = null;
ComponentResolveMetadata targetModuleVersion = targetModuleRevision.getMetadata();
if (targetModuleVersion == null) {
// Broken version
return;
}
ImmutableAttributes attributes = resolveState.getRoot().getMetadata().getAttributes();
List<ConfigurationMetadata> targetConfigurations;
try {
targetConfigurations = dependencyMetadata.selectConfigurations(attributes, targetModuleVersion, resolveState.getAttributesSchema());
} catch (Throwable t) {
// Failure to select the target variant/configurations from this component, given the dependency attributes/metadata.
targetNodeSelectionFailure = new ModuleVersionResolveException(dependencyState.getRequested(), t);
return;
}
for (ConfigurationMetadata targetConfiguration : targetConfigurations) {
NodeState targetNodeState = resolveState.getNode(targetModuleRevision, targetConfiguration);
this.targetNodes.add(targetNodeState);
}
}
use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class ModuleMetadataParser method consumeVariant.
private void consumeVariant(JsonReader reader, MutableModuleComponentResolveMetadata metadata) throws IOException {
reader.beginObject();
String variantName = null;
ImmutableAttributes attributes = ImmutableAttributes.EMPTY;
List<ModuleFile> files = Collections.emptyList();
List<ModuleDependency> dependencies = Collections.emptyList();
List<ModuleDependencyConstraint> dependencyConstraints = Collections.emptyList();
List<VariantCapability> capabilities = Collections.emptyList();
while (reader.peek() != END_OBJECT) {
String name = reader.nextName();
if (name.equals("name")) {
variantName = reader.nextString();
} else if (name.equals("attributes")) {
attributes = consumeAttributes(reader);
} else if (name.equals("files")) {
files = consumeFiles(reader);
} else if (name.equals("dependencies")) {
dependencies = consumeDependencies(reader);
} else if (name.equals("dependencyConstraints")) {
dependencyConstraints = consumeDependencyConstraints(reader);
} else if (name.equals("capabilities")) {
capabilities = consumeCapabilities(reader);
} else if (name.equals("available-at")) {
// For now just collect this as another dependency
// TODO - collect this information and merge the metadata from the other module
dependencies = consumeVariantLocation(reader);
} else {
consumeAny(reader);
}
}
reader.endObject();
MutableComponentVariant variant = metadata.addVariant(variantName, attributes);
for (ModuleFile file : files) {
variant.addFile(file.name, file.uri);
}
for (ModuleDependency dependency : dependencies) {
variant.addDependency(dependency.group, dependency.module, dependency.versionConstraint, dependency.excludes, dependency.reason);
}
for (ModuleDependencyConstraint dependencyConstraint : dependencyConstraints) {
variant.addDependencyConstraint(dependencyConstraint.group, dependencyConstraint.module, dependencyConstraint.versionConstraint, dependencyConstraint.reason);
}
for (VariantCapability capability : capabilities) {
variant.addCapability(capability.group, capability.name, capability.version);
}
}
use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class ConsumerProvidedVariantFinder method findProducersFor.
private void findProducersFor(AttributeContainerInternal actual, AttributeContainerInternal requested, ConsumerVariantMatchResult result) {
// Prefer direct transformation over indirect transformation
List<VariantTransformRegistry.Registration> candidates = new ArrayList<VariantTransformRegistry.Registration>();
for (VariantTransformRegistry.Registration transform : variantTransforms.getTransforms()) {
if (matchAttributes(transform.getTo(), requested)) {
if (matchAttributes(actual, transform.getFrom())) {
ImmutableAttributes variantAttributes = attributesFactory.concat(actual.asImmutable(), transform.getTo().asImmutable());
result.matched(variantAttributes, transform.getArtifactTransform(), 1);
}
candidates.add(transform);
}
}
if (result.hasMatches()) {
return;
}
for (final VariantTransformRegistry.Registration candidate : candidates) {
ConsumerVariantMatchResult inputVariants = new ConsumerVariantMatchResult();
collectConsumerVariants(actual, candidate.getFrom(), inputVariants);
if (!inputVariants.hasMatches()) {
continue;
}
for (final ConsumerVariantMatchResult.ConsumerVariant inputVariant : inputVariants.getMatches()) {
ImmutableAttributes variantAttributes = attributesFactory.concat(inputVariant.attributes.asImmutable(), candidate.getTo().asImmutable());
ArtifactTransformer transformer = new ChainedTransformer(inputVariant.transformer, candidate.getArtifactTransform());
result.matched(variantAttributes, transformer, inputVariant.depth + 1);
}
}
}
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) {
if (candidates.size() == 0) {
if (fallback != null && isMatching(schema, (AttributeContainerInternal) fallback.getAttributes(), requested)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("No candidates for {}, selected matching fallback {}", requested, fallback);
}
return ImmutableList.of(fallback);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("No candidates for {} and fallback {} does not match. Select nothing.", requested, fallback);
}
return ImmutableList.of();
}
if (candidates.size() == 1) {
T candidate = candidates.iterator().next();
if (isMatching(schema, (AttributeContainerInternal) candidate.getAttributes(), requested)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Selected match {} from candidates {} for {}", candidate, candidates, requested);
}
return Collections.singletonList(candidate);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Selected match [] from candidates {} for {}", candidates, requested);
}
return ImmutableList.of();
}
ImmutableAttributes requestedAttributes = requested.asImmutable();
List<T> matches = new MultipleCandidateMatcher<T>(schema, candidates, requestedAttributes).getMatches();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Selected matches {} from candidates {} for {}", matches, candidates, requested);
}
return matches;
}
use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class MultipleCandidateMatcher method collectExtraAttributes.
/**
* Collects attributes that were present on the candidates, but which the consumer did
* not ask for. Some of these attributes might be weakly typed, e.g. coming as Strings
* from an artifact repository. We always check whether the schema has a more strongly
* typed version of an attribute and use that one instead to apply its disambiguation
* rules.
*/
private void collectExtraAttributes() {
Set<Attribute<?>> extraAttributes = Sets.newLinkedHashSet();
for (ImmutableAttributes attributes : candidateAttributeSets) {
extraAttributes.addAll(attributes.keySet());
}
extraAttributes.removeAll(requested.keySet());
this.extraAttributes = extraAttributes.toArray(new Attribute[0]);
for (int i = 0; i < this.extraAttributes.length; i++) {
Attribute<?> extraAttribute = this.extraAttributes[i];
Attribute<?> schemaAttribute = schema.getAttribute(extraAttribute.getName());
if (schemaAttribute != null) {
this.extraAttributes[i] = schemaAttribute;
}
}
}
Aggregations