use of org.gradle.internal.component.model.ComponentArtifactMetadata in project gradle by gradle.
the class DefaultLocalComponentMetadata method copy.
/**
* Creates a copy of this metadata, transforming the artifacts and dependencies of this component.
*/
public DefaultLocalComponentMetadata copy(ComponentIdentifier componentIdentifier, Transformer<LocalComponentArtifactMetadata, LocalComponentArtifactMetadata> artifacts, Transformer<LocalOriginDependencyMetadata, LocalOriginDependencyMetadata> dependencies) {
DefaultLocalComponentMetadata copy = new DefaultLocalComponentMetadata(moduleVersionId, componentIdentifier, status, attributesSchema);
for (DefaultLocalConfigurationMetadata configuration : allConfigurations.values()) {
copy.addConfiguration(configuration.getName(), configuration.description, configuration.extendsFrom, configuration.hierarchy, configuration.visible, configuration.transitive, configuration.attributes, configuration.canBeConsumed, configuration.canBeResolved, configuration.capabilities);
}
// Artifacts
// Keep track of transformed artifacts as a given artifact may appear in multiple variants
Map<LocalComponentArtifactMetadata, LocalComponentArtifactMetadata> transformedArtifacts = new HashMap<LocalComponentArtifactMetadata, LocalComponentArtifactMetadata>();
for (Map.Entry<String, LocalComponentArtifactMetadata> entry : allArtifacts.entries()) {
LocalComponentArtifactMetadata oldArtifact = entry.getValue();
LocalComponentArtifactMetadata newArtifact = copyArtifact(oldArtifact, artifacts, transformedArtifacts);
copy.allArtifacts.put(entry.getKey(), newArtifact);
}
// Variants
for (Map.Entry<String, DefaultVariantMetadata> entry : allVariants.entries()) {
DefaultVariantMetadata oldVariant = entry.getValue();
List<LocalComponentArtifactMetadata> newArtifacts = new ArrayList<LocalComponentArtifactMetadata>(oldVariant.getArtifacts().size());
for (ComponentArtifactMetadata oldArtifact : oldVariant.getArtifacts()) {
newArtifacts.add(copyArtifact((LocalComponentArtifactMetadata) oldArtifact, artifacts, transformedArtifacts));
}
copy.allVariants.put(entry.getKey(), new DefaultVariantMetadata(oldVariant.asDescribable(), oldVariant.getAttributes(), newArtifacts, oldVariant.getCapabilities()));
}
for (DefaultLocalConfigurationMetadata configuration : allConfigurations.values()) {
configuration.realizeDependencies();
DefaultLocalConfigurationMetadata configurationCopy = copy.allConfigurations.get(configuration.getName());
// Dependencies
for (LocalOriginDependencyMetadata dependency : configuration.definedDependencies) {
configurationCopy.definedDependencies.add(dependencies.transform(dependency));
}
// Don't include file dependencies
// Exclude rules
configurationCopy.definedExcludes.addAll(configuration.definedExcludes);
}
return copy;
}
use of org.gradle.internal.component.model.ComponentArtifactMetadata in project gradle by gradle.
the class ExternalResourceResolverDescriptorParseContext method resolveMetaDataArtifactFile.
private LocallyAvailableExternalResource resolveMetaDataArtifactFile(ModuleComponentIdentifier moduleComponentIdentifier, ComponentMetaDataResolver componentResolver, ArtifactResolver artifactResolver, ArtifactType artifactType) {
BuildableComponentResolveResult moduleVersionResolveResult = new DefaultBuildableComponentResolveResult();
componentResolver.resolve(moduleComponentIdentifier, DefaultComponentOverrideMetadata.EMPTY, moduleVersionResolveResult);
BuildableArtifactSetResolveResult moduleArtifactsResolveResult = new DefaultBuildableArtifactSetResolveResult();
artifactResolver.resolveArtifactsWithType(moduleVersionResolveResult.getMetadata(), artifactType, moduleArtifactsResolveResult);
BuildableArtifactResolveResult artifactResolveResult = new DefaultBuildableArtifactResolveResult();
ComponentArtifactMetadata artifactMetaData = moduleArtifactsResolveResult.getResult().iterator().next();
artifactResolver.resolveArtifact(artifactMetaData, moduleVersionResolveResult.getMetadata().getSources(), artifactResolveResult);
File file = artifactResolveResult.getResult();
LocallyAvailableExternalResource resource = fileResourceRepository.resource(file);
ComponentArtifactIdentifier id = artifactMetaData.getId();
if (id instanceof ModuleComponentArtifactIdentifier) {
sources.add(new DefaultMetadataFileSource((ModuleComponentArtifactIdentifier) id, file, checksumService.sha1(file)));
}
return resource;
}
use of org.gradle.internal.component.model.ComponentArtifactMetadata in project gradle by gradle.
the class AbstractRealisedModuleResolveMetadataSerializationHelper method writeFiles.
protected void writeFiles(Encoder encoder, ImmutableList<? extends ComponentArtifactMetadata> artifacts) throws IOException {
int fileArtifactsCount = (int) artifacts.stream().filter(a -> a instanceof UrlBackedArtifactMetadata).count();
int ivyArtifactsCount = artifacts.size() - fileArtifactsCount;
encoder.writeSmallInt(ivyArtifactsCount);
for (ComponentArtifactMetadata artifact : artifacts) {
if (!(artifact instanceof UrlBackedArtifactMetadata)) {
IvyArtifactName artifactName = artifact.getName();
writeIvyArtifactName(encoder, artifactName);
ComponentIdentifier componentId = artifact.getComponentId();
if (componentId instanceof MavenUniqueSnapshotComponentIdentifier) {
MavenUniqueSnapshotComponentIdentifier uid = (MavenUniqueSnapshotComponentIdentifier) componentId;
encoder.writeNullableString(uid.getTimestamp());
encoder.writeString(uid.getVersion());
} else {
encoder.writeNullableString(null);
}
encoder.writeBoolean(artifact.getAlternativeArtifact().isPresent());
if (artifact.getAlternativeArtifact().isPresent()) {
writeIvyArtifactName(encoder, artifact.getAlternativeArtifact().get().getName());
}
encoder.writeBoolean(artifact.isOptionalArtifact());
}
}
encoder.writeSmallInt(fileArtifactsCount);
for (ComponentArtifactMetadata file : artifacts) {
if (file instanceof UrlBackedArtifactMetadata) {
encoder.writeString(((UrlBackedArtifactMetadata) file).getFileName());
encoder.writeString(((UrlBackedArtifactMetadata) file).getRelativeUrl());
}
}
}
use of org.gradle.internal.component.model.ComponentArtifactMetadata in project gradle by gradle.
the class DefaultLocalComponentMetadata method copy.
/**
* Creates a copy of this metadata, transforming the artifacts and dependencies of this component.
*/
public DefaultLocalComponentMetadata copy(ComponentIdentifier componentIdentifier, Transformer<LocalComponentArtifactMetadata, LocalComponentArtifactMetadata> artifacts) {
DefaultLocalComponentMetadata copy = new DefaultLocalComponentMetadata(moduleVersionId, componentIdentifier, status, attributesSchema);
for (DefaultLocalConfigurationMetadata configuration : allConfigurations.values()) {
copy.addConfiguration(configuration.getName(), configuration.description, configuration.extendsFrom, configuration.hierarchy, configuration.visible, configuration.transitive, configuration.attributes, configuration.canBeConsumed, configuration.consumptionDeprecation, configuration.canBeResolved, configuration.capabilities, Collections::emptyList);
}
// Artifacts
// Keep track of transformed artifacts as a given artifact may appear in multiple variants
Map<LocalComponentArtifactMetadata, LocalComponentArtifactMetadata> transformedArtifacts = new HashMap<>();
for (Map.Entry<String, LocalComponentArtifactMetadata> entry : allArtifacts.entries()) {
LocalComponentArtifactMetadata oldArtifact = entry.getValue();
LocalComponentArtifactMetadata newArtifact = copyArtifact(oldArtifact, artifacts, transformedArtifacts);
copy.allArtifacts.put(entry.getKey(), newArtifact);
}
// Variants
for (Map.Entry<String, DefaultVariantMetadata> entry : allVariants.entries()) {
DefaultVariantMetadata oldVariant = entry.getValue();
ImmutableList.Builder<LocalComponentArtifactMetadata> newArtifacts = new ImmutableList.Builder<>();
for (ComponentArtifactMetadata oldArtifact : oldVariant.getArtifacts()) {
newArtifacts.add(copyArtifact((LocalComponentArtifactMetadata) oldArtifact, artifacts, transformedArtifacts));
}
copy.allVariants.put(entry.getKey(), new DefaultVariantMetadata(oldVariant.getName(), oldVariant.getIdentifier(), oldVariant.asDescribable(), oldVariant.getAttributes(), newArtifacts.build(), oldVariant.getCapabilities()));
}
for (DefaultLocalConfigurationMetadata configuration : allConfigurations.values()) {
configuration.realizeDependencies();
DefaultLocalConfigurationMetadata configurationCopy = copy.allConfigurations.get(configuration.getName());
// Dependencies
configurationCopy.definedDependencies.addAll(configuration.definedDependencies);
configurationCopy.definedFiles.addAll(configuration.definedFiles);
// Exclude rules
configurationCopy.definedExcludes.addAll(configuration.definedExcludes);
}
return copy;
}
Aggregations