Search in sources :

Example 31 with AttributeContainer

use of org.gradle.api.attributes.AttributeContainer in project gradle by gradle.

the class NodeState method getResolvedVariant.

public ResolvedVariantResult getResolvedVariant() {
    if (cachedVariantResult != null) {
        return cachedVariantResult;
    }
    DisplayName name = Describables.of(metaData.getName());
    List<? extends Capability> capabilities = metaData.getCapabilities().getCapabilities();
    AttributeContainer attributes = desugar(metaData.getAttributes());
    List<Capability> resolvedVariantCapabilities = capabilities.isEmpty() ? Collections.singletonList(component.getImplicitCapability()) : ImmutableList.copyOf(capabilities);
    cachedVariantResult = new DefaultResolvedVariantResult(component.getComponentId(), name, attributes, resolvedVariantCapabilities, findExternalVariant());
    return cachedVariantResult;
}
Also used : Capability(org.gradle.api.capabilities.Capability) ShadowedCapability(org.gradle.internal.component.external.model.ShadowedCapability) DefaultResolvedVariantResult(org.gradle.api.internal.artifacts.result.DefaultResolvedVariantResult) DisplayName(org.gradle.internal.DisplayName) AttributeContainer(org.gradle.api.attributes.AttributeContainer)

Example 32 with AttributeContainer

use of org.gradle.api.attributes.AttributeContainer in project gradle by gradle.

the class Dimensions method variants.

private static void variants(Provider<String> baseName, Collection<BuildType> buildTypes, Collection<TargetMachine> targetMachines, ObjectFactory objectFactory, ImmutableAttributesFactory attributesFactory, // TODO: These should come from somewhere else, probably
Provider<String> group, Provider<String> version, Action<NativeVariantIdentity> action) {
    for (BuildType buildType : buildTypes) {
        for (TargetMachine targetMachine : targetMachines) {
            Usage runtimeUsage = objectFactory.named(Usage.class, Usage.NATIVE_RUNTIME);
            List<String> variantNameToken = Lists.newArrayList();
            // FIXME: Always build type name to keep parity with previous Gradle version in tooling API
            variantNameToken.add(buildType.getName());
            variantNameToken.add(createDimensionSuffix(targetMachine.getOperatingSystemFamily(), targetMachinesToOperatingSystems(targetMachines)));
            variantNameToken.add(createDimensionSuffix(targetMachine.getArchitecture(), targetMachinesToArchitectures(targetMachines)));
            String variantName = StringUtils.uncapitalize(String.join("", variantNameToken));
            AttributeContainer runtimeAttributes = attributesFactory.mutable();
            runtimeAttributes.attribute(Usage.USAGE_ATTRIBUTE, runtimeUsage);
            addCommonAttributes(buildType, targetMachine, runtimeAttributes);
            DefaultUsageContext runtimeUsageContext = new DefaultUsageContext(variantName + "Runtime", runtimeAttributes);
            DefaultUsageContext linkUsageContext = null;
            NativeVariantIdentity variantIdentity = new NativeVariantIdentity(variantName, baseName, group, version, buildType.isDebuggable(), buildType.isOptimized(), targetMachine, linkUsageContext, runtimeUsageContext, null);
            action.execute(variantIdentity);
        }
    }
}
Also used : Usage(org.gradle.api.attributes.Usage) TargetMachine(org.gradle.nativeplatform.TargetMachine) DefaultUsageContext(org.gradle.language.cpp.internal.DefaultUsageContext) AttributeContainer(org.gradle.api.attributes.AttributeContainer) NativeVariantIdentity(org.gradle.language.cpp.internal.NativeVariantIdentity)

Example 33 with AttributeContainer

use of org.gradle.api.attributes.AttributeContainer in project gradle by gradle.

the class Dimensions method variants.

