Search in sources :

Example 41 with DynamicObject

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

Example 42 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) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) Test(org.junit.Test)

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

Example 44 with DynamicObject

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;
}
Also used : DynamicObject(org.gradle.internal.metaobject.DynamicObject) ExtensibleDynamicObject(org.gradle.internal.extensibility.ExtensibleDynamicObject) ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) ExtensibleDynamicObject(org.gradle.internal.extensibility.ExtensibleDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) ExtensibleDynamicObject(org.gradle.internal.extensibility.ExtensibleDynamicObject) DynamicObjectAware(org.gradle.api.internal.DynamicObjectAware)

Example 45 with DynamicObject

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));
}
Also used : DynamicObject(org.gradle.internal.metaobject.DynamicObject)

Aggregations

DynamicObject (org.gradle.internal.metaobject.DynamicObject)45 BeanDynamicObject (org.gradle.internal.metaobject.BeanDynamicObject)40 Test (org.junit.Test)37 Convention (org.gradle.api.plugins.Convention)10 Callable (java.util.concurrent.Callable)5 DynamicObjectAware (org.gradle.api.internal.DynamicObjectAware)5 DefaultProviderFactory (org.gradle.api.internal.provider.DefaultProviderFactory)5 ExtensibleDynamicObject (org.gradle.internal.extensibility.ExtensibleDynamicObject)4 Closure (groovy.lang.Closure)3 MissingPropertyException (groovy.lang.MissingPropertyException)3 MissingMethodException (groovy.lang.MissingMethodException)2 File (java.io.File)2 Map (java.util.Map)2 ClassLoaderScope (org.gradle.api.internal.initialization.ClassLoaderScope)2 DynamicInvokeResult (org.gradle.internal.metaobject.DynamicInvokeResult)2 Predicate (com.google.common.base.Predicate)1 DirectoryTree (org.gradle.api.file.DirectoryTree)1 ExtensibleDynamicObject (org.gradle.api.internal.ExtensibleDynamicObject)1 ScriptHandlerInternal (org.gradle.api.internal.initialization.ScriptHandlerInternal)1