use of org.gradle.internal.metaobject.BeanDynamicObject in project gradle by gradle.
the class ExtensibleDynamicObjectTest method canInvokeMethodDefinedByScriptObject.
@Test
public void canInvokeMethodDefinedByScriptObject() {
Bean bean = new Bean();
Script script = TestUtil.createScript("def scriptMethod(a, b) { \"script:$a.$b\" } ");
bean.extensibleDynamicObject.addObject(new BeanDynamicObject(script), ExtensibleDynamicObject.Location.BeforeConvention);
assertTrue(bean.hasMethod("scriptMethod", "a", "b"));
assertThat(bean.getAsDynamicObject().invokeMethod("scriptMethod", "a", "b").toString(), equalTo((Object) "script:a.b"));
}
use of org.gradle.internal.metaobject.BeanDynamicObject in project gradle by gradle.
the class AntFileCollectionMatchingTaskBuilder method addToAntBuilder.
@Override
public Object addToAntBuilder(final Object node, final String childNodeName) {
final DynamicObject dynamicObject = new BeanDynamicObject(node);
final Iterable<DirectoryTree> existing = Lists.newLinkedList(FluentIterable.from(fileTrees).filter(new Predicate<DirectoryTree>() {
@Override
public boolean apply(DirectoryTree input) {
return input.getDir().exists();
}
}));
for (DirectoryTree fileTree : existing) {
dynamicObject.invokeMethod(childNodeName, Collections.singletonMap("location", fileTree.getDir()));
}
dynamicObject.invokeMethod("or", new Closure<Void>(this) {
public Object doCall(Object ignore) {
for (final DirectoryTree fileTree : existing) {
dynamicObject.invokeMethod("and", new Closure<Void>(this) {
public Object doCall(Object ignore) {
dynamicObject.invokeMethod("gradleBaseDirSelector", Collections.singletonMap("baseDir", fileTree.getDir()));
fileTree.getPatterns().addToAntBuilder(node, null);
return null;
}
});
}
return null;
}
});
return node;
}
use of org.gradle.internal.metaobject.BeanDynamicObject in project gradle by gradle.
the class AntFileTreeBuilder method addToAntBuilder.
@Override
public Object addToAntBuilder(Object node, String childNodeName) {
final DynamicObject dynamicObject = new BeanDynamicObject(node);
dynamicObject.invokeMethod(childNodeName == null ? "resources" : childNodeName, new Closure(this) {
public Object doCall(Object ignore) {
for (Map.Entry<String, File> entry : files.entrySet()) {
String name = entry.getKey();
File file = entry.getValue();
// gradleFileResource type is mapped to AntFileResource
dynamicObject.invokeMethod("gradleFileResource", ImmutableMap.of("file", file.getAbsolutePath(), "name", name));
}
return null;
}
});
return node;
}
use of org.gradle.internal.metaobject.BeanDynamicObject in project gradle by gradle.
the class AntFileCollectionBuilder method addToAntBuilder.
@Override
public Object addToAntBuilder(Object node, String childNodeName) {
final DynamicObject dynamicObject = new BeanDynamicObject(node);
dynamicObject.invokeMethod(childNodeName == null ? "resources" : childNodeName, new Closure(this) {
public Object doCall(Object ignore) {
for (File file : files) {
dynamicObject.invokeMethod("file", Collections.singletonMap("file", AntUtil.maskFilename(file.getAbsolutePath())));
}
return null;
}
});
return node;
}
use of org.gradle.internal.metaobject.BeanDynamicObject in project gradle by gradle.
the class ExtensibleDynamicObjectTest method canInvokeMethodDefinedByScriptObject.
@Test
public void canInvokeMethodDefinedByScriptObject() {
Bean bean = new Bean();
Script script = TestUtil.createScript("def scriptMethod(a, b) { \"script:$a.$b\" } ");
bean.extensibleDynamicObject.addObject(new BeanDynamicObject(script), ExtensibleDynamicObject.Location.BeforeConvention);
assertTrue(bean.hasMethod("scriptMethod", "a", "b"));
assertThat(bean.getAsDynamicObject().invokeMethod("scriptMethod", "a", "b").toString(), equalTo((Object) "script:a.b"));
}
Aggregations