Search in sources :

Example 21 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class DefaultArtifactTypeRegistry method mapAttributesFor.

@Override
public ImmutableAttributes mapAttributesFor(File file) {
    ImmutableAttributes attributes = ImmutableAttributes.EMPTY;
    if (file.isDirectory()) {
        attributes = attributesFactory.of(ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
    } else {
        String extension = Files.getFileExtension(file.getName());
        if (artifactTypeDefinitions != null) {
            attributes = applyForExtension(attributes, extension);
        }
        attributes = attributesFactory.concat(attributesFactory.of(ARTIFACT_TYPE_ATTRIBUTE, extension), attributes);
    }
    return attributes;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes)

Example 22 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class GradleModuleMetadataCompatibilityConverter method handleAttributeCompatibility.

private void handleAttributeCompatibility(MutableModuleComponentResolveMetadata metaDataFromResource) {
    // However this code will have to remain forever while the other one should be removed at some point (Gradle 7.0?)
    for (MutableComponentVariant variant : metaDataFromResource.getMutableVariants()) {
        ImmutableAttributes attributes = variant.getAttributes();
        ImmutableAttributes updatedAttributes = ImmutableAttributes.EMPTY;
        if (attributes.contains(USAGE_STRING_ATTRIBUTE)) {
            String attributeValue = attributes.getAttribute(USAGE_STRING_ATTRIBUTE);
            if (attributeValue.endsWith("-jars")) {
                updatedAttributes = attributesFactory.concat(updatedAttributes, USAGE_STRING_ATTRIBUTE, new CoercingStringValueSnapshot(attributeValue.replace("-jars", ""), instantiator));
            }
        }
        if (!updatedAttributes.isEmpty() && !attributes.contains(LIBRARY_ELEMENTS_STRING_ATTRIBUTE)) {
            updatedAttributes = attributesFactory.concat(updatedAttributes, LIBRARY_ELEMENTS_STRING_ATTRIBUTE, new CoercingStringValueSnapshot(LibraryElements.JAR, instantiator));
        }
        if (!updatedAttributes.isEmpty()) {
            updatedAttributes = attributesFactory.concat(attributes, updatedAttributes);
            variant.setAttributes(updatedAttributes);
        }
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) CoercingStringValueSnapshot(org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot) MutableComponentVariant(org.gradle.internal.component.external.model.MutableComponentVariant)

Example 23 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class DefaultArtifactSet method toResolvedVariant.

public static ResolvedVariant toResolvedVariant(VariantResolveMetadata variant, ModuleVersionIdentifier ownerId, ModuleSources moduleSources, ExcludeSpec exclusions, ArtifactResolver artifactResolver, Map<ComponentArtifactIdentifier, ResolvableArtifact> allResolvedArtifacts, ImmutableAttributes variantAttributes, CalculatedValueContainerFactory calculatedValueContainerFactory) {
    List<? extends ComponentArtifactMetadata> artifacts = variant.getArtifacts();
    ImmutableSet.Builder<ResolvableArtifact> resolvedArtifacts = ImmutableSet.builder();
    boolean hasExcludedArtifact = false;
    for (ComponentArtifactMetadata artifact : artifacts) {
        IvyArtifactName artifactName = artifact.getName();
        if (exclusions.excludesArtifact(ownerId.getModule(), artifactName)) {
            hasExcludedArtifact = true;
            continue;
        }
        ResolvableArtifact resolvedArtifact = allResolvedArtifacts.get(artifact.getId());
        if (resolvedArtifact == null) {
            if (artifact.isOptionalArtifact()) {
                DefaultBuildableArtifactResolveResult result = new DefaultBuildableArtifactResolveResult();
                artifactResolver.resolveArtifact(artifact, moduleSources, result);
                if (!result.isSuccessful()) {
                    // Optional artifact is not available
                    continue;
                }
            }
            ValueCalculator<File> artifactCalculator;
            if (artifactResolver instanceof ProjectArtifactResolver) {
                artifactCalculator = ((ProjectArtifactResolver) artifactResolver).resolveArtifactLater(artifact);
            } else {
                // TODO - push this up to all ArtifactResolver implementations
                artifactCalculator = new LazyArtifactSupplier(artifact, moduleSources, artifactResolver);
            }
            CalculatedValue<File> artifactSource = calculatedValueContainerFactory.create(Describables.of(artifact.getId()), artifactCalculator);
            resolvedArtifact = new DefaultResolvableArtifact(ownerId, artifactName, artifact.getId(), context -> context.add(artifact.getBuildDependencies()), artifactSource, calculatedValueContainerFactory);
            allResolvedArtifacts.put(artifact.getId(), resolvedArtifact);
        }
        resolvedArtifacts.add(resolvedArtifact);
    }
    VariantResolveMetadata.Identifier identifier = variant.getIdentifier();
    if (hasExcludedArtifact) {
        // An ad hoc variant, has no identifier
        identifier = null;
    }
    return ArtifactBackedResolvedVariant.create(identifier, variant.asDescribable(), variantAttributes, withImplicitCapability(variant, ownerId), resolvedArtifacts.build());
}
Also used : ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) AttributesSchemaInternal(org.gradle.api.internal.attributes.AttributesSchemaInternal) DefaultResolvableArtifact(org.gradle.api.internal.artifacts.DefaultResolvableArtifact) ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) ModuleSources(org.gradle.internal.component.model.ModuleSources) ExtraExecutionGraphDependenciesResolverFactory(org.gradle.api.internal.artifacts.transform.ExtraExecutionGraphDependenciesResolverFactory) ComponentConfigurationIdentifier(org.gradle.internal.component.model.ComponentConfigurationIdentifier) ValueCalculator(org.gradle.internal.model.ValueCalculator) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) VariantResolveMetadata(org.gradle.internal.component.model.VariantResolveMetadata) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) ArtifactResolver(org.gradle.internal.resolve.resolver.ArtifactResolver) Describables(org.gradle.internal.Describables) ImmutableList(com.google.common.collect.ImmutableList) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) NodeExecutionContext(org.gradle.api.internal.tasks.NodeExecutionContext) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ImmutableCapabilities(org.gradle.internal.component.external.model.ImmutableCapabilities) Map(java.util.Map) Describable(org.gradle.api.Describable) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) Nullable(javax.annotation.Nullable) CapabilitiesMetadata(org.gradle.api.capabilities.CapabilitiesMetadata) TransformedVariantFactory(org.gradle.api.internal.artifacts.transform.TransformedVariantFactory) VariantDefinition(org.gradle.api.internal.artifacts.transform.VariantDefinition) ImmutableCapability(org.gradle.internal.component.external.model.ImmutableCapability) CalculatedValue(org.gradle.internal.model.CalculatedValue) ImmutableSet(com.google.common.collect.ImmutableSet) TaskDependencyResolveContext(org.gradle.api.internal.tasks.TaskDependencyResolveContext) ArtifactTypeRegistry(org.gradle.api.internal.artifacts.type.ArtifactTypeRegistry) Collection(java.util.Collection) VariantSelector(org.gradle.api.internal.artifacts.transform.VariantSelector) Set(java.util.Set) ComponentArtifactIdentifier(org.gradle.api.artifacts.component.ComponentArtifactIdentifier) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec) File(java.io.File) DefaultBuildableArtifactResolveResult(org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult) List(java.util.List) CalculatedValueContainerFactory(org.gradle.internal.model.CalculatedValueContainerFactory) Spec(org.gradle.api.specs.Spec) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) ProjectArtifactResolver(org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectArtifactResolver) DefaultVariantMetadata(org.gradle.internal.component.model.DefaultVariantMetadata) ProjectArtifactResolver(org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectArtifactResolver) VariantResolveMetadata(org.gradle.internal.component.model.VariantResolveMetadata) DefaultBuildableArtifactResolveResult(org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult) DefaultResolvableArtifact(org.gradle.api.internal.artifacts.DefaultResolvableArtifact) ImmutableSet(com.google.common.collect.ImmutableSet) ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) DefaultResolvableArtifact(org.gradle.api.internal.artifacts.DefaultResolvableArtifact) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) File(java.io.File)