private static void variants(Provider<String> baseName, Collection<BuildType> buildTypes, Collection<Linkage> linkages, Collection<TargetMachine> targetMachines, ObjectFactory objectFactory, ImmutableAttributesFactory attributesFactory, // TODO: These should come from somewhere else, probably
Provider<String> group, Provider<String> version, Action<NativeVariantIdentity> action) {
    for (BuildType buildType : buildTypes) {
        for (Linkage linkage : linkages) {
            for (TargetMachine targetMachine : targetMachines) {
                Usage runtimeUsage = objectFactory.named(Usage.class, Usage.NATIVE_RUNTIME);
                Usage linkUsage = objectFactory.named(Usage.class, Usage.NATIVE_LINK);
                List<String> variantNameToken = Lists.newArrayList();
                // FIXME: Always build type name to keep parity with previous Gradle version in tooling API
                variantNameToken.add(buildType.getName());
                variantNameToken.add(createDimensionSuffix(linkage, linkages));
                variantNameToken.add(createDimensionSuffix(targetMachine.getOperatingSystemFamily(), targetMachinesToOperatingSystems(targetMachines)));
                variantNameToken.add(createDimensionSuffix(targetMachine.getArchitecture(), targetMachinesToArchitectures(targetMachines)));
                String variantName = StringUtils.uncapitalize(String.join("", variantNameToken));
                AttributeContainer runtimeAttributes = attributesFactory.mutable();
                runtimeAttributes.attribute(Usage.USAGE_ATTRIBUTE, runtimeUsage);
                addCommonAttributes(buildType, targetMachine, runtimeAttributes);
                runtimeAttributes.attribute(LINKAGE_ATTRIBUTE, linkage);
                DefaultUsageContext runtimeUsageContext = new DefaultUsageContext(variantName + "Runtime", runtimeAttributes);
                AttributeContainer linkAttributes = attributesFactory.mutable();
                linkAttributes.attribute(Usage.USAGE_ATTRIBUTE, linkUsage);
                addCommonAttributes(buildType, targetMachine, linkAttributes);
                linkAttributes.attribute(LINKAGE_ATTRIBUTE, linkage);
                DefaultUsageContext linkUsageContext = new DefaultUsageContext(variantName + "Link", linkAttributes);
                NativeVariantIdentity variantIdentity = new NativeVariantIdentity(variantName, baseName, group, version, buildType.isDebuggable(), buildType.isOptimized(), targetMachine, linkUsageContext, runtimeUsageContext, linkage);
                action.execute(variantIdentity);
            }
        }
    }
}
Also used : Usage(org.gradle.api.attributes.Usage) Linkage(org.gradle.nativeplatform.Linkage) TargetMachine(org.gradle.nativeplatform.TargetMachine) DefaultUsageContext(org.gradle.language.cpp.internal.DefaultUsageContext) AttributeContainer(org.gradle.api.attributes.AttributeContainer) NativeVariantIdentity(org.gradle.language.cpp.internal.NativeVariantIdentity)

Example 34 with AttributeContainer

use of org.gradle.api.attributes.AttributeContainer in project gradle by gradle.

the class AttributeDesugaring method desugarSelector.

public ComponentSelector desugarSelector(ComponentSelector selector) {
    if (selector instanceof ModuleComponentSelector) {
        ModuleComponentSelector module = (ModuleComponentSelector) selector;
        AttributeContainer moduleAttributes = module.getAttributes();
        if (!moduleAttributes.isEmpty()) {
            ImmutableAttributes attributes = ((AttributeContainerInternal) moduleAttributes).asImmutable();
            return DefaultModuleComponentSelector.newSelector(module.getModuleIdentifier(), module.getVersionConstraint(), desugar(attributes), module.getRequestedCapabilities());
        }
    }
    if (selector instanceof DefaultProjectComponentSelector) {
        DefaultProjectComponentSelector project = (DefaultProjectComponentSelector) selector;
        AttributeContainer projectAttributes = project.getAttributes();
        if (!projectAttributes.isEmpty()) {
            ImmutableAttributes attributes = ((AttributeContainerInternal) projectAttributes).asImmutable();
            return new DefaultProjectComponentSelector(project.getBuildIdentifier(), project.getIdentityPath(), project.projectPath(), project.getProjectName(), desugar(attributes), project.getRequestedCapabilities());
        }
    }
    return selector;
}
Also used : DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DefaultProjectComponentSelector(org.gradle.internal.component.local.model.DefaultProjectComponentSelector) AttributeContainer(org.gradle.api.attributes.AttributeContainer)

Aggregations

AttributeContainer (org.gradle.api.attributes.AttributeContainer)34 Usage (org.gradle.api.attributes.Usage)14 Configuration (org.gradle.api.artifacts.Configuration)13 Project (org.gradle.api.Project)7 DefaultUsageContext (org.gradle.language.cpp.internal.DefaultUsageContext)7 NativeVariantIdentity (org.gradle.language.cpp.internal.NativeVariantIdentity)7 Bundling (org.gradle.api.attributes.Bundling)6 Callable (java.util.concurrent.Callable)5 Action (org.gradle.api.Action)5 ObjectFactory (org.gradle.api.model.ObjectFactory)5 Provider (org.gradle.api.provider.Provider)5 OperatingSystemFamily (org.gradle.nativeplatform.OperatingSystemFamily)5 File (java.io.File)4 Set (java.util.Set)4 Attribute (org.gradle.api.attributes.Attribute)4 Category (org.gradle.api.attributes.Category)4 Task (org.gradle.api.Task)3 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)3 LibraryElements (org.gradle.api.attributes.LibraryElements)3 Capability (org.gradle.api.capabilities.Capability)3