Search in sources :

Example 6 with DynamicObject

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

the class ExtensibleDynamicObjectTest method additionalObjectPropertiesAreInherited.

@Test
public void additionalObjectPropertiesAreInherited() {
    Bean other = new Bean();
    other.defineProperty("other", "value");
    Bean bean = new Bean();
    bean.extensibleDynamicObject.addObject(other.getAsDynamicObject(), ExtensibleDynamicObject.Location.BeforeConvention);
    DynamicObject inherited = bean.getInheritable();
    assertTrue(inherited.hasProperty("other"));
    assertThat(inherited.getProperty("other"), equalTo((Object) "value"));
    assertThat(inherited.getProperties().get("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)

Example 7 with DynamicObject

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

the class ExtensibleDynamicObjectTest method conventionPropertiesAreInherited.

@Test
public void conventionPropertiesAreInherited() {
    Bean bean = new Bean();
    Convention convention = bean.extensibleDynamicObject.getConvention();
    ConventionBean conventionBean = new ConventionBean();
    conventionBean.setConventionProperty("value");
    convention.getPlugins().put("convention", conventionBean);
    DynamicObject inherited = bean.getInheritable();
    assertTrue(inherited.hasProperty("conventionProperty"));
    assertThat(inherited.getProperty("conventionProperty"), equalTo((Object) "value"));
    assertThat(inherited.getProperties().get("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 8 with DynamicObject

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

the class ExtensibleDynamicObjectTest method conventionMethodsAreInherited.

@Test
public void conventionMethodsAreInherited() {
    Bean bean = new Bean();
    Convention convention = bean.extensibleDynamicObject.getConvention();
    convention.getPlugins().put("convention", new ConventionBean());
    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 9 with DynamicObject

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

the class ExtensibleDynamicObjectTest method extraPropertiesAreInherited.

@Test
public void extraPropertiesAreInherited() {
    Bean bean = new Bean();
    bean.defineProperty("additional", "value");
    DynamicObject inherited = bean.getInheritable();
    assertTrue(inherited.hasProperty("additional"));
    assertThat(inherited.getProperty("additional"), equalTo((Object) "value"));
    assertThat(inherited.getProperties().get("additional"), 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)

Example 10 with DynamicObject

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

the class AntFileCollectionBuilder method addToAntBuilder.

@Override
public Object addToAntBuilder(Object node, String childNodeName) {
    final DynamicObject dynamicObject = new BeanDynamicObject(node);
    dynamicObject.invokeMethod(childNodeName == null ? "resources" : childNodeName, new Closure(this) {

        public Object doCall(Object ignore) {
            for (File file : files) {
                dynamicObject.invokeMethod("file", Collections.singletonMap("file", AntUtil.maskFilename(file.getAbsolutePath())));
            }
            return null;
        }
    });
    return node;
}
Also used : DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) Closure(groovy.lang.Closure) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) File(java.io.File)

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