use of org.gradle.internal.metaobject.DynamicInvokeResult in project gradle by gradle.
the class ConfigureUtil method configureByMap.
public static <T> T configureByMap(Map<?, ?> properties, T delegate) {
if (properties.isEmpty()) {
return delegate;
}
DynamicObject dynamicObject = DynamicObjectUtil.asDynamicObject(delegate);
for (Map.Entry<?, ?> entry : properties.entrySet()) {
String name = entry.getKey().toString();
Object value = entry.getValue();
DynamicInvokeResult result = dynamicObject.trySetProperty(name, value);
if (result.isFound()) {
continue;
}
result = dynamicObject.tryInvokeMethod(name, value);
if (!result.isFound()) {
throw dynamicObject.setMissingProperty(name);
}
}
return delegate;
}
use of org.gradle.internal.metaobject.DynamicInvokeResult in project gradle by gradle.
the class MixInClosurePropertiesAsMethodsDynamicObject method tryInvokeMethod.
@Override
public DynamicInvokeResult tryInvokeMethod(String name, Object... arguments) {
DynamicInvokeResult result = super.tryInvokeMethod(name, arguments);
if (result.isFound()) {
return result;
}
DynamicInvokeResult propertyResult = tryGetProperty(name);
if (propertyResult.isFound()) {
Object property = propertyResult.getValue();
if (property instanceof Closure) {
Closure closure = (Closure) property;
closure.setResolveStrategy(Closure.DELEGATE_FIRST);
BeanDynamicObject dynamicObject = new BeanDynamicObject(closure);
result = dynamicObject.tryInvokeMethod("doCall", arguments);
if (!result.isFound() && !(closure instanceof GeneratedClosure)) {
return DynamicInvokeResult.found(closure.call(arguments));
}
return result;
}
if (property instanceof NamedDomainObjectContainer && arguments.length == 1 && arguments[0] instanceof Closure) {
((NamedDomainObjectContainer) property).configure((Closure) arguments[0]);
return DynamicInvokeResult.found();
}
}
return DynamicInvokeResult.notFound();
}
use of org.gradle.internal.metaobject.DynamicInvokeResult in project gradle by gradle.
the class ConfigureUtil method configureByMap.
public static <T> T configureByMap(Map<?, ?> properties, T delegate) {
if (properties.isEmpty()) {
return delegate;
}
DynamicObject dynamicObject = DynamicObjectUtil.asDynamicObject(delegate);
for (Map.Entry<?, ?> entry : properties.entrySet()) {
String name = entry.getKey().toString();
Object value = entry.getValue();
DynamicInvokeResult result = dynamicObject.trySetProperty(name, value);
if (result.isFound()) {
continue;
}
result = dynamicObject.tryInvokeMethod(name, value);
if (!result.isFound()) {
throw dynamicObject.setMissingProperty(name);
}
}
return delegate;
}
Aggregations