Search in sources :

Example 1 with ModelRuleDescriptor

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

the class ModelBinding method onBind.

public final void onBind(ModelNodeInternal node) {
    if (boundTo != null) {
        ModelRuleDescriptor creatorDescriptor = node.getDescriptor();
        ModelPath path = node.getPath();
        throw new InvalidModelRuleException(referrer, new ModelRuleBindingException(new AmbiguousBindingReporter(predicate.getReference(), boundTo.getPath(), boundTo.getDescriptor(), path, creatorDescriptor).asString()));
    }
    doOnBind(node);
}
Also used : InvalidModelRuleException(org.gradle.model.InvalidModelRuleException) ModelPath(org.gradle.model.internal.core.ModelPath) ModelRuleBindingException(org.gradle.model.ModelRuleBindingException) AmbiguousBindingReporter(org.gradle.model.internal.report.AmbiguousBindingReporter) ModelRuleDescriptor(org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor)

Example 2 with ModelRuleDescriptor

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

the class TransformedModelDslBacking method create.

/**
     * Invoked by transformed DSL creation rules
     */
public <T> void create(String modelPathString, Class<T> type, Closure<?> closure) {
    ModelPath modelPath = ModelPath.path(modelPathString);
    DeferredModelAction modelAction = ruleFactory.toAction(type, closure);
    ModelRuleDescriptor descriptor = modelAction.getDescriptor();
    ModelType<T> modelType = ModelType.of(type);
    try {
        NodeInitializerRegistry nodeInitializerRegistry = modelRegistry.realize(DEFAULT_REFERENCE.getPath(), DEFAULT_REFERENCE.getType());
        NodeInitializer nodeInitializer = nodeInitializerRegistry.getNodeInitializer(forType(modelType));
        modelRegistry.register(ModelRegistrations.of(modelPath, nodeInitializer).descriptor(descriptor).build());
    } catch (ModelTypeInitializationException e) {
        throw new InvalidModelRuleDeclarationException(descriptor, e);
    }
    registerAction(modelPath, modelType, ModelActionRole.Initialize, modelAction);
}
Also used : InvalidModelRuleDeclarationException(org.gradle.model.InvalidModelRuleDeclarationException) ModelRuleDescriptor(org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor)

Example 3 with ModelRuleDescriptor

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

the class NodeBackedModelMap method doCreate.

private <S extends T> void doCreate(String name, ModelType<S> type, @Nullable Action<? super S> initAction) {
    ModelPath childPath = modelNode.getPath().child(name);
    ModelRuleDescriptor descriptor = sourceDescriptor.append("create(%s)", name);
    if (initAction != null) {
        doCreate(childPath, type, descriptor, NoInputsModelAction.of(ModelReference.of(childPath, type), descriptor, initAction));
    } else {
        doCreate(childPath, type, descriptor, null);
    }
}
Also used : ModelRuleDescriptor(org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor)

Example 4 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 5 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 : PotentialInput(org.gradle.model.dsl.internal.inputs.PotentialInput) BiAction(org.gradle.internal.BiAction) PotentialInputs(org.gradle.model.dsl.internal.inputs.PotentialInputs) List(java.util.List) 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 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 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 AmbiguousBindingReporter (org.gradle.model.internal.report.AmbiguousBindingReporter)1