Search in sources :

Example 11 with ConfigurationMetadata

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

the class LegacyConfigurationsSupplier method get.

@Override
public ImmutableList<? extends ConfigurationMetadata> get() {
    Set<String> configurationNames = targetComponent.getConfigurationNames();
    ImmutableList.Builder<ConfigurationMetadata> builder = new ImmutableList.Builder<>();
    for (String configurationName : configurationNames) {
        ConfigurationMetadata configuration = targetComponent.getConfiguration(configurationName);
        if (configuration.isCanBeConsumed()) {
            builder.add(configuration);
        }
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 12 with ConfigurationMetadata

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

the class AmbiguousConfigurationSelectionException method generateMessage.

private static String generateMessage(AttributeDescriber describer, AttributeContainerInternal fromConfigurationAttributes, AttributeMatcher attributeMatcher, List<? extends ConfigurationMetadata> matches, Set<ConfigurationMetadata> discarded, ComponentResolveMetadata targetComponent, boolean variantAware) {
    Map<String, ConfigurationMetadata> ambiguousConfigurations = new TreeMap<>();
    for (ConfigurationMetadata match : matches) {
        ambiguousConfigurations.put(match.getName(), match);
    }
    TreeFormatter formatter = new TreeFormatter();
    String configTerm = variantAware ? "variants" : "configurations";
    if (fromConfigurationAttributes.isEmpty()) {
        formatter.node("Cannot choose between the following " + configTerm + " of ");
    } else {
        formatter.node("The consumer was configured to find " + describer.describeAttributeSet(fromConfigurationAttributes.asMap()) + ". However we cannot choose between the following " + configTerm + " of ");
    }
    formatter.append(style(StyledTextOutput.Style.Info, targetComponent.getId().getDisplayName()));
    formatter.startChildren();
    for (String configuration : ambiguousConfigurations.keySet()) {
        formatter.node(configuration);
    }
    formatter.endChildren();
    formatter.node("All of them match the consumer attributes");
    // We're sorting the names of the configurations and later attributes
    // to make sure the output is consistently the same between invocations
    formatter.startChildren();
    for (ConfigurationMetadata ambiguousConf : ambiguousConfigurations.values()) {
        formatConfiguration(formatter, targetComponent, fromConfigurationAttributes, attributeMatcher, ambiguousConf, variantAware, true, describer);
    }
    formatter.endChildren();
    if (!discarded.isEmpty()) {
        formatter.node("The following " + configTerm + " were also considered but didn't match the requested attributes:");
        formatter.startChildren();
        discarded.stream().sorted(Comparator.comparing(ConfigurationMetadata::getName)).forEach(discardedConf -> formatConfiguration(formatter, targetComponent, fromConfigurationAttributes, attributeMatcher, discardedConf, variantAware, false, describer));
        formatter.endChildren();
    }
    return formatter.toString();
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) TreeMap(java.util.TreeMap) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 13 with ConfigurationMetadata

use of org.gradle.internal.component.model.ConfigurationMetadata 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 14 with ConfigurationMetadata

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

the class MavenDependencyDescriptor method selectLegacyConfigurations.

/**
 * Returns a set of configurations from the target component:
 *    - If this dependency is sourced from a 'compile' configuration, choose 'compile' if it exists, or 'default'.
 *    - Otherwise, choose 'runtime' if it exists, or 'default'. Also include 'compile' if it's not a parent of chosen ('runtime'/'default').
 *    - Always include 'master' if it exists, and it has dependencies and/or artifacts.
 */
@Override
public List<ConfigurationMetadata> selectLegacyConfigurations(ComponentIdentifier fromComponent, ConfigurationMetadata fromConfiguration, ComponentResolveMetadata targetComponent) {
    ImmutableList.Builder<ConfigurationMetadata> result = ImmutableList.builder();
    boolean requiresCompile = fromConfiguration.getName().equals("compile");
    if (!requiresCompile) {
        // From every configuration other than compile, include both the runtime and compile dependencies
        ConfigurationMetadata runtime = findTargetConfiguration(fromComponent, fromConfiguration, targetComponent, "runtime");
        result.add(runtime);
        requiresCompile = !runtime.getHierarchy().contains("compile");
    }
    if (requiresCompile) {
        // From compile configuration, or when the target's runtime configuration does not extend from compile, include the compile dependencies
        result.add(findTargetConfiguration(fromComponent, fromConfiguration, targetComponent, "compile"));
    }
    ConfigurationMetadata master = targetComponent.getConfiguration("master");
    if (master != null && (!master.getDependencies().isEmpty() || !master.getArtifacts().isEmpty())) {
        result.add(master);
    }
    return result.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 15 with ConfigurationMetadata

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

the class RealisedMavenModuleResolveMetadataSerializationHelper method readMavenConfigurations.

private Map<String, ConfigurationMetadata> readMavenConfigurations(Decoder decoder, DefaultMavenModuleResolveMetadata metadata, Map<Integer, MavenDependencyDescriptor> deduplicationDependencyCache) throws IOException {
    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();
        Configuration configuration = configurationDefinitions.get(configurationName);
        ImmutableSet<String> hierarchy = LazyToRealisedModuleComponentResolveMetadataHelper.constructHierarchy(configuration, configurationDefinitions);
        ImmutableAttributes attributes = getAttributeContainerSerializer().read(decoder);
        ImmutableCapabilities capabilities = readCapabilities(decoder);
        boolean isExternalVariant = decoder.readBoolean();
        ImmutableList<? extends ModuleComponentArtifactMetadata> artifacts = readFiles(decoder, metadata.getId());
        RealisedConfigurationMetadata configurationMetadata = new RealisedConfigurationMetadata(metadata.getId(), configurationName, configuration.isTransitive(), configuration.isVisible(), hierarchy, artifacts, ImmutableList.of(), attributes, capabilities, false, isExternalVariant);
        ImmutableList<ModuleDependencyMetadata> dependencies = readDependencies(decoder, metadata, configurationMetadata, deduplicationDependencyCache);
        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) 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)

Aggregations

ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)32 ImmutableList (com.google.common.collect.ImmutableList)10 RealisedConfigurationMetadata (org.gradle.internal.component.external.model.RealisedConfigurationMetadata)8 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)6 ModuleConfigurationMetadata (org.gradle.internal.component.model.ModuleConfigurationMetadata)6 TreeMap (java.util.TreeMap)4 ModuleDependencyMetadata (org.gradle.internal.component.external.model.ModuleDependencyMetadata)4 ImmutableCapabilities (org.gradle.internal.component.external.model.ImmutableCapabilities)3 ComponentResolveMetadata (org.gradle.internal.component.model.ComponentResolveMetadata)3 ConfigurationNotFoundException (org.gradle.internal.component.model.ConfigurationNotFoundException)3 TreeFormatter (org.gradle.internal.text.TreeFormatter)3 InvalidUserDataException (org.gradle.api.InvalidUserDataException)2 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)2 Configuration (org.gradle.internal.component.external.descriptor.Configuration)2 VariantMetadataRules (org.gradle.internal.component.external.model.VariantMetadataRules)2 LocalConfigurationMetadata (org.gradle.internal.component.local.model.LocalConfigurationMetadata)2 TreeFormatter (org.gradle.internal.logging.text.TreeFormatter)2 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1