Search in sources :

Example 6 with ModelPath

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

the class ModelElementNode method addNode.

private void addNode(ModelNodeInternal child, ModelRegistration registration) {
    ModelPath childPath = child.getPath();
    if (!getPath().isDirectChild(childPath)) {
        throw new IllegalArgumentException(String.format("Element registration has a path (%s) which is not a child of this node (%s).", childPath, getPath()));
    }
    ModelNodeInternal currentChild = links == null ? null : links.get(childPath.getName());
    if (currentChild != null) {
        if (!currentChild.isAtLeast(Created)) {
            throw new DuplicateModelException(String.format("Cannot create '%s' using creation rule '%s' as the rule '%s' is already registered to create this model element.", childPath, describe(registration.getDescriptor()), describe(currentChild.getDescriptor())));
        }
        throw new DuplicateModelException(String.format("Cannot create '%s' using creation rule '%s' as the rule '%s' has already been used to create this model element.", childPath, describe(registration.getDescriptor()), describe(currentChild.getDescriptor())));
    }
    if (!isMutable()) {
        throw new IllegalStateException(String.format("Cannot create '%s' using creation rule '%s' as model element '%s' is no longer mutable.", childPath, describe(registration.getDescriptor()), getPath()));
    }
    if (links == null) {
        links = Maps.newTreeMap();
    }
    links.put(child.getPath().getName(), child);
    modelRegistry.registerNode(child, registration.getActions());
}
Also used : DuplicateModelException(org.gradle.model.internal.core.DuplicateModelException) ModelPath(org.gradle.model.internal.core.ModelPath)

Example 7 with ModelPath

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

the class ModelGraph method doNotify.

private void doNotify(ModelNodeInternal node) {
    notifying = true;
    try {
        notifyListeners(node, pathListeners.get(node.getPath()));
        notifyListeners(node, parentListeners.get(node.getPath().getParent()));
        notifyListeners(node, listeners);
        if (!ancestorListeners.isEmpty()) {
            // Don't traverse path back to root when there is nothing that can possibly match
            for (ModelPath path = node.getPath().getParent(); path != null; path = path.getParent()) {
                notifyListeners(node, ancestorListeners.get(path));
            }
        }
    } finally {
        notifying = false;
    }
}
Also used : ModelPath(org.gradle.model.internal.core.ModelPath)

Example 8 with ModelPath

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

the class IncompatibleTypeReferenceReporter method of.

public static IncompatibleTypeReferenceReporter of(MutableModelNode node, ModelType<?> type, String description, boolean writable) {
    ModelPath path = node.getPath();
    ModelRuleDescriptor creatorDescriptor = node.getDescriptor();
    return new IncompatibleTypeReferenceReporter(creatorDescriptor.toString(), path.toString(), type.toString(), description, writable, node.getTypeDescriptions());
}
Also used : ModelPath(org.gradle.model.internal.core.ModelPath) ModelRuleDescriptor(org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor)

Example 9 with ModelPath

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

the class AbstractModelCreationRuleExtractor method registration.

@Nullable
@Override
public <R, S> ExtractedModelRule registration(MethodRuleDefinition<R, S> ruleDefinition, MethodModelRuleExtractionContext context) {
    ModelPath modelPath = determineModelName(ruleDefinition, context);
    validateMethod(ruleDefinition, context);
    if (context.hasProblems()) {
        return null;
    }
    return buildRule(modelPath, ruleDefinition);
}
Also used : ModelPath(org.gradle.model.internal.core.ModelPath) Nullable(javax.annotation.Nullable)

Example 10 with ModelPath

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

the class DefaultModelRegistry method register.

@Override
public DefaultModelRegistry register(ModelRegistration registration) {
    ModelPath path = registration.getPath();
    if (!ModelPath.ROOT.isDirectChild(path)) {
        throw new InvalidModelRuleDeclarationException(registration.getDescriptor(), "Cannot register element at '" + path + "', only top level is allowed (e.g. '" + path.getRootParent() + "')");
    }
    ModelNodeInternal root = modelGraph.getRoot();
    root.addLink(registration);
    return this;
}
Also used : ModelPath(org.gradle.model.internal.core.ModelPath) InvalidModelRuleDeclarationException(org.gradle.model.InvalidModelRuleDeclarationException)

Aggregations

ModelPath (org.gradle.model.internal.core.ModelPath)10 ModelRuleDescriptor (org.gradle.model.internal.core.rule.describe.ModelRuleDescriptor)2 Annotation (java.lang.annotation.Annotation)1 Nullable (javax.annotation.Nullable)1 Spec (org.gradle.api.specs.Spec)1 InvalidModelRuleDeclarationException (org.gradle.model.InvalidModelRuleDeclarationException)1 InvalidModelRuleException (org.gradle.model.InvalidModelRuleException)1 ModelRuleBindingException (org.gradle.model.ModelRuleBindingException)1 Path (org.gradle.model.Path)1 DuplicateModelException (org.gradle.model.internal.core.DuplicateModelException)1 ModelNode (org.gradle.model.internal.core.ModelNode)1 State (org.gradle.model.internal.core.ModelNode.State)1 MutableModelNode (org.gradle.model.internal.core.MutableModelNode)1 UnmanagedModelProjection (org.gradle.model.internal.core.UnmanagedModelProjection)1 SimpleModelRuleDescriptor (org.gradle.model.internal.core.rule.describe.SimpleModelRuleDescriptor)1 AmbiguousBindingReporter (org.gradle.model.internal.report.AmbiguousBindingReporter)1 UnboundRuleInput (org.gradle.model.internal.report.unbound.UnboundRuleInput)1