use of org.gradle.model.dsl.internal.inputs.PotentialInput 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