use of org.gradle.api.internal.attributes.AttributeContainerInternal in project gradle by gradle.
the class JvmLocalLibraryMetaDataAdapter method createResolvedMetaData.
private DefaultLibraryLocalComponentMetadata createResolvedMetaData(BinarySpecInternal selectedBinary, String projectPath, EnumMap<UsageKind, Iterable<DependencySpec>> dependenciesPerUsage, EnumMap<UsageKind, List<PublishArtifact>> artifacts) {
DefaultLibraryLocalComponentMetadata metadata = newResolvedLibraryMetadata(selectedBinary.getId(), toStringMap(dependenciesPerUsage), projectPath);
for (Map.Entry<UsageKind, List<PublishArtifact>> entry : artifacts.entrySet()) {
UsageKind usage = entry.getKey();
final List<PublishArtifact> publishArtifacts = entry.getValue();
metadata.addArtifacts(usage.getConfigurationName(), publishArtifacts);
metadata.addVariant(usage.getConfigurationName(), new OutgoingVariant() {
@Override
public AttributeContainerInternal getAttributes() {
return ImmutableAttributes.EMPTY;
}
@Override
public Set<? extends PublishArtifact> getArtifacts() {
return new LinkedHashSet<PublishArtifact>(publishArtifacts);
}
@Override
public Set<? extends OutgoingVariant> getChildren() {
return ImmutableSet.of();
}
});
}
return metadata;
}
use of org.gradle.api.internal.attributes.AttributeContainerInternal in project gradle by gradle.
the class DefaultArtifactSet method snapshot.
@Override
public ArtifactSet snapshot() {
ImmutableSet.Builder<ResolvedVariant> result = ImmutableSet.builder();
for (VariantMetadata variant : variants) {
Set<? extends ComponentArtifactMetadata> artifacts = variant.getArtifacts();
Set<ResolvedArtifact> resolvedArtifacts = new LinkedHashSet<ResolvedArtifact>(artifacts.size());
// Add artifact format as an implicit attribute when all artifacts have the same format
AttributeContainerInternal attributes = variant.getAttributes();
if (!attributes.contains(ArtifactAttributes.ARTIFACT_FORMAT)) {
String format = null;
for (ComponentArtifactMetadata artifact : artifacts) {
String candidateFormat = artifact.getName().getType();
if (format == null) {
format = candidateFormat;
} else if (!format.equals(candidateFormat)) {
format = null;
break;
}
}
if (format != null) {
attributes = attributesFactory.concat(attributes.asImmutable(), ArtifactAttributes.ARTIFACT_FORMAT, format);
}
}
for (ComponentArtifactMetadata artifact : artifacts) {
IvyArtifactName artifactName = artifact.getName();
if (exclusions.excludeArtifact(moduleVersionIdentifier.getModule(), artifactName)) {
continue;
}
ResolvedArtifact resolvedArtifact = allResolvedArtifacts.get(artifact.getId());
if (resolvedArtifact == null) {
Factory<File> artifactSource = new BuildOperationArtifactSource(buildOperationExecutor, artifact.getId(), new LazyArtifactSource(artifact, moduleSource, artifactResolver));
resolvedArtifact = new DefaultResolvedArtifact(moduleVersionIdentifier, artifactName, artifact.getId(), artifact.getBuildDependencies(), artifactSource);
allResolvedArtifacts.put(artifact.getId(), resolvedArtifact);
}
resolvedArtifacts.add(resolvedArtifact);
}
result.add(ArtifactBackedResolvedVariant.create(attributes, resolvedArtifacts));
}
return new ArtifactSetSnapshot(id, componentIdentifier, result.build());
}
use of org.gradle.api.internal.attributes.AttributeContainerInternal in project gradle by gradle.
the class LocalFileDependencyBackedArtifactSet method snapshot.
@Override
public ResolvedArtifactSet snapshot() {
ComponentIdentifier componentIdentifier = dependencyMetadata.getComponentId();
if (componentIdentifier != null && !componentFilter.isSatisfiedBy(componentIdentifier)) {
return ResolvedArtifactSet.EMPTY;
}
Set<File> files;
try {
files = dependencyMetadata.getFiles().getFiles();
} catch (Throwable throwable) {
return new FailingResolvedArtifactSetSnapshot(throwable);
}
List<ResolvedVariant> variants = Lists.newArrayListWithCapacity(files.size());
for (File file : files) {
ComponentArtifactIdentifier artifactIdentifier;
if (componentIdentifier == null) {
artifactIdentifier = new OpaqueComponentArtifactIdentifier(file);
if (!componentFilter.isSatisfiedBy(artifactIdentifier.getComponentIdentifier())) {
continue;
}
} else {
artifactIdentifier = new ComponentFileArtifactIdentifier(componentIdentifier, file.getName());
}
AttributeContainerInternal variantAttributes = DefaultArtifactAttributes.forFile(file, attributesFactory);
ResolvedVariant variant = new SingletonFileResolvedVariant(file, artifactIdentifier, variantAttributes);
variants.add(selector.select(Collections.singleton(variant)));
}
return new ResolvedVariantBackedArtifactSetSnapshot(variants, dependencyMetadata);
}
use of org.gradle.api.internal.attributes.AttributeContainerInternal in project gradle by gradle.
the class LocalComponentDependencyMetadata method selectConfigurations.
@Override
public Set<ConfigurationMetadata> selectConfigurations(ComponentResolveMetadata fromComponent, ConfigurationMetadata fromConfiguration, ComponentResolveMetadata targetComponent, AttributesSchema attributesSchema) {
AttributeContainerInternal fromConfigurationAttributes = fromConfiguration.getAttributes();
boolean consumerHasAttributes = !fromConfigurationAttributes.isEmpty();
boolean useConfigurationAttributes = dependencyConfiguration == null && consumerHasAttributes;
AttributesSchema producerAttributeSchema = targetComponent.getAttributesSchema() == null ? attributesSchema : targetComponent.getAttributesSchema();
if (useConfigurationAttributes) {
List<? extends ConfigurationMetadata> consumableConfigurations = targetComponent.getConsumableConfigurationsHavingAttributes();
List<? extends ConfigurationMetadata> matches = ((AttributesSchemaInternal) attributesSchema).getMatches(producerAttributeSchema, consumableConfigurations, fromConfigurationAttributes);
if (matches.size() == 1) {
return ImmutableSet.of(ClientAttributesPreservingConfigurationMetadata.wrapIfLocal(matches.get(0), fromConfigurationAttributes));
} else if (!matches.isEmpty()) {
throw new AmbiguousConfigurationSelectionException(fromConfigurationAttributes, attributesSchema, matches, targetComponent);
}
}
String targetConfiguration = GUtil.elvis(dependencyConfiguration, Dependency.DEFAULT_CONFIGURATION);
ConfigurationMetadata toConfiguration = targetComponent.getConfiguration(targetConfiguration);
if (toConfiguration == null) {
throw new ConfigurationNotFoundException(fromComponent.getComponentId(), moduleConfiguration, targetConfiguration, targetComponent.getComponentId());
}
if (!toConfiguration.isCanBeConsumed()) {
if (dependencyConfiguration == null) {
// this was a fallback to `default`, and `default` is not consumable
Set<String> configurationNames = Sets.newTreeSet();
configurationNames.addAll(targetComponent.getConfigurationNames());
throw new NoMatchingConfigurationSelectionException(fromConfigurationAttributes, attributesSchema, targetComponent, Lists.newArrayList(configurationNames));
}
// explicit configuration selection
throw new ConfigurationNotConsumableException(targetComponent.toString(), toConfiguration.getName());
}
ConfigurationMetadata delegate = toConfiguration;
if (consumerHasAttributes) {
if (!delegate.getAttributes().isEmpty()) {
// need to validate that the selected configuration still matches the consumer attributes
List<ConfigurationMetadata> matches = ((AttributesSchemaInternal) attributesSchema).getMatches(producerAttributeSchema, Collections.singletonList(delegate), fromConfigurationAttributes);
if (matches.isEmpty()) {
throw new IncompatibleConfigurationSelectionException(fromConfigurationAttributes, attributesSchema, targetComponent, targetConfiguration);
}
}
}
if (useConfigurationAttributes) {
delegate = ClientAttributesPreservingConfigurationMetadata.wrapIfLocal(delegate, fromConfigurationAttributes);
}
return ImmutableSet.of(delegate);
}
use of org.gradle.api.internal.attributes.AttributeContainerInternal in project gradle by gradle.
the class DefaultConfiguration method lockAttributes.
@Override
public void lockAttributes() {
AttributeContainerInternal delegatee = configurationAttributes.asImmutable();
configurationAttributes = new AttributeContainerWithErrorMessage(delegatee);
}
Aggregations