Search in sources :

Example 1 with Convention

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

the class ExtensibleDynamicObjectTest method extraPropertyTakesPrecedenceOverConventionProperty.

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

Example 2 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 3 with Convention

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

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