Search in sources :

Example 1 with InstantiatingAction

use of org.gradle.internal.action.InstantiatingAction in project gradle by gradle.

the class DefaultComponentMetadataProcessor method processMetadata.

@Override
public ModuleComponentResolveMetadata processMetadata(ModuleComponentResolveMetadata origin) {
    VariantDerivationStrategy curStrategy = metadataRuleContainer.getVariantDerivationStrategy();
    ModuleComponentResolveMetadata metadata = origin.withDerivationStrategy(curStrategy);
    ModuleComponentResolveMetadata updatedMetadata;
    if (metadataRuleContainer.isEmpty()) {
        updatedMetadata = maybeForceRealisation(metadata);
    } else if (metadataRuleContainer.isClassBasedRulesOnly()) {
        Action<ComponentMetadataContext> action = collectRulesAndCreateAction(metadataRuleContainer.getOnlyClassRules(), metadata.getModuleVersionId(), metadataResolutionContext.getInjectingInstantiator());
        if (action instanceof InstantiatingAction) {
            InstantiatingAction<ComponentMetadataContext> ia = (InstantiatingAction<ComponentMetadataContext>) action;
            if (shouldCacheComponentMetadataRule(ia, metadata)) {
                updatedMetadata = processClassRuleWithCaching(ia, metadata, metadataResolutionContext);
            } else {
                MutableModuleComponentResolveMetadata mutableMetadata = metadata.asMutable();
                processClassRule(action, metadata, createDetails(mutableMetadata));
                updatedMetadata = maybeForceRealisation(mutableMetadata.asImmutable());
            }
        } else {
            updatedMetadata = maybeForceRealisation(metadata);
        }
    } else {
        MutableModuleComponentResolveMetadata mutableMetadata = metadata.asMutable();
        ComponentMetadataDetails details = createDetails(mutableMetadata);
        processAllRules(metadata, details, metadata.getModuleVersionId());
        updatedMetadata = maybeForceRealisation(mutableMetadata.asImmutable());
    }
    if (!updatedMetadata.getStatusScheme().contains(updatedMetadata.getStatus())) {
        throw new ModuleVersionResolveException(updatedMetadata.getModuleVersionId(), () -> String.format("Unexpected status '%s' specified for %s. Expected one of: %s", updatedMetadata.getStatus(), updatedMetadata.getId().getDisplayName(), updatedMetadata.getStatusScheme()));
    }
    return updatedMetadata;
}
Also used : MutableModuleComponentResolveMetadata(org.gradle.internal.component.external.model.MutableModuleComponentResolveMetadata) MutableModuleComponentResolveMetadata(org.gradle.internal.component.external.model.MutableModuleComponentResolveMetadata) ModuleComponentResolveMetadata(org.gradle.internal.component.external.model.ModuleComponentResolveMetadata) Action(org.gradle.api.Action) InstantiatingAction(org.gradle.internal.action.InstantiatingAction) RuleAction(org.gradle.internal.rules.RuleAction) SpecRuleAction(org.gradle.internal.rules.SpecRuleAction) ComponentMetadataContext(org.gradle.api.artifacts.ComponentMetadataContext) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) VariantDerivationStrategy(org.gradle.internal.component.external.model.VariantDerivationStrategy) InstantiatingAction(org.gradle.internal.action.InstantiatingAction) ComponentMetadataDetails(org.gradle.api.artifacts.ComponentMetadataDetails)

Example 2 with InstantiatingAction

use of org.gradle.internal.action.InstantiatingAction in project gradle by gradle.

the class DefaultMetadataProvider method getComponentMetadataFromSupplier.

private ComponentMetadata getComponentMetadataFromSupplier(InstantiatingAction<ComponentMetadataSupplierDetails> componentMetadataSupplier) {
    ComponentMetadata metadata;
    ModuleVersionIdentifier id = DefaultModuleVersionIdentifier.newId(resolveState.getId());
    metadata = resolveState.getComponentMetadataSupplierExecutor().execute(id, componentMetadataSupplier, TO_COMPONENT_METADATA, id1 -> {
        final SimpleComponentMetadataBuilder builder = new SimpleComponentMetadataBuilder(id1, resolveState.getAttributesFactory());
        return new BuildableComponentMetadataSupplierDetails(builder);
    }, resolveState.getCachePolicy());
    return metadata;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DefaultModuleVersionIdentifier(org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier) DefaultIvyModuleDescriptor(org.gradle.api.internal.artifacts.ivyservice.DefaultIvyModuleDescriptor) IvyModuleDescriptor(org.gradle.api.artifacts.ivy.IvyModuleDescriptor) ComponentMetadataSupplierDetails(org.gradle.api.artifacts.ComponentMetadataSupplierDetails) CachePolicy(org.gradle.api.internal.artifacts.configurations.dynamicversion.CachePolicy) MavenVersionUtils(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.MavenVersionUtils) Lists(com.google.common.collect.Lists) ComponentMetadataAdapter(org.gradle.api.internal.artifacts.repositories.resolver.ComponentMetadataAdapter) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) AttributeContainer(org.gradle.api.attributes.AttributeContainer) Attribute(org.gradle.api.attributes.Attribute) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ModuleComponentResolveMetadata(org.gradle.internal.component.external.model.ModuleComponentResolveMetadata) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) IvyModuleResolveMetadata(org.gradle.internal.component.external.model.ivy.IvyModuleResolveMetadata) DefaultModuleVersionIdentifier(org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier) ComponentMetadataBuilder(org.gradle.api.artifacts.ComponentMetadataBuilder) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) Nullable(javax.annotation.Nullable) Transformer(org.gradle.api.Transformer) ImmutableAttributesFactory(org.gradle.api.internal.attributes.ImmutableAttributesFactory) MetadataResolutionContext(org.gradle.api.internal.artifacts.MetadataResolutionContext) Action(org.gradle.api.Action) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) Instantiator(org.gradle.internal.reflect.Instantiator) List(java.util.List) ComponentMetadata(org.gradle.api.artifacts.ComponentMetadata) TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) InstantiatingAction(org.gradle.internal.action.InstantiatingAction) BuildableModuleComponentMetaDataResolveResult(org.gradle.internal.resolve.result.BuildableModuleComponentMetaDataResolveResult) InvalidUserDataException(org.gradle.api.InvalidUserDataException) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal) ComponentMetadata(org.gradle.api.artifacts.ComponentMetadata)

Aggregations

Action (org.gradle.api.Action)2 InstantiatingAction (org.gradle.internal.action.InstantiatingAction)2 ModuleComponentResolveMetadata (org.gradle.internal.component.external.model.ModuleComponentResolveMetadata)2 Lists (com.google.common.collect.Lists)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 Transformer (org.gradle.api.Transformer)1 ComponentMetadata (org.gradle.api.artifacts.ComponentMetadata)1 ComponentMetadataBuilder (org.gradle.api.artifacts.ComponentMetadataBuilder)1 ComponentMetadataContext (org.gradle.api.artifacts.ComponentMetadataContext)1 ComponentMetadataDetails (org.gradle.api.artifacts.ComponentMetadataDetails)1 ComponentMetadataSupplierDetails (org.gradle.api.artifacts.ComponentMetadataSupplierDetails)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)1 IvyModuleDescriptor (org.gradle.api.artifacts.ivy.IvyModuleDescriptor)1 Attribute (org.gradle.api.attributes.Attribute)1 AttributeContainer (org.gradle.api.attributes.AttributeContainer)1 DefaultModuleVersionIdentifier (org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier)1 MetadataResolutionContext (org.gradle.api.internal.artifacts.MetadataResolutionContext)1