Search in sources :

Example 6 with ComponentArtifactMetadata

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) LocalOriginDependencyMetadata(org.gradle.internal.component.model.LocalOriginDependencyMetadata) HashMap(java.util.HashMap) Map(java.util.Map) DefaultVariantMetadata(org.gradle.internal.component.model.DefaultVariantMetadata)

Example 7 with ComponentArtifactMetadata

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;
}
Also used : ComponentArtifactIdentifier(org.gradle.api.artifacts.component.ComponentArtifactIdentifier) ModuleComponentArtifactIdentifier(org.gradle.internal.component.external.model.ModuleComponentArtifactIdentifier) ModuleComponentArtifactIdentifier(org.gradle.internal.component.external.model.ModuleComponentArtifactIdentifier) DefaultBuildableComponentResolveResult(org.gradle.internal.resolve.result.DefaultBuildableComponentResolveResult) BuildableComponentResolveResult(org.gradle.internal.resolve.result.BuildableComponentResolveResult) ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) DefaultMetadataFileSource(org.gradle.api.internal.artifacts.repositories.metadata.DefaultMetadataFileSource) DefaultBuildableComponentResolveResult(org.gradle.internal.resolve.result.DefaultBuildableComponentResolveResult) LocallyAvailableExternalResource(org.gradle.internal.resource.local.LocallyAvailableExternalResource) BuildableArtifactSetResolveResult(org.gradle.internal.resolve.result.BuildableArtifactSetResolveResult) DefaultBuildableArtifactSetResolveResult(org.gradle.internal.resolve.result.DefaultBuildableArtifactSetResolveResult) DefaultBuildableArtifactSetResolveResult(org.gradle.internal.resolve.result.DefaultBuildableArtifactSetResolveResult) BuildableArtifactResolveResult(org.gradle.internal.resolve.result.BuildableArtifactResolveResult) DefaultBuildableArtifactResolveResult(org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult) DefaultBuildableArtifactResolveResult(org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult) File(java.io.File)

Example 8 with ComponentArtifactMetadata

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());
        }
    }
}
Also used : ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) MavenUniqueSnapshotComponentIdentifier(org.gradle.api.internal.artifacts.repositories.resolver.MavenUniqueSnapshotComponentIdentifier) DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) MavenUniqueSnapshotComponentIdentifier(org.gradle.api.internal.artifacts.repositories.resolver.MavenUniqueSnapshotComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier)

Example 9 with ComponentArtifactMetadata

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;
}
Also used : HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) LocalConfigurationMetadataBuilder(org.gradle.api.internal.artifacts.ivyservice.moduleconverter.dependencies.LocalConfigurationMetadataBuilder) DeprecationMessageBuilder(org.gradle.internal.deprecation.DeprecationMessageBuilder) ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) Collections(java.util.Collections) HashMap(java.util.HashMap) Map(java.util.Map) DefaultVariantMetadata(org.gradle.internal.component.model.DefaultVariantMetadata)

Aggregations

ComponentArtifactMetadata (org.gradle.internal.component.model.ComponentArtifactMetadata)9 File (java.io.File)4 IvyArtifactName (org.gradle.internal.component.model.IvyArtifactName)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Map (java.util.Map)3 DefaultBuildableArtifactResolveResult (org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult)3 ImmutableList (com.google.common.collect.ImmutableList)2 HashMap (java.util.HashMap)2 ComponentArtifactIdentifier (org.gradle.api.artifacts.component.ComponentArtifactIdentifier)2 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)2 DefaultResolvedArtifact (org.gradle.api.internal.artifacts.DefaultResolvedArtifact)2 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 DefaultVariantMetadata (org.gradle.internal.component.model.DefaultVariantMetadata)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1