Search in sources :

Example 21 with DynamicObject

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."));
    }
}
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 22 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)

Example 23 with DynamicObject

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

Example 24 with DynamicObject

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());
}
Also used : BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) DefaultProviderFactory(org.gradle.api.internal.provider.DefaultProviderFactory) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 25 with DynamicObject

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());
}
Also used : BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) DefaultProviderFactory(org.gradle.api.internal.provider.DefaultProviderFactory) Callable(java.util.concurrent.Callable) 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