Search in sources :

Example 6 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class JavaEcosystemVariantDerivationStrategy method derive.

@Override
public ImmutableList<? extends ConfigurationMetadata> derive(ModuleComponentResolveMetadata metadata) {
    if (metadata instanceof DefaultMavenModuleResolveMetadata) {
        DefaultMavenModuleResolveMetadata md = (DefaultMavenModuleResolveMetadata) metadata;
        ImmutableAttributes attributes = md.getAttributes();
        MavenImmutableAttributesFactory attributesFactory = (MavenImmutableAttributesFactory) md.getAttributesFactory();
        DefaultConfigurationMetadata compileConfiguration = (DefaultConfigurationMetadata) md.getConfiguration("compile");
        DefaultConfigurationMetadata runtimeConfiguration = (DefaultConfigurationMetadata) md.getConfiguration("runtime");
        ModuleComponentIdentifier componentId = md.getId();
        ImmutableCapabilities shadowedPlatformCapability = buildShadowPlatformCapability(componentId, false);
        ImmutableCapabilities shadowedEnforcedPlatformCapability = buildShadowPlatformCapability(componentId, true);
        return ImmutableList.of(// component we cannot mix precise usages with more generic ones)
        libraryWithUsageAttribute(compileConfiguration, attributes, attributesFactory, Usage.JAVA_API), libraryWithUsageAttribute(runtimeConfiguration, attributes, attributesFactory, Usage.JAVA_RUNTIME), libraryWithSourcesVariant(runtimeConfiguration, attributes, attributesFactory, metadata), libraryWithJavadocVariant(runtimeConfiguration, attributes, attributesFactory, metadata), platformWithUsageAttribute(compileConfiguration, attributes, attributesFactory, Usage.JAVA_API, false, shadowedPlatformCapability), platformWithUsageAttribute(runtimeConfiguration, attributes, attributesFactory, Usage.JAVA_RUNTIME, false, shadowedPlatformCapability), platformWithUsageAttribute(compileConfiguration, attributes, attributesFactory, Usage.JAVA_API, true, shadowedEnforcedPlatformCapability), platformWithUsageAttribute(runtimeConfiguration, attributes, attributesFactory, Usage.JAVA_RUNTIME, true, shadowedEnforcedPlatformCapability));
    }
    return null;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) DefaultMavenModuleResolveMetadata(org.gradle.internal.component.external.model.maven.DefaultMavenModuleResolveMetadata) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) MavenImmutableAttributesFactory(org.gradle.api.internal.artifacts.repositories.metadata.MavenImmutableAttributesFactory)

Example 7 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class JavaEcosystemVariantDerivationStrategy method platformWithUsageAttribute.

private static ConfigurationMetadata platformWithUsageAttribute(DefaultConfigurationMetadata conf, ImmutableAttributes originAttributes, MavenImmutableAttributesFactory attributesFactory, String usage, boolean enforcedPlatform, ImmutableCapabilities shadowedPlatformCapability) {
    ImmutableAttributes attributes = attributesFactory.platformWithUsage(originAttributes, usage, enforcedPlatform);
    String prefix = enforcedPlatform ? "enforced-platform-" : "platform-";
    DefaultConfigurationMetadata.Builder builder = conf.mutate().withName(prefix + conf.getName()).withAttributes(attributes).withConstraintsOnly().withCapabilities(shadowedPlatformCapability);
    if (enforcedPlatform) {
        builder = builder.withForcedDependencies();
    }
    return builder.build();
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes)

Example 8 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class LazyToRealisedModuleComponentResolveMetadataHelper method addVariantsFromRules.

