Search in sources :

Example 1 with DependencyConstraint

use of org.gradle.api.artifacts.DependencyConstraint in project gradle by gradle.

the class DefaultConfiguration method createCopy.

private DefaultConfiguration createCopy(Set<Dependency> dependencies, Set<DependencyConstraint> dependencyConstraints, boolean recursive) {
    DetachedConfigurationsProvider configurationsProvider = new DetachedConfigurationsProvider();
    RootComponentMetadataBuilder rootComponentMetadataBuilder = this.rootComponentMetadataBuilder.withConfigurationsProvider(configurationsProvider);
    String newName = name + "Copy";
    Factory<ResolutionStrategyInternal> childResolutionStrategy = resolutionStrategy != null ? Factories.constant(resolutionStrategy.copy()) : resolutionStrategyFactory;
    DefaultConfiguration copiedConfiguration = instantiator.newInstance(DefaultConfiguration.class, domainObjectContext, newName, configurationsProvider, resolver, listenerManager, metaDataProvider, childResolutionStrategy, projectAccessListener, projectFinder, fileCollectionFactory, buildOperationExecutor, instantiator, artifactNotationParser, capabilityNotationParser, attributesFactory, rootComponentMetadataBuilder);
    configurationsProvider.setTheOnlyConfiguration(copiedConfiguration);
    // state, cachedResolvedConfiguration, and extendsFrom intentionally not copied - must re-resolve copy
    // copying extendsFrom could mess up dependencies when copy was re-resolved
    copiedConfiguration.visible = visible;
    copiedConfiguration.transitive = transitive;
    copiedConfiguration.description = description;
    copiedConfiguration.defaultDependencyActions = defaultDependencyActions;
    copiedConfiguration.dependencyResolutionListeners = dependencyResolutionListeners;
    copiedConfiguration.canBeConsumed = canBeConsumed;
    copiedConfiguration.canBeResolved = canBeResolved;
    copiedConfiguration.getArtifacts().addAll(getAllArtifacts());
    if (!configurationAttributes.isEmpty()) {
        for (Attribute<?> attribute : configurationAttributes.keySet()) {
            Object value = configurationAttributes.getAttribute(attribute);
            copiedConfiguration.getAttributes().attribute(Cast.<Attribute<Object>>uncheckedCast(attribute), value);
        }
    }
    // todo An ExcludeRule is a value object but we don't enforce immutability for DefaultExcludeRule as strong as we
    // should (we expose the Map). We should provide a better API for ExcludeRule (I don't want to use unmodifiable Map).
    // As soon as DefaultExcludeRule is truly immutable, we don't need to create a new instance of DefaultExcludeRule.
    Set<Configuration> excludeRuleSources = new LinkedHashSet<Configuration>();
    excludeRuleSources.add(this);
    if (recursive) {
        excludeRuleSources.addAll(getHierarchy());
    }
    for (Configuration excludeRuleSource : excludeRuleSources) {
        for (ExcludeRule excludeRule : excludeRuleSource.getExcludeRules()) {
            copiedConfiguration.excludeRules.add(new DefaultExcludeRule(excludeRule.getGroup(), excludeRule.getModule()));
        }
    }
    DomainObjectSet<Dependency> copiedDependencies = copiedConfiguration.getDependencies();
    for (Dependency dependency : dependencies) {
        copiedDependencies.add(dependency.copy());
    }
    DomainObjectSet<DependencyConstraint> copiedDependencyConstraints = copiedConfiguration.getDependencyConstraints();
    for (DependencyConstraint dependencyConstraint : dependencyConstraints) {
        copiedDependencyConstraints.add(((DefaultDependencyConstraint) dependencyConstraint).copy());
    }
    return copiedConfiguration;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) ResolvedProjectConfiguration(org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedProjectConfiguration) DefaultLenientConfiguration(org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration) Configuration(org.gradle.api.artifacts.Configuration) DefaultDependencyConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultDependencyConstraint) DependencyConstraint(org.gradle.api.artifacts.DependencyConstraint) Dependency(org.gradle.api.artifacts.Dependency) TaskDependency(org.gradle.api.tasks.TaskDependency) FileCollectionDependency(org.gradle.api.artifacts.FileCollectionDependency) AbstractTaskDependency(org.gradle.api.internal.tasks.AbstractTaskDependency) ExcludeRule(org.gradle.api.artifacts.ExcludeRule) DefaultExcludeRule(org.gradle.api.internal.artifacts.DefaultExcludeRule) DefaultExcludeRule(org.gradle.api.internal.artifacts.DefaultExcludeRule) RootComponentMetadataBuilder(org.gradle.api.internal.artifacts.ivyservice.moduleconverter.RootComponentMetadataBuilder)

Example 2 with DependencyConstraint

use of org.gradle.api.artifacts.DependencyConstraint in project gradle by gradle.

the class DefaultDependencyConstraintHandler method doAdd.

