Search in sources :

Example 71 with Configuration

use of org.gradle.api.artifacts.Configuration in project spring-boot by spring-projects.

the class ProjectLibraries method getLibraries.

private Set<GradleLibrary> getLibraries(String configurationName, LibraryScope scope) {
    Configuration configuration = (configurationName == null ? null : this.project.getConfigurations().findByName(configurationName));
    if (configuration == null) {
        return null;
    }
    Set<GradleLibrary> libraries = new LinkedHashSet<>();
    for (ResolvedArtifact artifact : configuration.getResolvedConfiguration().getResolvedArtifacts()) {
        libraries.add(new ResolvedArtifactLibrary(artifact, scope));
    }
    libraries.addAll(getLibrariesForFileDependencies(configuration, scope));
    return libraries;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) Configuration(org.gradle.api.artifacts.Configuration)

Example 72 with Configuration

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

the class DefaultConfiguration method collectSuperConfigs.

private void collectSuperConfigs(Configuration configuration, Set<Configuration> result) {
    for (Configuration superConfig : configuration.getExtendsFrom()) {
        if (result.contains(superConfig)) {
            result.remove(superConfig);
        }
        result.add(superConfig);
        collectSuperConfigs(superConfig, result);
    }
}
Also used : 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)

Example 73 with Configuration

use of org.gradle.api.artifacts.Configuration 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 74 with Configuration

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

the class DefaultConfigurationContainer method dump.

/**
 * Build a formatted representation of all Configurations in this ConfigurationContainer. Configuration(s) being toStringed are likely derivations of DefaultConfiguration.
 */
public String dump() {
    StringBuilder reply = new StringBuilder();
    reply.append("Configuration of type: " + getTypeDisplayName());
    Collection<? extends Configuration> configs = getAll();
    for (Configuration c : configs) {
        reply.append("\n  " + c.toString());
    }
    return reply.toString();
}
Also used : Configuration(org.gradle.api.artifacts.Configuration)

Example 75 with Configuration

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

the class DynamicAddDependencyMethods method tryInvokeMethod.

@Override
public DynamicInvokeResult tryInvokeMethod(String name, Object... arguments) {
    if (arguments.length == 0) {
        return DynamicInvokeResult.notFound();
    }
    Configuration configuration = configurationContainer.findByName(name);
    if (configuration == null) {
        return DynamicInvokeResult.notFound();
    }
    List<?> normalizedArgs = CollectionUtils.flattenCollections(arguments);
    if (normalizedArgs.size() == 2 && normalizedArgs.get(1) instanceof Closure) {
        return DynamicInvokeResult.found(dependencyAdder.add(configuration, normalizedArgs.get(0), (Closure) normalizedArgs.get(1)));
    } else if (normalizedArgs.size() == 1) {
        return DynamicInvokeResult.found(dependencyAdder.add(configuration, normalizedArgs.get(0), null));
    } else {
        for (Object arg : normalizedArgs) {
            dependencyAdder.add(configuration, arg, null);
        }
        return DynamicInvokeResult.found();
    }
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) Closure(groovy.lang.Closure)

Aggregations

Configuration (org.gradle.api.artifacts.Configuration)85 Project (org.gradle.api.Project)11 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)11 File (java.io.File)10 Dependency (org.gradle.api.artifacts.Dependency)10 Callable (java.util.concurrent.Callable)9 ResolvedConfiguration (org.gradle.api.artifacts.ResolvedConfiguration)9 ResolvedProjectConfiguration (org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedProjectConfiguration)9 DependencySet (org.gradle.api.artifacts.DependencySet)8 DefaultLenientConfiguration (org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration)7 LinkedHashSet (java.util.LinkedHashSet)6 Usage (org.gradle.api.attributes.Usage)6 Action (org.gradle.api.Action)5 ConventionMapping (org.gradle.api.internal.ConventionMapping)5 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)4 IConventionAware (org.gradle.api.internal.IConventionAware)4 ArchivePublishArtifact (org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact)4 DefaultUsageContext (org.gradle.language.cpp.internal.DefaultUsageContext)4 Set (java.util.Set)3 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)3