Search in sources :

Example 1 with Capability

use of org.gradle.api.capabilities.Capability in project gradle by gradle.

the class NodeState method findCapability.

@Nullable
public Capability findCapability(String group, String name) {
    Capability onComponent = component.findCapability(group, name);
    if (onComponent != null) {
        return onComponent;
    }
    List<? extends Capability> capabilities = metaData.getCapabilities().getCapabilities();
    if (!capabilities.isEmpty()) {
        // Not required, but Guava's performance bad for an empty immutable list
        for (Capability capability : capabilities) {
            if (capability.getGroup().equals(group) && capability.getName().equals(name)) {
                return capability;
            }
        }
    }
    return null;
}
Also used : Capability(org.gradle.api.capabilities.Capability) ShadowedCapability(org.gradle.internal.component.external.model.ShadowedCapability) Nullable(javax.annotation.Nullable)

Example 2 with Capability

use of org.gradle.api.capabilities.Capability in project gradle by gradle.

the class UpgradeCapabilityResolver method resolve.

@Override
public void resolve(CapabilitiesConflictHandler.ResolutionDetails details) {
    Collection<? extends Capability> capabilityVersions = details.getCapabilityVersions();
    if (capabilityVersions.size() > 1) {
        Set<Capability> sorted = Sets.newTreeSet((o1, o2) -> {
            VersionNumber v1 = VersionNumber.parse(o1.getVersion());
            VersionNumber v2 = VersionNumber.parse(o2.getVersion());
            return v2.compareTo(v1);
        });
        sorted.addAll(capabilityVersions);
        boolean first = true;
        for (Capability capability : sorted) {
            DisplayName reason = Describables.of("latest version of capability", ((CapabilityInternal) capability).getCapabilityId());
            boolean isFirst = first;
            details.getCandidates(capability).forEach(cand -> {
                cand.byReason(reason);
                if (!isFirst) {
                    cand.evict();
                }
            });
            first = false;
        }
    }
}
Also used : Capability(org.gradle.api.capabilities.Capability) DisplayName(org.gradle.internal.DisplayName) VersionNumber(org.gradle.util.internal.VersionNumber)

Example 3 with Capability

use of org.gradle.api.capabilities.Capability in project gradle by gradle.

the class DependencyManagementBuildScopeServices method createDependencyFactory.

DependencyFactory createDependencyFactory(Instantiator instantiator, DefaultProjectDependencyFactory factory, ClassPathRegistry classPathRegistry, CurrentGradleInstallation currentGradleInstallation, FileCollectionFactory fileCollectionFactory, RuntimeShadedJarFactory runtimeShadedJarFactory, ImmutableAttributesFactory attributesFactory, SimpleMapInterner stringInterner) {
    NotationParser<Object, Capability> capabilityNotationParser = new CapabilityNotationParserFactory(false).create();
    ProjectDependencyFactory projectDependencyFactory = new ProjectDependencyFactory(factory);
    return new DefaultDependencyFactory(DependencyNotationParser.parser(instantiator, factory, classPathRegistry, fileCollectionFactory, runtimeShadedJarFactory, currentGradleInstallation, stringInterner, attributesFactory, capabilityNotationParser), DependencyConstraintNotationParser.parser(instantiator, factory, stringInterner, attributesFactory), new ClientModuleNotationParserFactory(instantiator, stringInterner).create(), capabilityNotationParser, projectDependencyFactory, attributesFactory);
}
Also used : Capability(org.gradle.api.capabilities.Capability) ClientModuleNotationParserFactory(org.gradle.api.internal.notations.ClientModuleNotationParserFactory) ProjectDependencyFactory(org.gradle.api.internal.notations.ProjectDependencyFactory) CapabilityNotationParserFactory(org.gradle.api.internal.artifacts.dsl.CapabilityNotationParserFactory)

Example 4 with Capability

use of org.gradle.api.capabilities.Capability in project gradle by gradle.

the class DefaultConfigurationPublications method capability.

@Override
public void capability(Object notation) {
    if (canCreate) {
        Capability descriptor = capabilityNotationParser.parseNotation(notation);
        if (capabilities == null) {
            // it's rare that a component would declare more than 1 capability
            capabilities = Lists.newArrayListWithExpectedSize(1);
        }
        capabilities.add(descriptor);
    } else {
        throw new InvalidUserCodeException("Cannot declare capability '" + notation + "' after dependency " + displayName + " has been resolved");
    }
}
Also used : Capability(org.gradle.api.capabilities.Capability) InvalidUserCodeException(org.gradle.api.InvalidUserCodeException)

Example 5 with Capability

use of org.gradle.api.capabilities.Capability in project gradle by gradle.

the class ModuleComponentSelectorSerializer method writeCapabilities.

private void writeCapabilities(Encoder encoder, Collection<Capability> capabilities) throws IOException {
    encoder.writeSmallInt(capabilities.size());
    for (Capability capability : capabilities) {
        encoder.writeString(capability.getGroup());
        encoder.writeString(capability.getName());
        encoder.writeNullableString(capability.getVersion());
    }
}
Also used : ImmutableCapability(org.gradle.internal.component.external.model.ImmutableCapability) Capability(org.gradle.api.capabilities.Capability)

Aggregations

Capability (org.gradle.api.capabilities.Capability)21 ImmutableCapability (org.gradle.internal.component.external.model.ImmutableCapability)7 VersionConstraint (org.gradle.api.artifacts.VersionConstraint)3 DefaultImmutableVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)3 ShadowedCapability (org.gradle.internal.component.external.model.ShadowedCapability)3 ImmutableList (com.google.common.collect.ImmutableList)2 DependencyConstraint (org.gradle.api.artifacts.DependencyConstraint)2 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)2 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)2 AttributeContainer (org.gradle.api.attributes.AttributeContainer)2 DefaultResolvedVariantResult (org.gradle.api.internal.artifacts.result.DefaultResolvedVariantResult)2 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 UsageContext (org.gradle.api.internal.component.UsageContext)2 DisplayName (org.gradle.internal.DisplayName)2 DefaultShadowedCapability (org.gradle.internal.component.external.model.DefaultShadowedCapability)2 ProjectDerivedCapability (org.gradle.internal.component.external.model.ProjectDerivedCapability)2 Nullable (javax.annotation.Nullable)1 InvalidUserCodeException (org.gradle.api.InvalidUserCodeException)1 Configuration (org.gradle.api.artifacts.Configuration)1 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)1