Search in sources :

Example 16 with DynamicObject

use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.

the class ExtensibleDynamicObjectTest method additionalObjectMethodsAreInherited.

@Test
public void additionalObjectMethodsAreInherited() {
    Bean other = new Bean();
    Convention convention = other.extensibleDynamicObject.getConvention();
    convention.getPlugins().put("convention", new ConventionBean());
    Bean bean = new Bean();
    bean.extensibleDynamicObject.addObject(other.getAsDynamicObject(), ExtensibleDynamicObject.Location.BeforeConvention);
    DynamicObject inherited = bean.getInheritable();
    assertTrue(inherited.hasMethod("conventionMethod", "a", "b"));
    assertThat(inherited.invokeMethod("conventionMethod", "a", "b"), equalTo((Object) "convention:a.b"));
}
Also used : Convention(org.gradle.api.plugins.Convention) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) Test(org.junit.Test)

Example 17 with DynamicObject

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, ThreadGlobalInstantiator.getOrCreate());
    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() + "."));
    }
}
Also used : MissingMethodException(groovy.lang.MissingMethodException) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) Test(org.junit.Test)

Example 18 with DynamicObject

use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.

the class ExtensibleDynamicObjectTest method parentMethodsAreInherited.

@Test
public void parentMethodsAreInherited() {
    Bean parent = new Bean();
    Convention convention = parent.extensibleDynamicObject.getConvention();
    convention.getPlugins().put("convention", new ConventionBean());
    Bean bean = new Bean();
    bean.setParent(parent.getAsDynamicObject());
    DynamicObject inherited = bean.getInheritable();
    assertTrue(inherited.hasMethod("conventionMethod", "a", "b"));
    assertThat(inherited.invokeMethod("conventionMethod", "a", "b"), equalTo((Object) "convention:a.b"));
}
Also used : Convention(org.gradle.api.plugins.Convention) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) Test(org.junit.Test)

Example 19 with DynamicObject

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"));
}
Also used : Convention(org.gradle.api.plugins.Convention) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) Test(org.junit.Test)

Example 20 with DynamicObject

use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.

the class ExtensibleDynamicObjectTest method inheritedAdditionalObjectPropertiesTrackChanges.

@Test
public void inheritedAdditionalObjectPropertiesTrackChanges() {
    Bean other = new Bean();
    other.defineProperty("other", "value");
    Bean bean = new Bean();
    DynamicObject inherited = bean.getInheritable();
    assertFalse(inherited.hasProperty("other"));
    bean.extensibleDynamicObject.addObject(other.getAsDynamicObject(), ExtensibleDynamicObject.Location.BeforeConvention);
    assertTrue(inherited.hasProperty("other"));
    assertThat(inherited.getProperty("other"), equalTo((Object) "value"));
}
Also used : DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) Test(org.junit.Test)

Aggregations

DynamicObject (org.gradle.internal.metaobject.DynamicObject)25 BeanDynamicObject (org.gradle.internal.metaobject.BeanDynamicObject)21 Test (org.junit.Test)18 Convention (org.gradle.api.plugins.Convention)5 Closure (groovy.lang.Closure)3 File (java.io.File)2 Callable (java.util.concurrent.Callable)2 DefaultProviderFactory (org.gradle.api.internal.provider.DefaultProviderFactory)2 Predicate (com.google.common.base.Predicate)1 MissingMethodException (groovy.lang.MissingMethodException)1 Map (java.util.Map)1 DynamicObjectAware (org.gradle.api.internal.DynamicObjectAware)1 ExtensibleDynamicObject (org.gradle.api.internal.ExtensibleDynamicObject)1 DirectoryFileTree (org.gradle.api.internal.file.collections.DirectoryFileTree)1 ClassLoaderScope (org.gradle.api.internal.initialization.ClassLoaderScope)1 ScriptHandlerInternal (org.gradle.api.internal.initialization.ScriptHandlerInternal)1 DslObject (org.gradle.api.internal.plugins.DslObject)1 DynamicInvokeResult (org.gradle.internal.metaobject.DynamicInvokeResult)1