Search in sources :

Example 1 with DefaultVariantMetadata

use of org.gradle.internal.component.model.DefaultVariantMetadata in project gradle by gradle.

the class ResolvedArtifactsGraphVisitor method getArtifacts.

private ArtifactSet getArtifacts(DependencyGraphEdge dependency, DependencyGraphNode toConfiguration) {
    long id = idGenerator.generateId();
    ConfigurationMetadata configuration = toConfiguration.getMetadata();
    ComponentResolveMetadata component = toConfiguration.getOwner().getMetadata();
    Set<? extends ComponentArtifactMetadata> artifacts = dependency.getArtifacts(configuration);
    if (!artifacts.isEmpty()) {
        Set<DefaultVariantMetadata> variants = ImmutableSet.of(new DefaultVariantMetadata(ImmutableAttributes.EMPTY, artifacts));
        return new DefaultArtifactSet(component.getComponentId(), component.getId(), component.getSource(), ModuleExclusions.excludeNone(), variants, artifactResolver, allResolvedArtifacts, id, attributesFactory, buildOperationExecutor);
    }
    ArtifactSet configurationArtifactSet = artifactSetsByConfiguration.get(toConfiguration.getNodeId());
    if (configurationArtifactSet == null) {
        Set<? extends VariantMetadata> variants = doResolve(component, configuration);
        configurationArtifactSet = new DefaultArtifactSet(component.getComponentId(), component.getId(), component.getSource(), dependency.getExclusions(moduleExclusions), variants, artifactResolver, allResolvedArtifacts, id, attributesFactory, buildOperationExecutor);
        // Only share an ArtifactSet if the artifacts are not filtered by the dependency
        if (!dependency.getExclusions(moduleExclusions).mayExcludeArtifacts()) {
            artifactSetsByConfiguration.put(toConfiguration.getNodeId(), configurationArtifactSet);
        }
    }
    return configurationArtifactSet;
}
Also used : ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) DefaultVariantMetadata(org.gradle.internal.component.model.DefaultVariantMetadata)

Example 2 with DefaultVariantMetadata

use of org.gradle.internal.component.model.DefaultVariantMetadata 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(id, 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);
    }
    // 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();
        Set<LocalComponentArtifactMetadata> newArtifacts = new LinkedHashSet<LocalComponentArtifactMetadata>(oldVariant.getArtifacts().size());
        for (ComponentArtifactMetadata oldArtifact : oldVariant.getArtifacts()) {
            newArtifacts.add(copyArtifact((LocalComponentArtifactMetadata) oldArtifact, artifacts, transformedArtifacts));
        }
        copy.allVariants.put(entry.getKey(), new DefaultVariantMetadata(oldVariant.getAttributes(), newArtifacts));
    }
    // Dependencies
    for (LocalOriginDependencyMetadata oldDependency : allDependencies) {
        copy.allDependencies.add(dependencies.transform(oldDependency));
    }
    // Exclude rules
    copy.allExcludes.addAll(allExcludes);
    return copy;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) 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 3 with DefaultVariantMetadata

use of org.gradle.internal.component.model.DefaultVariantMetadata in project gradle by gradle.

the class DefaultLocalComponentMetadata method addVariant.

@Override
public void addVariant(String configuration, OutgoingVariant variant) {
    Set<LocalComponentArtifactMetadata> artifacts;
    if (variant.getArtifacts().isEmpty()) {
        artifacts = ImmutableSet.of();
    } else {
        ImmutableSet.Builder<LocalComponentArtifactMetadata> builder = ImmutableSet.builder();
        for (PublishArtifact artifact : variant.getArtifacts()) {
            builder.add(new PublishArtifactLocalArtifactMetadata(componentIdentifier, artifact));
        }
        artifacts = builder.build();
    }
    allVariants.put(configuration, new DefaultVariantMetadata(variant.getAttributes().asImmutable(), artifacts));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) DefaultVariantMetadata(org.gradle.internal.component.model.DefaultVariantMetadata)

Aggregations

DefaultVariantMetadata (org.gradle.internal.component.model.DefaultVariantMetadata)3 ImmutableSet (com.google.common.collect.ImmutableSet)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)1 ComponentArtifactMetadata (org.gradle.internal.component.model.ComponentArtifactMetadata)1 ComponentResolveMetadata (org.gradle.internal.component.model.ComponentResolveMetadata)1 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)1 LocalOriginDependencyMetadata (org.gradle.internal.component.model.LocalOriginDependencyMetadata)1