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;
}
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);
}
}
}
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());
}
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));
}
}
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;
}
Aggregations