use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class ExtensibleDynamicObjectTest method doesNotIncludeToStringInGetPropertyErrorMessageWhenItIsNotImplemented.
@Test
public void doesNotIncludeToStringInGetPropertyErrorMessageWhenItIsNotImplemented() {
DynamicObject bean = new ExtensibleDynamicObject(new Object(), Object.class, TestUtil.instantiatorFactory().decorateLenient());
try {
bean.getProperty("unknown");
fail();
} catch (MissingPropertyException e) {
assertThat(e.getMessage(), equalTo("Could not get unknown property 'unknown' for object of type java.lang.Object."));
}
}
use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class ExtensibleDynamicObjectTest method inheritedConventionPropertiesTrackChanges.
@Test
public void inheritedConventionPropertiesTrackChanges() {
Bean bean = new Bean();
DynamicObject inherited = bean.getInheritable();
assertFalse(inherited.hasProperty("conventionProperty"));
Convention convention = bean.extensibleDynamicObject.getConvention();
ConventionBean conventionBean = new ConventionBean();
conventionBean.setConventionProperty("value");
convention.getPlugins().put("convention", conventionBean);
assertTrue(inherited.hasProperty("conventionProperty"));
assertThat(inherited.getProperty("conventionProperty"), equalTo((Object) "value"));
}
use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class ExtensibleDynamicObjectTest method canCallGroovyDynamicMethods.
@Test
public void canCallGroovyDynamicMethods() {
DynamicGroovyBean bean = new DynamicGroovyBean();
DynamicObject object = new ExtensibleDynamicObject(bean, DynamicGroovyBean.class, TestUtil.instantiatorFactory().decorateLenient());
Integer doubled = (Integer) object.invokeMethod("bar", 1);
assertThat(doubled, equalTo(2));
try {
object.invokeMethod("xxx", 1, 2, 3);
fail();
} catch (MissingMethodException e) {
assertThat(e.getMessage(), equalTo("Could not find method xxx() for arguments [1, 2, 3] on object of type " + DynamicGroovyBean.class.getName() + "."));
}
}
use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class SettingsFactory method createSettings.
public SettingsInternal createSettings(GradleInternal gradle, File settingsDir, ScriptSource settingsScript, GradleProperties gradleProperties, StartParameter startParameter, ClassLoaderScope baseClassLoaderScope) {
ClassLoaderScope classLoaderScope = baseClassLoaderScope.createChild("settings[" + gradle.getIdentityPath() + "]");
DefaultSettings settings = instantiator.newInstance(DefaultSettings.class, serviceRegistryFactory, gradle, classLoaderScope, baseClassLoaderScope, scriptHandlerFactory.create(settingsScript, classLoaderScope), settingsDir, settingsScript, startParameter);
Map<String, Object> properties = gradleProperties.mergeProperties(emptyMap());
DynamicObject dynamicObject = ((DynamicObjectAware) settings).getAsDynamicObject();
((ExtensibleDynamicObject) dynamicObject).addProperties(properties);
return settings;
}
use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class AntBuilderDelegate method addTaskDefinition.
private void addTaskDefinition(String name, String className) throws ClassNotFoundException {
DynamicObject project = DynamicObjectUtil.asDynamicObject(builder.getProperty("project"));
project.invokeMethod("addTaskDefinition", name, antlibClassLoader.loadClass(className));
}
Aggregations