Search in sources :

Example 6 with RealisedConfigurationMetadata

use of org.gradle.internal.component.external.model.RealisedConfigurationMetadata in project gradle by gradle.

the class RealisedMavenModuleResolveMetadata method transform.

/**
 * Factory method to transform a {@link DefaultMavenModuleResolveMetadata}, which is lazy, in a realised version.
 *
 * @param metadata the lazy metadata to transform
 * @return the realised version of the metadata
 */
public static RealisedMavenModuleResolveMetadata transform(DefaultMavenModuleResolveMetadata metadata) {
    VariantMetadataRules variantMetadataRules = metadata.getVariantMetadataRules();
    ImmutableList<? extends ComponentVariant> variants = LazyToRealisedModuleComponentResolveMetadataHelper.realiseVariants(metadata, variantMetadataRules, metadata.getVariants());
    Map<String, ConfigurationMetadata> configurations = Maps.newHashMapWithExpectedSize(metadata.getConfigurationNames().size());
    List<ConfigurationMetadata> derivedVariants = ImmutableList.of();
    if (variants.isEmpty()) {
        Optional<ImmutableList<? extends ConfigurationMetadata>> maybeDeriveVariants = metadata.maybeDeriveVariants();
        if (maybeDeriveVariants.isPresent()) {
            ImmutableList.Builder<ConfigurationMetadata> builder = new ImmutableList.Builder<>();
            for (ConfigurationMetadata derivedVariant : maybeDeriveVariants.get()) {
                ImmutableList<ModuleDependencyMetadata> dependencies = Cast.uncheckedCast(derivedVariant.getDependencies());
                // We do not need to apply the rules manually to derived variants, because the derivation already
                // instantiated 'derivedVariant' as 'DefaultConfigurationMetadata' which does the rules application
                // automatically when calling the getters (done in the code below).
                RealisedConfigurationMetadata derivedVariantMetadata = new RealisedConfigurationMetadata(metadata.getId(), derivedVariant.getName(), derivedVariant.isTransitive(), derivedVariant.isVisible(), derivedVariant.getHierarchy(), Cast.uncheckedCast(derivedVariant.getArtifacts()), derivedVariant.getExcludes(), derivedVariant.getAttributes(), (ImmutableCapabilities) derivedVariant.getCapabilities(), dependencies, false, derivedVariant.isExternalVariant());
                builder.add(derivedVariantMetadata);
            }
            derivedVariants = addVariantsFromRules(metadata, builder.build(), variantMetadataRules);
        }
    }
    for (String configurationName : metadata.getConfigurationNames()) {
        configurations.put(configurationName, createConfiguration(metadata, configurationName));
    }
    return new RealisedMavenModuleResolveMetadata(metadata, variants, derivedVariants, configurations);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ModuleDependencyMetadata(org.gradle.internal.component.external.model.ModuleDependencyMetadata) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) ModuleConfigurationMetadata(org.gradle.internal.component.model.ModuleConfigurationMetadata) RealisedConfigurationMetadata(org.gradle.internal.component.external.model.RealisedConfigurationMetadata) RealisedConfigurationMetadata(org.gradle.internal.component.external.model.RealisedConfigurationMetadata) VariantMetadataRules(org.gradle.internal.component.external.model.VariantMetadataRules)

Example 7 with RealisedConfigurationMetadata

use of org.gradle.internal.component.external.model.RealisedConfigurationMetadata in project gradle by gradle.

the class RealisedIvyModuleResolveMetadataSerializationHelper method writeDependencies.

