Search in sources :

Example 11 with ModelRuleDescriptor

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

the class ModelNodeRenderer method printCreator.

public void printCreator(ModelNode model, StyledTextOutput styledTextoutput) {
    if (omitDetails()) {
        return;
    }
    ModelRuleDescriptor descriptor = model.getDescriptor();
    StringBuffer buffer = new StringBuffer();
    descriptor.describeTo(buffer);
    printNodeAttribute(styledTextoutput, "Creator:", buffer.toString());
}
Also used : ModelRuleDescriptor(org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor)

Example 12 with ModelRuleDescriptor

use of org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor 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 13 with ModelRuleDescriptor

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

the class ClosureBackedRuleFactory method toAction.

public <T> DeferredModelAction toAction(final Class<T> subjectType, final Closure<?> closure) {
    final TransformedClosure transformedClosure = (TransformedClosure) closure;
    SourceLocation sourceLocation = ruleLocationExtractor.transform(transformedClosure);
    final ModelRuleDescriptor descriptor = sourceLocation.asDescriptor();
    return new DeferredModelAction() {

        @Override
        public ModelRuleDescriptor getDescriptor() {
            return descriptor;
        }

        @Override
        public void execute(MutableModelNode node, ModelActionRole role) {
            final boolean supportsNestedRules = node.canBeViewedAs(MANAGED_INSTANCE_TYPE);
            InputReferences inputs = transformedClosure.inputReferences();
            List<InputReference> inputReferences = supportsNestedRules ? inputs.getOwnReferences() : inputs.getAllReferences();
            final Map<String, PotentialInput> inputValues = Maps.newLinkedHashMap();
            List<ModelReference<?>> inputModelReferences = Lists.newArrayList();
            for (InputReference inputReference : inputReferences) {
                String description = "@ line " + inputReference.getLineNumber();
                String path = inputReference.getPath();
                if (!inputValues.containsKey(path)) {
                    inputValues.put(path, new PotentialInput(inputModelReferences.size()));
                    inputModelReferences.add(ModelReference.untyped(ModelPath.path(path), description));
                }
            }
            node.applyToSelf(role, InputUsingModelAction.of(ModelReference.of(node.getPath(), subjectType), descriptor, inputModelReferences, new BiAction<T, List<ModelView<?>>>() {

                @Override
                public void execute(T t, List<ModelView<?>> modelViews) {
                    // Make a copy of the closure, attach inputs and execute
                    Closure<?> cloned = closure.rehydrate(null, closure.getThisObject(), closure.getThisObject());
                    ((TransformedClosure) cloned).makeRule(new PotentialInputs(modelViews, inputValues), supportsNestedRules ? ClosureBackedRuleFactory.this : null);
                    ClosureBackedAction.execute(t, cloned);
                }
            }));
        }
    };
}
Also used : DeferredModelAction(org.gradle.model.internal.core.DeferredModelAction) PotentialInput(org.gradle.model.dsl.internal.inputs.PotentialInput) BiAction(org.gradle.internal.BiAction) ModelActionRole(org.gradle.model.internal.core.ModelActionRole) ModelReference(org.gradle.model.internal.core.ModelReference) PotentialInputs(org.gradle.model.dsl.internal.inputs.PotentialInputs) ModelView(org.gradle.model.internal.core.ModelView) List(java.util.List) ModelRuleDescriptor(org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor) MutableModelNode(org.gradle.model.internal.core.MutableModelNode)

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