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 DefaultModelRegistry method fireAction.
private void fireAction(RuleBinder boundMutator) {
final List<ModelView<?>> inputs = toViews(boundMutator.getInputBindings(), boundMutator.getAction().getDescriptor());
ModelBinding subjectBinding = boundMutator.getSubjectBinding();
final ModelNodeInternal node = subjectBinding.getNode();
final ModelAction mutator = boundMutator.getAction();
ModelRuleDescriptor descriptor = mutator.getDescriptor();
LOGGER.debug("Project {} - Mutating {} using {}", projectPath, node.getPath(), descriptor);
try {
RuleContext.run(descriptor, new Runnable() {
@Override
public void run() {
mutator.execute(node, inputs);
}
});
} catch (Throwable e) {
// TODO some representation of state of the inputs
throw new ModelRuleExecutionException(descriptor, e);
}
}
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