Search in sources :

Example 11 with Convention

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

the class ExtensibleDynamicObjectTest method additionalObjectMethodsAreInherited.

@Test
public void additionalObjectMethodsAreInherited() {
    Bean other = new Bean();
    Convention convention = other.extensibleDynamicObject.getConvention();
    convention.getPlugins().put("convention", new ConventionBean());
    Bean bean = new Bean();
    bean.extensibleDynamicObject.addObject(other.getAsDynamicObject(), ExtensibleDynamicObject.Location.BeforeConvention);
    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 12 with Convention

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

the class ExtensibleDynamicObjectTest method canInvokeMethodsOnGroovyObjectFromGroovy.

@Test
public void canInvokeMethodsOnGroovyObjectFromGroovy() {
    GroovyBean bean = new GroovyBean();
    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 13 with Convention

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

the class ExtensibleDynamicObjectTest method conventionPropertyTakesPrecedenceOverParentProperty.

@Test
public void conventionPropertyTakesPrecedenceOverParentProperty() {
    Bean parent = new Bean();
    parent.defineProperty("conventionProperty", "parent");
    Bean bean = new Bean();
    bean.setParent(parent.getAsDynamicObject());
    Convention convention = bean.extensibleDynamicObject.getConvention();
    ConventionBean conventionBean = new ConventionBean();
    conventionBean.setConventionProperty("value");
    convention.getPlugins().put("test", conventionBean);
    assertThat(bean.getProperty("conventionProperty"), equalTo((Object) "value"));
}
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 14 with Convention

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

the class ExtensibleDynamicObjectTest method parentMethodsAreInherited.

@Test
public void parentMethodsAreInherited() {
    Bean parent = new Bean();
    Convention convention = parent.extensibleDynamicObject.getConvention();
    convention.getPlugins().put("convention", new ConventionBean());
    Bean bean = new Bean();
    bean.setParent(parent.getAsDynamicObject());
    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 15 with Convention

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

Aggregations

Convention (org.gradle.api.plugins.Convention)18 Test (org.junit.Test)14 BeanDynamicObject (org.gradle.internal.metaobject.BeanDynamicObject)10 DynamicObject (org.gradle.internal.metaobject.DynamicObject)10 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)4 DefaultScalaSourceSet (org.gradle.api.internal.tasks.DefaultScalaSourceSet)3 ScalaSourceSet (org.gradle.api.tasks.ScalaSourceSet)3 File (java.io.File)2 BuildAdapter (org.gradle.BuildAdapter)2 Gradle (org.gradle.api.invocation.Gradle)2 IncrementalCompileOptions (org.gradle.api.tasks.scala.IncrementalCompileOptions)2 ScalaCompile (org.gradle.api.tasks.scala.ScalaCompile)2 Jar (org.gradle.jvm.tasks.Jar)2 Callable (java.util.concurrent.Callable)1 FileTreeElement (org.gradle.api.file.FileTreeElement)1 SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)1 JavaBasePlugin (org.gradle.api.plugins.JavaBasePlugin)1 WarPluginConvention (org.gradle.api.plugins.WarPluginConvention)1 Spec (org.gradle.api.specs.Spec)1 SourceSet (org.gradle.api.tasks.SourceSet)1