Search in sources :

Example 1 with DuplicateModelException

use of org.gradle.model.internal.core.DuplicateModelException 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)

Aggregations

DuplicateModelException (org.gradle.model.internal.core.DuplicateModelException)1 ModelPath (org.gradle.model.internal.core.ModelPath)1