private DependencyConstraint doAdd(Configuration configuration, Object dependencyNotation, @Nullable Action<? super DependencyConstraint> configureAction) {
    DependencyConstraint dependency = doCreate(dependencyNotation, configureAction);
    configuration.getDependencyConstraints().add(dependency);
    return dependency;
}
Also used : DependencyConstraint(org.gradle.api.artifacts.DependencyConstraint)

Example 3 with DependencyConstraint

use of org.gradle.api.artifacts.DependencyConstraint in project gradle by gradle.

the class ModuleMetadataFileGenerator method writeDependencyConstraints.

private void writeDependencyConstraints(UsageContext variant, JsonWriter jsonWriter) throws IOException {
    if (variant.getDependencyConstraints().isEmpty()) {
        return;
    }
    jsonWriter.name("dependencyConstraints");
    jsonWriter.beginArray();
    for (DependencyConstraint dependencyConstraint : variant.getDependencyConstraints()) {
        writeDependencyConstraint(dependencyConstraint, jsonWriter);
    }
    jsonWriter.endArray();
}
Also used : DependencyConstraint(org.gradle.api.artifacts.DependencyConstraint)

Example 4 with DependencyConstraint

use of org.gradle.api.artifacts.DependencyConstraint in project gradle by gradle.

the class DefaultMavenPublication method from.

public void from(SoftwareComponent component) {
    if (this.component != null) {
        throw new InvalidUserDataException(String.format("Maven publication '%s' cannot include multiple components", name));
    }
    this.component = (SoftwareComponentInternal) component;
    Set<ArtifactKey> seenArtifacts = Sets.newHashSet();
    Set<ModuleDependency> seenDependencies = Sets.newHashSet();
    Set<DependencyConstraint> seenConstraints = Sets.newHashSet();
    for (UsageContext usageContext : getSortedUsageContexts()) {
        // TODO Need a smarter way to map usage to artifact classifier
        for (PublishArtifact publishArtifact : usageContext.getArtifacts()) {
            ArtifactKey key = new ArtifactKey(publishArtifact.getFile(), publishArtifact.getClassifier(), publishArtifact.getExtension());
            if (seenArtifacts.add(key)) {
                artifact(publishArtifact);
            }
        }
        Set<MavenDependencyInternal> dependencies = dependenciesFor(usageContext.getUsage());
        for (ModuleDependency dependency : usageContext.getDependencies()) {
            if (seenDependencies.add(dependency)) {
                if (dependency instanceof ProjectDependency) {
                    addProjectDependency((ProjectDependency) dependency, dependencies);
                } else {
                    addModuleDependency(dependency, dependencies);
                }
            }
        }
        Set<MavenDependency> dependencyConstraints = dependencyConstraintsFor(usageContext.getUsage());
        for (DependencyConstraint dependency : usageContext.getDependencyConstraints()) {
            if (seenConstraints.add(dependency) && !dependency.getVersionConstraint().getPreferredVersion().isEmpty()) {
                addDependencyConstraint(dependency, dependencyConstraints);
            }
        }
    }
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) DependencyConstraint(org.gradle.api.artifacts.DependencyConstraint) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) MavenDependencyInternal(org.gradle.api.publish.maven.internal.dependencies.MavenDependencyInternal) UsageContext(org.gradle.api.internal.component.UsageContext) InvalidUserDataException(org.gradle.api.InvalidUserDataException) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) DefaultMavenDependency(org.gradle.api.publish.maven.internal.dependencies.DefaultMavenDependency) MavenDependency(org.gradle.api.publish.maven.MavenDependency)

Aggregations

DependencyConstraint (org.gradle.api.artifacts.DependencyConstraint)4 LinkedHashSet (java.util.LinkedHashSet)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 Configuration (org.gradle.api.artifacts.Configuration)1 Dependency (org.gradle.api.artifacts.Dependency)1 ExcludeRule (org.gradle.api.artifacts.ExcludeRule)1 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)1 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)1 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)1 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)1 ResolvedConfiguration (org.gradle.api.artifacts.ResolvedConfiguration)1 DefaultExcludeRule (org.gradle.api.internal.artifacts.DefaultExcludeRule)1 DefaultDependencyConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultDependencyConstraint)1 DefaultLenientConfiguration (org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration)1 RootComponentMetadataBuilder (org.gradle.api.internal.artifacts.ivyservice.moduleconverter.RootComponentMetadataBuilder)1 ResolvedProjectConfiguration (org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedProjectConfiguration)1 UsageContext (org.gradle.api.internal.component.UsageContext)1 AbstractTaskDependency (org.gradle.api.internal.tasks.AbstractTaskDependency)1 MavenDependency (org.gradle.api.publish.maven.MavenDependency)1 DefaultMavenDependency (org.gradle.api.publish.maven.internal.dependencies.DefaultMavenDependency)1