@Override
protected void writeDependencies(Encoder encoder, ConfigurationMetadata configuration, Map<ExternalDependencyDescriptor, Integer> deduplicationDependencyCache) throws IOException {
    List<? extends DependencyMetadata> dependencies = configuration.getDependencies();
    encoder.writeSmallInt(dependencies.size());
    for (DependencyMetadata dependency : dependencies) {
        if (dependency instanceof GradleDependencyMetadata) {
            encoder.writeByte(GRADLE_DEPENDENCY_METADATA);
            writeDependencyMetadata(encoder, (GradleDependencyMetadata) dependency);
        } else if (dependency instanceof ConfigurationBoundExternalDependencyMetadata) {
            ConfigurationBoundExternalDependencyMetadata dependencyMetadata = (ConfigurationBoundExternalDependencyMetadata) dependency;
            ExternalDependencyDescriptor dependencyDescriptor = dependencyMetadata.getDependencyDescriptor();
            if (dependencyDescriptor instanceof IvyDependencyDescriptor) {
                encoder.writeByte(IVY_DEPENDENCY_METADATA);
                boolean addedByRule = configuration instanceof RealisedConfigurationMetadata && ((RealisedConfigurationMetadata) configuration).isAddedByRule();
                writeIvyDependency(encoder, (IvyDependencyDescriptor) dependencyDescriptor, configuration.getName(), addedByRule);
            } else {
                throw new IllegalStateException("Unknown type of dependency descriptor: " + dependencyDescriptor.getClass());
            }
            encoder.writeNullableString(dependency.getReason());
        }
    }
}
Also used : GradleDependencyMetadata(org.gradle.internal.component.external.model.GradleDependencyMetadata) ConfigurationBoundExternalDependencyMetadata(org.gradle.internal.component.external.model.ConfigurationBoundExternalDependencyMetadata) ExternalDependencyDescriptor(org.gradle.internal.component.external.model.ExternalDependencyDescriptor) GradleDependencyMetadata(org.gradle.internal.component.external.model.GradleDependencyMetadata) DependencyMetadata(org.gradle.internal.component.model.DependencyMetadata) ModuleDependencyMetadata(org.gradle.internal.component.external.model.ModuleDependencyMetadata) ConfigurationBoundExternalDependencyMetadata(org.gradle.internal.component.external.model.ConfigurationBoundExternalDependencyMetadata) RealisedConfigurationMetadata(org.gradle.internal.component.external.model.RealisedConfigurationMetadata)

Example 8 with RealisedConfigurationMetadata

use of org.gradle.internal.component.external.model.RealisedConfigurationMetadata in project gradle by gradle.

the class RealisedIvyModuleResolveMetadataSerializationHelper method writeConfiguration.

@Override
protected void writeConfiguration(Encoder encoder, ConfigurationMetadata configuration) throws IOException {
    super.writeConfiguration(encoder, configuration);
    if (configuration instanceof RealisedConfigurationMetadata) {
        RealisedConfigurationMetadata realisedMetadata = (RealisedConfigurationMetadata) configuration;
        if (realisedMetadata.isAddedByRule()) {
            encoder.writeBoolean(true);
            writeMavenExcludeRules(encoder, realisedMetadata.getExcludes());
        } else {
            encoder.writeBoolean(false);
        }
    } else {
        encoder.writeBoolean(false);
    }
}
Also used : RealisedConfigurationMetadata(org.gradle.internal.component.external.model.RealisedConfigurationMetadata)

Aggregations

RealisedConfigurationMetadata (org.gradle.internal.component.external.model.RealisedConfigurationMetadata)8 ModuleDependencyMetadata (org.gradle.internal.component.external.model.ModuleDependencyMetadata)7 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)3 ImmutableCapabilities (org.gradle.internal.component.external.model.ImmutableCapabilities)3 Configuration (org.gradle.internal.component.external.descriptor.Configuration)2 ConfigurationBoundExternalDependencyMetadata (org.gradle.internal.component.external.model.ConfigurationBoundExternalDependencyMetadata)2 DependencyMetadata (org.gradle.internal.component.model.DependencyMetadata)2 ExcludeMetadata (org.gradle.internal.component.model.ExcludeMetadata)2 ModuleConfigurationMetadata (org.gradle.internal.component.model.ModuleConfigurationMetadata)2 ExternalDependencyDescriptor (org.gradle.internal.component.external.model.ExternalDependencyDescriptor)1 GradleDependencyMetadata (org.gradle.internal.component.external.model.GradleDependencyMetadata)1 VariantMetadataRules (org.gradle.internal.component.external.model.VariantMetadataRules)1