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