Example 24 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class LocalFileDependencyBackedArtifactSet method visit.

@Override
public void visit(Visitor listener) {
    FileCollectionStructureVisitor.VisitType visitType = listener.prepareForVisit(this);
    if (visitType == FileCollectionStructureVisitor.VisitType.NoContents) {
        listener.visitArtifacts(new EndCollection(this));
        return;
    }
    ComponentIdentifier componentIdentifier = dependencyMetadata.getComponentId();
    if (componentIdentifier != null && !componentFilter.isSatisfiedBy(componentIdentifier)) {
        listener.visitArtifacts(new EndCollection(this));
        return;
    }
    FileCollectionInternal fileCollection = dependencyMetadata.getFiles();
    Set<File> files;
    try {
        files = fileCollection.getFiles();
    } catch (Exception throwable) {
        listener.visitArtifacts(new BrokenArtifacts(throwable));
        return;
    }
    ImmutableList.Builder<ResolvedArtifactSet> selectedArtifacts = ImmutableList.builderWithExpectedSize(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());
        }
        ImmutableAttributes variantAttributes = artifactTypeRegistry.mapAttributesFor(file);
        SingletonFileResolvedVariant variant = new SingletonFileResolvedVariant(file, artifactIdentifier, LOCAL_FILE, variantAttributes, dependencyMetadata, calculatedValueContainerFactory);
        selectedArtifacts.add(selector.select(variant, this));
    }
    CompositeResolvedArtifactSet.of(selectedArtifacts.build()).visit(listener);
    if (visitType == FileCollectionStructureVisitor.VisitType.Spec) {
        listener.visitArtifacts(new CollectionSpec(fileCollection));
    }
}
Also used : OpaqueComponentArtifactIdentifier(org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier) ComponentArtifactIdentifier(org.gradle.api.artifacts.component.ComponentArtifactIdentifier) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ImmutableList(com.google.common.collect.ImmutableList) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ComponentFileArtifactIdentifier(org.gradle.internal.component.local.model.ComponentFileArtifactIdentifier) OpaqueComponentArtifactIdentifier(org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier) FileCollectionInternal(org.gradle.api.internal.file.FileCollectionInternal) FileCollectionStructureVisitor(org.gradle.api.internal.file.FileCollectionStructureVisitor) File(java.io.File)

