use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class DefaultMavenImmutableAttributesFactory method libraryWithUsage.
@Override
public ImmutableAttributes libraryWithUsage(ImmutableAttributes original, String usage) {
ComponentTypeEntry entry = new ComponentTypeEntry(original, Category.LIBRARY, usage);
ImmutableAttributes result = concatCache.get(entry);
if (result == null) {
result = concat(original, USAGE_ATTRIBUTE, new CoercingStringValueSnapshot(usage, objectInstantiator));
result = concat(result, FORMAT_ATTRIBUTE, new CoercingStringValueSnapshot(LibraryElements.JAR, objectInstantiator));
result = concat(result, CATEGORY_ATTRIBUTE, new CoercingStringValueSnapshot(Category.LIBRARY, objectInstantiator));
concatCache.put(entry, result);
}
return result;
}
use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class DefaultMavenImmutableAttributesFactory method sourcesVariant.
@Override
public ImmutableAttributes sourcesVariant(ImmutableAttributes original) {
ImmutableAttributes result = original;
result = concat(result, CATEGORY_ATTRIBUTE, new CoercingStringValueSnapshot(Category.DOCUMENTATION, objectInstantiator));
result = concat(result, Bundling.BUNDLING_ATTRIBUTE, objectInstantiator.named(Bundling.class, Bundling.EXTERNAL));
result = concat(result, DocsType.DOCS_TYPE_ATTRIBUTE, objectInstantiator.named(DocsType.class, DocsType.SOURCES));
result = concat(result, USAGE_ATTRIBUTE, new CoercingStringValueSnapshot(Usage.JAVA_RUNTIME, objectInstantiator));
return result;
}
use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class DefaultMavenImmutableAttributesFactory method javadocVariant.
@Override
public ImmutableAttributes javadocVariant(ImmutableAttributes original) {
ImmutableAttributes result = original;
result = concat(result, CATEGORY_ATTRIBUTE, new CoercingStringValueSnapshot(Category.DOCUMENTATION, objectInstantiator));
result = concat(result, Bundling.BUNDLING_ATTRIBUTE, objectInstantiator.named(Bundling.class, Bundling.EXTERNAL));
result = concat(result, DocsType.DOCS_TYPE_ATTRIBUTE, objectInstantiator.named(DocsType.class, DocsType.JAVADOC));
result = concat(result, USAGE_ATTRIBUTE, new CoercingStringValueSnapshot(Usage.JAVA_RUNTIME, objectInstantiator));
return result;
}
use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class AttributeMatchingVariantSelector method doSelect.
private ResolvedArtifactSet doSelect(ResolvedVariantSet producer, Factory factory, AttributeMatchingExplanationBuilder explanationBuilder) {
AttributeMatcher matcher = schema.withProducer(producer.getSchema());
ImmutableAttributes componentRequested = attributesFactory.concat(requested, producer.getOverriddenAttributes());
List<? extends ResolvedVariant> matches = matcher.matches(producer.getVariants(), componentRequested, explanationBuilder);
if (matches.size() == 1) {
return matches.get(0).getArtifacts();
}
if (matches.size() > 1) {
if (explanationBuilder instanceof TraceDiscardedVariants) {
Set<ResolvedVariant> discarded = Cast.uncheckedCast(((TraceDiscardedVariants) explanationBuilder).discarded);
AttributeDescriber describer = DescriberSelector.selectDescriber(componentRequested, schema);
throw new AmbiguousVariantSelectionException(describer, producer.asDescribable().getDisplayName(), componentRequested, matches, matcher, discarded);
} else {
// because we're going to fail, we can afford a second run with details
return doSelect(producer, factory, new TraceDiscardedVariants());
}
}
List<Pair<ResolvedVariant, MutableConsumerVariantMatchResult.ConsumerVariant>> candidates = new ArrayList<>();
for (ResolvedVariant variant : producer.getVariants()) {
AttributeContainerInternal variantAttributes = variant.getAttributes().asImmutable();
ConsumerVariantMatchResult matchResult = consumerProvidedVariantFinder.collectConsumerVariants(variantAttributes, componentRequested);
for (MutableConsumerVariantMatchResult.ConsumerVariant consumerVariant : matchResult.getMatches()) {
candidates.add(Pair.of(variant, consumerVariant));
}
}
if (candidates.size() > 1) {
candidates = tryDisambiguate(matcher, candidates, componentRequested, explanationBuilder);
}
if (candidates.size() == 1) {
Pair<ResolvedVariant, MutableConsumerVariantMatchResult.ConsumerVariant> result = candidates.get(0);
ResolvedVariant variant = result.getLeft();
VariantDefinition definition = result.getRight();
return factory.asTransformed(variant, definition, dependenciesResolver, transformedVariantFactory);
}
if (!candidates.isEmpty()) {
throw new AmbiguousTransformException(producer.asDescribable().getDisplayName(), componentRequested, candidates);
}
if (ignoreWhenNoMatches) {
return ResolvedArtifactSet.EMPTY;
}
throw new NoMatchingVariantSelectionException(producer.asDescribable().getDisplayName(), componentRequested, producer.getVariants(), matcher, DescriberSelector.selectDescriber(componentRequested, schema));
}
use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class AttributeMatchingVariantSelector method disambiguateWithSchema.
private List<Pair<ResolvedVariant, MutableConsumerVariantMatchResult.ConsumerVariant>> disambiguateWithSchema(AttributeMatcher matcher, List<Pair<ResolvedVariant, MutableConsumerVariantMatchResult.ConsumerVariant>> candidates, ImmutableAttributes componentRequested, AttributeMatchingExplanationBuilder explanationBuilder) {
List<AttributeContainerInternal> candidateAttributes = candidates.stream().map(pair -> pair.getRight().attributes).collect(Collectors.toList());
List<AttributeContainerInternal> matches = matcher.matches(candidateAttributes, componentRequested, explanationBuilder);
if (matches.size() == 1) {
AttributeContainerInternal singleMatch = matches.get(0);
return candidates.stream().filter(pair -> pair.getRight().attributes.equals(singleMatch)).collect(Collectors.toList());
} else if (matches.size() > 0 && matches.size() < candidates.size()) {
// We know all are compatibles, so this is only possible if some disambiguation happens but not getting us to 1 candidate
return candidates.stream().filter(pair -> matches.contains(pair.getRight().attributes)).collect(Collectors.toList());
}
return candidates;
}
Aggregations