Search in sources :

Example 1 with ForcedDependencyMetadataWrapper

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

the class RealisedMavenModuleResolveMetadataSerializationHelper 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 ForcedDependencyMetadataWrapper) {
            ForcedDependencyMetadataWrapper wrapper = (ForcedDependencyMetadataWrapper) dependency;
            dependency = wrapper.unwrap();
            if (wrapper.isForce()) {
                encoder.writeByte(FORCED_DEPENDENCY_METADATA);
            }
        }
        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 MavenDependencyDescriptor) {
                encoder.writeByte(MAVEN_DEPENDENCY_METADATA);
                writeMavenDependency(encoder, (MavenDependencyDescriptor) dependencyDescriptor, deduplicationDependencyCache);
            } else {
                throw new IllegalStateException("Unknown type of dependency descriptor: " + dependencyDescriptor.getClass());
            }
            encoder.writeNullableString(dependency.getReason());
        }
    }
}
Also used : ForcedDependencyMetadataWrapper(org.gradle.internal.component.external.model.ForcedDependencyMetadataWrapper) 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)

Example 2 with ForcedDependencyMetadataWrapper

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

the class RealisedMavenModuleResolveMetadataSerializationHelper method readDependencies.

private ImmutableList<ModuleDependencyMetadata> readDependencies(Decoder decoder, DefaultMavenModuleResolveMetadata metadata, RealisedConfigurationMetadata configurationMetadata, Map<Integer, MavenDependencyDescriptor> deduplicationDependencyCache) throws IOException {
    ImmutableList.Builder<ModuleDependencyMetadata> builder = ImmutableList.builder();
    int dependenciesCount = decoder.readSmallInt();
    if (dependenciesCount == 0) {
        return ImmutableList.of();
    }
    for (int j = 0; j < dependenciesCount; j++) {
        byte dependencyType = decoder.readByte();
        boolean force = false;
        if (dependencyType == FORCED_DEPENDENCY_METADATA) {
            force = true;
            dependencyType = decoder.readByte();
        }
        ModuleDependencyMetadata md;
        switch(dependencyType) {
            case GRADLE_DEPENDENCY_METADATA:
                md = readDependencyMetadata(decoder);
                break;
            case MAVEN_DEPENDENCY_METADATA:
                MavenDependencyDescriptor mavenDependencyDescriptor = readMavenDependency(decoder, deduplicationDependencyCache);
                ModuleDependencyMetadata dependencyMetadata = RealisedMavenModuleResolveMetadata.contextualize(configurationMetadata, metadata.getId(), mavenDependencyDescriptor);
                md = dependencyMetadata.withReason(decoder.readNullableString());
                break;
            case IVY_DEPENDENCY_METADATA:
                throw new IllegalStateException("Unexpected Ivy dependency for Maven module");
            default:
                throw new IllegalStateException("Unknown dependency type " + dependencyType);
        }
        if (force) {
            md = new ForcedDependencyMetadataWrapper(md);
        }
        builder.add(md);
    }
    return builder.build();
}
Also used : ForcedDependencyMetadataWrapper(org.gradle.internal.component.external.model.ForcedDependencyMetadataWrapper) ImmutableList(com.google.common.collect.ImmutableList) ModuleDependencyMetadata(org.gradle.internal.component.external.model.ModuleDependencyMetadata)

Aggregations

ForcedDependencyMetadataWrapper (org.gradle.internal.component.external.model.ForcedDependencyMetadataWrapper)2 ModuleDependencyMetadata (org.gradle.internal.component.external.model.ModuleDependencyMetadata)2 ImmutableList (com.google.common.collect.ImmutableList)1 ConfigurationBoundExternalDependencyMetadata (org.gradle.internal.component.external.model.ConfigurationBoundExternalDependencyMetadata)1 ExternalDependencyDescriptor (org.gradle.internal.component.external.model.ExternalDependencyDescriptor)1 GradleDependencyMetadata (org.gradle.internal.component.external.model.GradleDependencyMetadata)1 DependencyMetadata (org.gradle.internal.component.model.DependencyMetadata)1