private static ImmutableList<AbstractRealisedModuleComponentResolveMetadata.ImmutableRealisedVariantImpl> addVariantsFromRules(ModuleComponentResolveMetadata componentMetadata, List<AbstractRealisedModuleComponentResolveMetadata.ImmutableRealisedVariantImpl> declaredVariants, VariantMetadataRules variantMetadataRules) {
    List<AdditionalVariant> additionalVariants = variantMetadataRules.getAdditionalVariants();
    if (additionalVariants.isEmpty()) {
        return ImmutableList.copyOf(declaredVariants);
    }
    ImmutableList.Builder<AbstractRealisedModuleComponentResolveMetadata.ImmutableRealisedVariantImpl> builder = new ImmutableList.Builder<>();
    builder.addAll(declaredVariants);
    Map<String, ComponentVariant> variantsByName = declaredVariants.stream().collect(Collectors.toMap(ComponentVariant::getName, Function.identity()));
    for (AdditionalVariant additionalVariant : additionalVariants) {
        String baseName = additionalVariant.getBase();
        ImmutableAttributes attributes;
        ImmutableCapabilities capabilities;
        ImmutableList<? extends ComponentVariant.Dependency> dependencies;
        ImmutableList<? extends ComponentVariant.DependencyConstraint> dependencyConstraints;
        ImmutableList<? extends ComponentVariant.File> files;
        ComponentVariant baseVariant = variantsByName.get(baseName);
        boolean isExternalVariant;
        if (baseVariant == null) {
            attributes = componentMetadata.getAttributes();
            capabilities = ImmutableCapabilities.EMPTY;
            dependencies = ImmutableList.of();
            dependencyConstraints = ImmutableList.of();
            files = ImmutableList.of();
            isExternalVariant = false;
        } else {
            attributes = (ImmutableAttributes) baseVariant.getAttributes();
            capabilities = (ImmutableCapabilities) baseVariant.getCapabilities();
            dependencies = baseVariant.getDependencies();
            dependencyConstraints = baseVariant.getDependencyConstraints();
            files = baseVariant.getFiles();
            isExternalVariant = baseVariant.isExternalVariant();
        }
        if (baseName == null || baseVariant != null) {
            AbstractRealisedModuleComponentResolveMetadata.ImmutableRealisedVariantImpl variant = applyRules(new AbstractMutableModuleComponentResolveMetadata.ImmutableVariantImpl(componentMetadata.getId(), additionalVariant.getName(), attributes, dependencies, dependencyConstraints, files, capabilities, isExternalVariant), variantMetadataRules, componentMetadata.getId());
            builder.add(variant);
        } else if (!additionalVariant.isLenient()) {
            throw new InvalidUserDataException("Variant '" + baseName + "' not defined in module " + componentMetadata.getId().getDisplayName());
        }
    }
    return builder.build();
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ImmutableList(com.google.common.collect.ImmutableList) InvalidUserDataException(org.gradle.api.InvalidUserDataException)

Example 9 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class RealisedIvyModuleResolveMetadataSerializationHelper method readIvyConfigurations.

private Map<String, ConfigurationMetadata> readIvyConfigurations(Decoder decoder, DefaultIvyModuleResolveMetadata metadata) throws IOException {
    IvyConfigurationHelper configurationHelper = new IvyConfigurationHelper(metadata.getArtifactDefinitions(), new IdentityHashMap<>(), metadata.getExcludes(), metadata.getDependencies(), metadata.getId());
    ImmutableMap<String, Configuration> configurationDefinitions = metadata.getConfigurationDefinitions();
    int configurationsCount = decoder.readSmallInt();
    Map<String, ConfigurationMetadata> configurations = Maps.newHashMapWithExpectedSize(configurationsCount);
    for (int i = 0; i < configurationsCount; i++) {
        String configurationName = decoder.readString();
        boolean transitive = true;
        boolean visible = true;
        ImmutableSet<String> hierarchy = ImmutableSet.of(configurationName);
        ImmutableList<ExcludeMetadata> excludes;
        Configuration configuration = configurationDefinitions.get(configurationName);
        if (configuration != null) {
            // if the configuration represents a variant added by a rule, it is not in the definition list
            transitive = configuration.isTransitive();
            visible = configuration.isVisible();
            hierarchy = LazyToRealisedModuleComponentResolveMetadataHelper.constructHierarchy(configuration, configurationDefinitions);
            excludes = configurationHelper.filterExcludes(hierarchy);
        } else {
            excludes = ImmutableList.of();
        }
        ImmutableAttributes attributes = getAttributeContainerSerializer().read(decoder);
        ImmutableCapabilities capabilities = readCapabilities(decoder);
        boolean isExternalVariant = decoder.readBoolean();
        boolean hasExplicitExcludes = decoder.readBoolean();
        if (hasExplicitExcludes) {
            excludes = ImmutableList.copyOf(readMavenExcludes(decoder));
        }
        ImmutableList<? extends ModuleComponentArtifactMetadata> artifacts = readFiles(decoder, metadata.getId());
        RealisedConfigurationMetadata configurationMetadata = new RealisedConfigurationMetadata(metadata.getId(), configurationName, transitive, visible, hierarchy, artifacts, excludes, attributes, capabilities, false, isExternalVariant);
        ImmutableList.Builder<ModuleDependencyMetadata> builder = ImmutableList.builder();
        int dependenciesCount = decoder.readSmallInt();
        for (int j = 0; j < dependenciesCount; j++) {
            byte dependencyType = decoder.readByte();
            switch(dependencyType) {
                case GRADLE_DEPENDENCY_METADATA:
                    builder.add(readDependencyMetadata(decoder));
                    break;
                case IVY_DEPENDENCY_METADATA:
                    IvyDependencyDescriptor ivyDependency = readIvyDependency(decoder);
                    ModuleDependencyMetadata dependencyMetadata = configurationHelper.contextualize(configurationMetadata, metadata.getId(), ivyDependency);
                    builder.add(dependencyMetadata.withReason(decoder.readNullableString()));
                    break;
                case MAVEN_DEPENDENCY_METADATA:
                    throw new IllegalStateException("Unexpected Maven dependency for Ivy module");
                default:
                    throw new IllegalStateException("Unknown dependency type " + dependencyType);
            }
        }
        ImmutableList<ModuleDependencyMetadata> dependencies = builder.build();
        configurationMetadata.setDependencies(dependencies);
        configurations.put(configurationName, configurationMetadata);
    }
    return configurations;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) Configuration(org.gradle.internal.component.external.descriptor.Configuration) ImmutableCapabilities(org.gradle.internal.component.external.model.ImmutableCapabilities) ImmutableList(com.google.common.collect.ImmutableList) ModuleDependencyMetadata(org.gradle.internal.component.external.model.ModuleDependencyMetadata) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) RealisedConfigurationMetadata(org.gradle.internal.component.external.model.RealisedConfigurationMetadata) RealisedConfigurationMetadata(org.gradle.internal.component.external.model.RealisedConfigurationMetadata) ExcludeMetadata(org.gradle.internal.component.model.ExcludeMetadata)

