Search in sources :

Example 6 with ModelRuleDescriptor

use of org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor in project gradle by gradle.

the class NodeBackedModelMap method named.

@Override
public void named(String name, Class<? extends RuleSource> ruleSource) {
    viewState.assertCanMutate();
    ModelRuleDescriptor descriptor = sourceDescriptor.append("named(%s, %s)", name, ruleSource.getName());
    ModelReference<T> subject = ModelReference.of(modelNode.getPath().child(name), elementType);
    modelNode.defineRulesForLink(ModelActionRole.Defaults, new FilteringActionWrapper<T>(elementFilter, subject, DirectNodeNoInputsModelAction.of(subject, descriptor, new ApplyRuleSource(ruleSource))));
}
Also used : ModelRuleDescriptor(org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor)

Example 7 with ModelRuleDescriptor

use of org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor in project gradle by gradle.

the class NodeBackedModelMap method named.

@Override
public void named(String name, Action<? super T> configAction) {
    viewState.assertCanMutate();
    ModelRuleDescriptor descriptor = sourceDescriptor.append("named(%s)", name);
    ModelReference<T> subject = ModelReference.of(modelNode.getPath().child(name), elementType);
    modelNode.applyToLink(ModelActionRole.Mutate, new FilteringActionWrapper<T>(elementFilter, subject, NoInputsModelAction.of(subject, descriptor, configAction)));
}
Also used : ModelRuleDescriptor(org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor)

Example 8 with ModelRuleDescriptor

use of org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor in project gradle by gradle.

the class NodeBackedModelMap method mutateChildren.

private <E> void mutateChildren(ModelActionRole role, ModelType<E> filterType, String operation, Action<? super E> configAction) {
    viewState.assertCanMutate();
    ModelRuleDescriptor descriptor = sourceDescriptor.append(operation);
    ModelReference<E> subject = ModelReference.of(filterType);
    modelNode.applyTo(allLinks(elementFilter.withType(filterType)), role, NoInputsModelAction.of(subject, descriptor, configAction));
}
Also used : ModelRuleDescriptor(org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor)

Example 9 with ModelRuleDescriptor

use of org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor in project gradle by gradle.

the class NodeBackedModelMap method put.

@Override
public void put(String name, T instance) {
    Class<T> type = Cast.uncheckedCast(instance.getClass());
    ModelRuleDescriptor descriptor = sourceDescriptor.append("put()");
    if (instance instanceof ManagedInstance) {
        ManagedInstance target = (ManagedInstance) instance;
        modelNode.addReference(name, target.getManagedType(), target.getBackingNode(), descriptor);
    } else {
        modelNode.addLink(ModelRegistrations.unmanagedInstance(ModelReference.of(modelNode.getPath().child(name), type), Factories.constant(instance)).descriptor(descriptor).build());
    }
}
Also used : ManagedInstance(org.gradle.model.internal.manage.instance.ManagedInstance) ModelRuleDescriptor(org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor)

Example 10 with ModelRuleDescriptor

use of org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor in project gradle by gradle.

the class NodeBackedModelSet method create.

@Override
public void create(final Action<? super T> action) {
    state.assertCanMutate();
    String name = String.valueOf(modelNode.getLinkCount(ModelNodes.withType(elementType)));
    ModelPath childPath = modelNode.getPath().child(name);
    final ModelRuleDescriptor descriptor = this.descriptor.append("create()");
    NodeInitializer nodeInitializer = creatorStrategy.initializer(elementType, Specs.<ModelType<?>>satisfyAll());
    ModelRegistration registration = ModelRegistrations.of(childPath, nodeInitializer).descriptor(descriptor).action(ModelActionRole.Initialize, NoInputsModelAction.of(ModelReference.of(childPath, elementType), descriptor, action)).build();
    modelNode.addLink(registration);
}
Also used : ModelRuleDescriptor(org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor)

Aggregations

ModelRuleDescriptor (org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor)13 ModelPath (org.gradle.model.internal.core.ModelPath)2 ModelView (org.gradle.model.internal.core.ModelView)2 SimpleModelRuleDescriptor (org.gradle.model.internal.core.rule.describe.SimpleModelRuleDescriptor)2 List (java.util.List)1 BiAction (org.gradle.internal.BiAction)1 InvalidModelRuleDeclarationException (org.gradle.model.InvalidModelRuleDeclarationException)1 InvalidModelRuleException (org.gradle.model.InvalidModelRuleException)1 ModelRuleBindingException (org.gradle.model.ModelRuleBindingException)1 PotentialInput (org.gradle.model.dsl.internal.inputs.PotentialInput)1 PotentialInputs (org.gradle.model.dsl.internal.inputs.PotentialInputs)1 DeferredModelAction (org.gradle.model.internal.core.DeferredModelAction)1 ModelAction (org.gradle.model.internal.core.ModelAction)1 ModelActionRole (org.gradle.model.internal.core.ModelActionRole)1 ModelReference (org.gradle.model.internal.core.ModelReference)1 ModelRuleExecutionException (org.gradle.model.internal.core.ModelRuleExecutionException)1 MutableModelNode (org.gradle.model.internal.core.MutableModelNode)1 NodeInitializer (org.gradle.model.internal.core.NodeInitializer)1 NodeInitializerRegistry (org.gradle.model.internal.core.NodeInitializerRegistry)1 ManagedInstance (org.gradle.model.internal.manage.instance.ManagedInstance)1