Search in sources :

Example 16 with ConfigurationMetadata

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

the class IvyDependencyDescriptor method findMatches.

private void findMatches(ComponentIdentifier fromComponent, ComponentResolveMetadata targetComponent, String fromConfiguration, String patternConfiguration, String targetPattern, List<ConfigurationMetadata> targetConfigurations) {
    int startFallback = targetPattern.indexOf('(');
    if (startFallback >= 0) {
        if (targetPattern.endsWith(")")) {
            String preferred = targetPattern.substring(0, startFallback);
            ConfigurationMetadata configuration = targetComponent.getConfiguration(preferred);
            if (configuration != null) {
                maybeAddConfiguration(targetConfigurations, configuration);
                return;
            }
            targetPattern = targetPattern.substring(startFallback + 1, targetPattern.length() - 1);
        }
    }
    if (targetPattern.equals("*")) {
        for (String targetName : targetComponent.getConfigurationNames()) {
            ConfigurationMetadata configuration = targetComponent.getConfiguration(targetName);
            if (configuration.isVisible()) {
                maybeAddConfiguration(targetConfigurations, configuration);
            }
        }
        return;
    }
    if (targetPattern.equals("@")) {
        targetPattern = patternConfiguration;
    } else if (targetPattern.equals("#")) {
        targetPattern = fromConfiguration;
    }
    ConfigurationMetadata configuration = targetComponent.getConfiguration(targetPattern);
    if (configuration == null) {
        throw new ConfigurationNotFoundException(fromComponent, fromConfiguration, targetPattern, targetComponent.getId());
    }
    maybeAddConfiguration(targetConfigurations, configuration);
}
Also used : ConfigurationNotFoundException(org.gradle.internal.component.model.ConfigurationNotFoundException) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 17 with ConfigurationMetadata

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

the class IvyDependencyDescriptor method maybeAddConfiguration.

private void maybeAddConfiguration(List<ConfigurationMetadata> configurations, ConfigurationMetadata toAdd) {
    Iterator<ConfigurationMetadata> iter = configurations.iterator();
    while (iter.hasNext()) {
        ConfigurationMetadata configuration = iter.next();
        if (configuration.getHierarchy().contains(toAdd.getName())) {
            // this configuration is a child of toAdd, so no need to add it
            return;
        }
        if (toAdd.getHierarchy().contains(configuration.getName())) {
            // toAdd is a child, so implies this configuration
            iter.remove();
        }
    }
    configurations.add(toAdd);
}
Also used : ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 18 with ConfigurationMetadata

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

the class ResolvedArtifactsGraphVisitor method getArtifacts.

private ArtifactsForNode getArtifacts(DependencyGraphEdge dependency, DependencyGraphNode toConfiguration) {
    ConfigurationMetadata targetConfiguration = toConfiguration.getMetadata();
    ComponentResolveMetadata component = toConfiguration.getOwner().getMetadata();
    ImmutableAttributes overriddenAttributes = dependency.getAttributes();
    List<? extends ComponentArtifactMetadata> artifacts = dependency.getArtifacts(targetConfiguration);
    if (!artifacts.isEmpty()) {
        int id = nextId++;
        ArtifactSet artifactSet = artifactSelector.resolveArtifacts(component, artifacts, overriddenAttributes);
        return new ArtifactsForNode(id, artifactSet);
    }
    ArtifactsForNode configurationArtifactSet = artifactsByNodeId.get(toConfiguration.getNodeId());
    if (configurationArtifactSet == null) {
        ExcludeSpec exclusions = dependency.getExclusions();
        ArtifactSet nodeArtifacts = artifactSelector.resolveArtifacts(component, targetConfiguration, exclusions, overriddenAttributes);
        int id = nextId++;
        configurationArtifactSet = new ArtifactsForNode(id, nodeArtifacts);
        // Only share an ArtifactSet if the artifacts are not filtered by the dependency
        if (!exclusions.mayExcludeArtifacts()) {
            artifactsByNodeId.put(toConfiguration.getNodeId(), configurationArtifactSet);
        }
    }
    return configurationArtifactSet;
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec)

Example 19 with ConfigurationMetadata

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

the class AmbiguousConfigurationSelectionException method formatConfiguration.

static void formatConfiguration(TreeFormatter formatter, AttributeContainer fromConfigurationAttributes, AttributesSchema consumerSchema, List<? extends ConfigurationMetadata> matches, Set<String> requestedAttributes, final String conf) {
    Optional<? extends ConfigurationMetadata> match = Iterables.tryFind(matches, new Predicate<ConfigurationMetadata>() {

        @Override
        public boolean apply(ConfigurationMetadata input) {
            return conf.equals(input.getName());
        }
    });
    if (match.isPresent()) {
        AttributeContainer producerAttributes = match.get().getAttributes();
        Set<Attribute<?>> targetAttributes = producerAttributes.keySet();
        Set<String> targetAttributeNames = Sets.newTreeSet(Iterables.transform(targetAttributes, ATTRIBUTE_NAME));
        Set<Attribute<?>> allAttributes = Sets.union(fromConfigurationAttributes.keySet(), producerAttributes.keySet());
        Set<String> commonAttributes = Sets.intersection(requestedAttributes, targetAttributeNames);
        Set<String> consumerOnlyAttributes = Sets.difference(requestedAttributes, targetAttributeNames);
        formatter.node("Configuration '");
        formatter.append(conf);
        formatter.append("'");
        formatter.startChildren();
        List<Attribute<?>> sortedAttributes = Ordering.usingToString().sortedCopy(allAttributes);
        formatAttributes(formatter, fromConfigurationAttributes, consumerSchema, producerAttributes, commonAttributes, consumerOnlyAttributes, sortedAttributes);
        formatter.endChildren();
    }
}
Also used : Attribute(org.gradle.api.attributes.Attribute) AttributeContainer(org.gradle.api.attributes.AttributeContainer) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 20 with ConfigurationMetadata

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

the class IvyDependencyMetadata method findMatches.

private void findMatches(ComponentResolveMetadata fromComponent, ComponentResolveMetadata targetComponent, String fromConfiguration, String patternConfiguration, String targetPattern, Set<ConfigurationMetadata> targetConfigurations) {
    int startFallback = targetPattern.indexOf('(');
    if (startFallback >= 0) {
        if (targetPattern.endsWith(")")) {
            String preferred = targetPattern.substring(0, startFallback);
            ConfigurationMetadata configuration = targetComponent.getConfiguration(preferred);
            if (configuration != null) {
                targetConfigurations.add(configuration);
                return;
            }
            targetPattern = targetPattern.substring(startFallback + 1, targetPattern.length() - 1);
        }
    }
    if (targetPattern.equals("*")) {
        for (String targetName : targetComponent.getConfigurationNames()) {
            ConfigurationMetadata configuration = targetComponent.getConfiguration(targetName);
            if (configuration.isVisible()) {
                targetConfigurations.add(configuration);
            }
        }
        return;
    }
    if (targetPattern.equals("@")) {
        targetPattern = patternConfiguration;
    } else if (targetPattern.equals("#")) {
        targetPattern = fromConfiguration;
    }
    ConfigurationMetadata configuration = targetComponent.getConfiguration(targetPattern);
    if (configuration == null) {
        throw new ConfigurationNotFoundException(fromComponent.getComponentId(), fromConfiguration, targetPattern, targetComponent.getComponentId());
    }
    targetConfigurations.add(configuration);
}
Also used : ConfigurationNotFoundException(org.gradle.internal.component.model.ConfigurationNotFoundException) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

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