Search in sources :

Example 1 with AttributeContainerInternal

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;
}
Also used : OutgoingVariant(org.gradle.api.internal.artifacts.configurations.OutgoingVariant) LinkedHashSet(java.util.LinkedHashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) DefaultLibraryLocalComponentMetadata(org.gradle.language.base.internal.model.DefaultLibraryLocalComponentMetadata) LinkedList(java.util.LinkedList) List(java.util.List) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) DefaultPublishArtifact(org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact) HashMap(java.util.HashMap) Map(java.util.Map) EnumMap(java.util.EnumMap) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal)

Example 2 with AttributeContainerInternal

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());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) VariantMetadata(org.gradle.internal.component.model.VariantMetadata) DefaultResolvedArtifact(org.gradle.api.internal.artifacts.DefaultResolvedArtifact) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal) ImmutableSet(com.google.common.collect.ImmutableSet) ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) DefaultResolvedArtifact(org.gradle.api.internal.artifacts.DefaultResolvedArtifact) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) File(java.io.File)

Example 3 with AttributeContainerInternal

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);
}
Also used : OpaqueComponentArtifactIdentifier(org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier) ComponentArtifactIdentifier(org.gradle.api.artifacts.component.ComponentArtifactIdentifier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal) ComponentFileArtifactIdentifier(org.gradle.internal.component.local.model.ComponentFileArtifactIdentifier) OpaqueComponentArtifactIdentifier(org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier) File(java.io.File)

Example 4 with AttributeContainerInternal

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);
}
Also used : ConfigurationNotConsumableException(org.gradle.internal.exceptions.ConfigurationNotConsumableException) AmbiguousConfigurationSelectionException(org.gradle.internal.component.AmbiguousConfigurationSelectionException) AttributesSchema(org.gradle.api.attributes.AttributesSchema) AttributesSchemaInternal(org.gradle.api.internal.attributes.AttributesSchemaInternal) NoMatchingConfigurationSelectionException(org.gradle.internal.component.NoMatchingConfigurationSelectionException) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal) LocalConfigurationMetadata(org.gradle.internal.component.local.model.LocalConfigurationMetadata) IncompatibleConfigurationSelectionException(org.gradle.internal.component.IncompatibleConfigurationSelectionException)

Example 5 with AttributeContainerInternal

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);
}
Also used : AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal)

Aggregations

AttributeContainerInternal (org.gradle.api.internal.attributes.AttributeContainerInternal)6 ImmutableSet (com.google.common.collect.ImmutableSet)2 File (java.io.File)2 LinkedHashSet (java.util.LinkedHashSet)2 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Dependency (org.gradle.api.artifacts.Dependency)1 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)1 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)1 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)1 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)1 ComponentArtifactIdentifier (org.gradle.api.artifacts.component.ComponentArtifactIdentifier)1 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)1 AttributesSchema (org.gradle.api.attributes.AttributesSchema)1 DefaultResolvedArtifact (org.gradle.api.internal.artifacts.DefaultResolvedArtifact)1 OutgoingVariant (org.gradle.api.internal.artifacts.configurations.OutgoingVariant)1