Search in sources :

Example 1 with ModelAction

use of org.gradle.model.internal.core.ModelAction in project gradle by gradle.

the class RuleExtractorUtils method configureRuleAction.

public static void configureRuleAction(MethodModelRuleApplicationContext context, RuleApplicationScope ruleApplicationScope, ModelActionRole role, MethodRuleAction ruleAction) {
    ModelAction action = context.contextualize(ruleAction);
    ModelRegistry registry = context.getRegistry();
    switch(ruleApplicationScope) {
        case SELF:
            registry.configure(role, action);
            break;
        case DESCENDANTS:
            registry.configureMatching(new NonReferenceDescendantsSpec(context.getScope()), role, action);
            break;
        default:
            throw new AssertionError();
    }
}
Also used : ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) ModelAction(org.gradle.model.internal.core.ModelAction)

Example 2 with ModelAction

use of org.gradle.model.internal.core.ModelAction in project gradle by gradle.

the class DefaultModelRegistry method fireAction.

private void fireAction(RuleBinder boundMutator) {
    final List<ModelView<?>> inputs = toViews(boundMutator.getInputBindings(), boundMutator.getAction().getDescriptor());
    ModelBinding subjectBinding = boundMutator.getSubjectBinding();
    final ModelNodeInternal node = subjectBinding.getNode();
    final ModelAction mutator = boundMutator.getAction();
    ModelRuleDescriptor descriptor = mutator.getDescriptor();
    LOGGER.debug("Project {} - Mutating {} using {}", projectPath, node.getPath(), descriptor);
    try {
        RuleContext.run(descriptor, new Runnable() {

            @Override
            public void run() {
                mutator.execute(node, inputs);
            }
        });
    } catch (Throwable e) {
        // TODO some representation of state of the inputs
        throw new ModelRuleExecutionException(descriptor, e);
    }
}
Also used : ModelRuleExecutionException(org.gradle.model.internal.core.ModelRuleExecutionException) ModelView(org.gradle.model.internal.core.ModelView) ModelAction(org.gradle.model.internal.core.ModelAction) ModelRuleDescriptor(org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor) SimpleModelRuleDescriptor(org.gradle.model.internal.core.rule.describe.SimpleModelRuleDescriptor)

Example 3 with ModelAction

use of org.gradle.model.internal.core.ModelAction in project gradle by gradle.

the class DefaultModelRegistry method addRuleBindings.

private void addRuleBindings(ModelNodeInternal node, Multimap<ModelActionRole, ? extends ModelAction> actions) {
    for (Map.Entry<ModelActionRole, ? extends ModelAction> entry : actions.entries()) {
        ModelActionRole role = entry.getKey();
        ModelAction action = entry.getValue();
        checkNodePath(node, action);
        RuleBinder binder = bindInternal(action.getSubject(), role, action);
        node.addRegistrationActionBinder(binder);
    }
}
Also used : ModelAction(org.gradle.model.internal.core.ModelAction) HashMap(java.util.HashMap) Map(java.util.Map) ModelActionRole(org.gradle.model.internal.core.ModelActionRole)

Aggregations

ModelAction (org.gradle.model.internal.core.ModelAction)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ModelActionRole (org.gradle.model.internal.core.ModelActionRole)1 ModelRuleExecutionException (org.gradle.model.internal.core.ModelRuleExecutionException)1 ModelView (org.gradle.model.internal.core.ModelView)1 ModelRuleDescriptor (org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor)1 SimpleModelRuleDescriptor (org.gradle.model.internal.core.rule.describe.SimpleModelRuleDescriptor)1 ModelRegistry (org.gradle.model.internal.registry.ModelRegistry)1