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());
}
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;
}
}
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());
}
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);
}
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;
}
Aggregations