Search in sources :

Example 26 with Convention

use of org.gradle.api.plugins.Convention in project gradle by gradle.

the class ExtensibleDynamicObjectTest method canInvokeMethodsOnJavaSubClassOfGroovyObjectFromGroovy.

@Test
public void canInvokeMethodsOnJavaSubClassOfGroovyObjectFromGroovy() {
    // This doesn't work.
    // It used to because at the bottom of the hierarchy chain the object implemented methodMissing().
    // However, our normal “decorated” classes do not do this so it is not realistic.
    // Groovy does something very strange here.
    // For some reason (probably because the class is Java), it won't employ any dynamism.
    // Even implementing invokeMethod at the Java level has no effect.
    DynamicJavaBean javaBean = new DynamicJavaBean();
    Convention convention = javaBean.extensibleDynamicObject.getConvention();
    convention.getPlugins().put("bean", new ConventionBean());
    new ExtensibleDynamicObjectTestHelper().assertCanCallMethods(javaBean);
}
Also used : Convention(org.gradle.api.plugins.Convention) Test(org.junit.Test)

Example 27 with Convention

use of org.gradle.api.plugins.Convention in project gradle by gradle.

the class ExtensibleDynamicObjectTest method canInvokeMethodsOnJavaObjectFromGroovy.

@Test
public void canInvokeMethodsOnJavaObjectFromGroovy() {
    Bean bean = new Bean();
    Convention convention = bean.extensibleDynamicObject.getConvention();
    convention.getPlugins().put("bean", new ConventionBean());
    new ExtensibleDynamicObjectTestHelper().assertCanCallMethods(bean);
}
Also used : Convention(org.gradle.api.plugins.Convention) Test(org.junit.Test)

Example 28 with Convention

use of org.gradle.api.plugins.Convention 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) 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 29 with Convention

use of org.gradle.api.plugins.Convention in project gradle by gradle.

the class ExtensibleDynamicObjectTest method canGetAndSetPropertyDefinedByConventionObject.

@Test
public void canGetAndSetPropertyDefinedByConventionObject() {
    Bean bean = new Bean();
    Convention convention = bean.extensibleDynamicObject.getConvention();
    ConventionBean conventionBean = new ConventionBean();
    convention.getPlugins().put("test", conventionBean);
    conventionBean.setConventionProperty("value");
    assertThat(bean.getProperty("conventionProperty"), equalTo((Object) "value"));
    bean.setProperty("conventionProperty", "new value");
    assertThat(bean.getProperty("conventionProperty"), equalTo((Object) "new value"));
    assertThat(conventionBean.getConventionProperty(), equalTo((Object) "new value"));
}
Also used : Convention(org.gradle.api.plugins.Convention) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) Test(org.junit.Test)

Example 30 with Convention

use of org.gradle.api.plugins.Convention in project gradle by gradle.

the class ExtensibleDynamicObjectTest method canGetAllProperties.

@Test
public void canGetAllProperties() {
    Bean parent = new Bean();
    parent.defineProperty("parentProperty", "parentProperty");
    parent.setReadWriteProperty("ignore me");
    parent.doSetReadOnlyProperty("ignore me");
    Convention parentConvention = parent.extensibleDynamicObject.getConvention();
    parentConvention.getPlugins().put("parent", new ConventionBean());
    GroovyBean bean = new GroovyBean();
    bean.defineProperty("additional", "additional");
    bean.setReadWriteProperty("readWriteProperty");
    bean.doSetReadOnlyProperty("readOnlyProperty");
    bean.setGroovyProperty("groovyProperty");
    Convention convention = bean.extensibleDynamicObject.getConvention();
    ConventionBean conventionBean = new ConventionBean();
    conventionBean.setConventionProperty("conventionProperty");
    convention.getPlugins().put("bean", conventionBean);
    bean.setParent(parent.getAsDynamicObject());
    Map<String, Object> properties = bean.getProperties();
    assertThat(properties.get("properties"), sameInstance((Object) properties));
    assertThat(properties.get("readWriteProperty"), equalTo((Object) "readWriteProperty"));
    assertThat(properties.get("readOnlyProperty"), equalTo((Object) "readOnlyProperty"));
    assertThat(properties.get("parentProperty"), equalTo((Object) "parentProperty"));
    assertThat(properties.get("additional"), equalTo((Object) "additional"));
    assertThat(properties.get("groovyProperty"), equalTo((Object) "groovyProperty"));
    assertThat(properties.get("groovyDynamicProperty"), equalTo(null));
    assertThat(properties.get("conventionProperty"), equalTo((Object) "conventionProperty"));
}
Also used : Convention(org.gradle.api.plugins.Convention) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) Test(org.junit.Test)

Aggregations

Convention (org.gradle.api.plugins.Convention)33 Test (org.junit.Test)28 BeanDynamicObject (org.gradle.internal.metaobject.BeanDynamicObject)20 DynamicObject (org.gradle.internal.metaobject.DynamicObject)20 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)5 File (java.io.File)3 DefaultScalaSourceSet (org.gradle.api.internal.tasks.DefaultScalaSourceSet)3 ScalaSourceSet (org.gradle.api.tasks.ScalaSourceSet)3 BuildAdapter (org.gradle.BuildAdapter)2 Gradle (org.gradle.api.invocation.Gradle)2 SourceSet (org.gradle.api.tasks.SourceSet)2 IncrementalCompileOptions (org.gradle.api.tasks.scala.IncrementalCompileOptions)2 ScalaCompile (org.gradle.api.tasks.scala.ScalaCompile)2 Jar (org.gradle.jvm.tasks.Jar)2 HashSet (java.util.HashSet)1 Callable (java.util.concurrent.Callable)1 Project (org.gradle.api.Project)1 FileCollection (org.gradle.api.file.FileCollection)1 FileTreeElement (org.gradle.api.file.FileTreeElement)1 SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)1