Example 10 with ImmutableAttributes

use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.

the class RealisedIvyModuleResolveMetadata method applyRules.

private static RealisedConfigurationMetadata applyRules(ModuleComponentIdentifier id, String configurationName, VariantMetadataRules variantMetadataRules, ImmutableAttributes attributes, ImmutableCapabilities capabilities, ImmutableList<? extends ModuleComponentArtifactMetadata> artifacts, ImmutableList<ExcludeMetadata> excludes, boolean transitive, boolean visible, ImmutableSet<String> hierarchy, IvyConfigurationHelper configurationHelper, @Nullable List<ModuleDependencyMetadata> dependenciesOverride, boolean addedByRule, boolean isExternalVariant) {
    NameOnlyVariantResolveMetadata variant = new NameOnlyVariantResolveMetadata(configurationName);
    ImmutableAttributes variantAttributes = variantMetadataRules.applyVariantAttributeRules(variant, attributes);
    CapabilitiesMetadata capabilitiesMetadata = variantMetadataRules.applyCapabilitiesRules(variant, capabilities);
    ImmutableList<? extends ModuleComponentArtifactMetadata> artifactsMetadata = variantMetadataRules.applyVariantFilesMetadataRulesToArtifacts(variant, artifacts, id);
    return createConfiguration(id, configurationName, transitive, visible, hierarchy, artifactsMetadata, excludes, variantAttributes, ImmutableCapabilities.of(capabilitiesMetadata.getCapabilities()), variantMetadataRules, configurationHelper, dependenciesOverride, addedByRule, isExternalVariant);
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) CapabilitiesMetadata(org.gradle.api.capabilities.CapabilitiesMetadata)

Aggregations

ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)63 CoercingStringValueSnapshot (org.gradle.internal.snapshot.impl.CoercingStringValueSnapshot)9 AttributeContainerInternal (org.gradle.api.internal.attributes.AttributeContainerInternal)8 ArrayList (java.util.ArrayList)7 Attribute (org.gradle.api.attributes.Attribute)7 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)7 ImmutableCapabilities (org.gradle.internal.component.external.model.ImmutableCapabilities)6 AttributeMatcher (org.gradle.internal.component.model.AttributeMatcher)6 ImmutableList (com.google.common.collect.ImmutableList)5 File (java.io.File)5 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)4 CapabilitiesMetadata (org.gradle.api.capabilities.CapabilitiesMetadata)4 ExcludeMetadata (org.gradle.internal.component.model.ExcludeMetadata)4 List (java.util.List)3 VersionConstraint (org.gradle.api.artifacts.VersionConstraint)3 DefaultImmutableVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)3 ModuleDependencyMetadata (org.gradle.internal.component.external.model.ModuleDependencyMetadata)3 MutableComponentVariant (org.gradle.internal.component.external.model.MutableComponentVariant)3 RealisedConfigurationMetadata (org.gradle.internal.component.external.model.RealisedConfigurationMetadata)3 VariantResolveMetadata (org.gradle.internal.component.model.VariantResolveMetadata)3