use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class ExtensibleDynamicObjectTest method doesNotIncludeToStringInSetPropertyErrorMessageWhenItIsNotImplemented.
@Test
public void doesNotIncludeToStringInSetPropertyErrorMessageWhenItIsNotImplemented() {
DynamicObject bean = new ExtensibleDynamicObject(new Object(), Object.class, ThreadGlobalInstantiator.getOrCreate());
try {
bean.setProperty("unknown", "value");
fail();
} catch (MissingPropertyException e) {
assertThat(e.getMessage(), equalTo("Could not set unknown property 'unknown' for object of type java.lang.Object."));
}
}
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));
}
use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class CodeNarcPlugin method configureForSourceSet.
@Override
protected void configureForSourceSet(final SourceSet sourceSet, CodeNarc task) {
task.setDescription("Run CodeNarc analysis for " + sourceSet.getName() + " classes");
DynamicObject dynamicObject = new DslObject(sourceSet).getAsDynamicObject();
task.setSource(dynamicObject.getProperty("allGroovy"));
}
use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class AsmBackedClassGeneratorTest method doesNotAddSetterMethodsForPropertyWhoseTypeIsPropertyWhenTheSetterMethodsAlreadyExist.
@Test
public void doesNotAddSetterMethodsForPropertyWhoseTypeIsPropertyWhenTheSetterMethodsAlreadyExist() throws Exception {
DefaultProviderFactory providerFactory = new DefaultProviderFactory();
BeanWithProperty bean = generator.newInstance(BeanWithProperty.class, TestUtil.objectFactory());
DynamicObject dynamicObject = ((DynamicObjectAware) bean).getAsDynamicObject();
dynamicObject.setProperty("prop2", "value");
assertEquals("[value]", bean.getProp2().get());
dynamicObject.setProperty("prop2", 12);
assertEquals("[12]", bean.getProp2().get());
dynamicObject.setProperty("prop2", providerFactory.provider(new Callable<String>() {
int count;
@Override
public String call() throws Exception {
return "[" + String.valueOf(++count) + "]";
}
}));
assertEquals("[1]", bean.getProp2().get());
assertEquals("[2]", bean.getProp2().get());
}
use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class AsmBackedClassGeneratorTest method addsSetterMethodsForPropertyWhoseTypeIsProperty.
@Test
public void addsSetterMethodsForPropertyWhoseTypeIsProperty() throws Exception {
DefaultProviderFactory providerFactory = new DefaultProviderFactory();
BeanWithProperty bean = generator.newInstance(BeanWithProperty.class, TestUtil.objectFactory());
DynamicObject dynamicObject = ((DynamicObjectAware) bean).getAsDynamicObject();
dynamicObject.setProperty("prop", "value");
assertEquals("value", bean.getProp().get());
dynamicObject.setProperty("prop", providerFactory.provider(new Callable<String>() {
int count;
@Override
public String call() throws Exception {
return "[" + String.valueOf(++count) + "]";
}
}));
assertEquals("[1]", bean.getProp().get());
assertEquals("[2]", bean.getProp().get());
}
Aggregations