Example 25 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class ResolvedArtifactsGraphVisitor method getArtifacts.

private ArtifactsForNode getArtifacts(DependencyGraphEdge dependency, DependencyGraphNode toConfiguration) {
    ConfigurationMetadata targetConfiguration = toConfiguration.getMetadata();
    ComponentResolveMetadata component = toConfiguration.getOwner().getMetadata();
    ImmutableAttributes overriddenAttributes = dependency.getAttributes();
    List<? extends ComponentArtifactMetadata> artifacts = dependency.getArtifacts(targetConfiguration);
    if (!artifacts.isEmpty()) {
        int id = nextId++;
        ArtifactSet artifactSet = artifactSelector.resolveArtifacts(component, artifacts, overriddenAttributes);
        return new ArtifactsForNode(id, artifactSet);
    }
    ArtifactsForNode configurationArtifactSet = artifactsByNodeId.get(toConfiguration.getNodeId());
    if (configurationArtifactSet == null) {
        ExcludeSpec exclusions = dependency.getExclusions();
        ArtifactSet nodeArtifacts = artifactSelector.resolveArtifacts(component, targetConfiguration, exclusions, overriddenAttributes);
        int id = nextId++;
        configurationArtifactSet = new ArtifactsForNode(id, nodeArtifacts);
        // Only share an ArtifactSet if the artifacts are not filtered by the dependency
        if (!exclusions.mayExcludeArtifacts()) {
            artifactsByNodeId.put(toConfiguration.getNodeId(), configurationArtifactSet);
        }
    }
    return configurationArtifactSet;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)

Aggregations

ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)63 CoercingStringValueSnapshot (org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot)9 AttributeContainerInternal (org.gradle.api.internal.attributes.AttributeContainerInternal)8 ArrayList (java.util.ArrayList)7 Attribute (org.gradle.api.attributes.Attribute)7 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)7 ImmutableCapabilities (org.gradle.internal.component.external.model.ImmutableCapabilities)6 AttributeMatcher (org.gradle.internal.component.model.AttributeMatcher)6 ImmutableList (com.google.common.collect.ImmutableList)5 File (java.io.File)5 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)4 CapabilitiesMetadata (org.gradle.api.capabilities.CapabilitiesMetadata)4 ExcludeMetadata (org.gradle.internal.component.model.ExcludeMetadata)4 List (java.util.List)3 VersionConstraint (org.gradle.api.artifacts.VersionConstraint)3 DefaultImmutableVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)3 ModuleDependencyMetadata (org.gradle.internal.component.external.model.ModuleDependencyMetadata)3 MutableComponentVariant (org.gradle.internal.component.external.model.MutableComponentVariant)3 RealisedConfigurationMetadata (org.gradle.internal.component.external.model.RealisedConfigurationMetadata)3 VariantResolveMetadata (org.gradle.internal.component.model.VariantResolveMetadata)3