use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class AntFileCollectionMatchingTaskBuilder method addToAntBuilder.
public Object addToAntBuilder(final Object node, final String childNodeName) {
final DynamicObject dynamicObject = new BeanDynamicObject(node);
final Iterable<DirectoryFileTree> existing = Lists.newLinkedList(FluentIterable.from(fileTrees).filter(new Predicate<DirectoryFileTree>() {
@Override
public boolean apply(DirectoryFileTree input) {
return input.getDir().exists();
}
}));
for (DirectoryFileTree fileTree : existing) {
dynamicObject.invokeMethod(childNodeName, Collections.singletonMap("location", fileTree.getDir()));
}
dynamicObject.invokeMethod("or", new Closure<Void>(this) {
public Object doCall(Object ignore) {
for (final DirectoryFileTree 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.DynamicObject 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.DynamicObject in project gradle by gradle.
the class SettingsFactory method createSettings.
public SettingsInternal createSettings(GradleInternal gradle, File settingsDir, ScriptSource settingsScript, Map<String, String> gradleProperties, StartParameter startParameter, ClassLoaderScope buildRootClassLoaderScope) {
ClassLoaderScope settingsClassLoaderScope = buildRootClassLoaderScope.createChild("settings");
ScriptHandlerInternal settingsScriptHandler = scriptHandlerFactory.create(settingsScript, settingsClassLoaderScope);
DefaultSettings settings = instantiator.newInstance(DefaultSettings.class, serviceRegistryFactory, gradle, settingsClassLoaderScope, buildRootClassLoaderScope, settingsScriptHandler, settingsDir, settingsScript, startParameter);
DynamicObject dynamicObject = ((DynamicObjectAware) settings).getAsDynamicObject();
((ExtensibleDynamicObject) dynamicObject).addProperties(gradleProperties);
return settings;
}
use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class ConfigureUtil method configureByMap.
public static <T> T configureByMap(Map<?, ?> properties, T delegate) {
if (properties.isEmpty()) {
return delegate;
}
DynamicObject dynamicObject = DynamicObjectUtil.asDynamicObject(delegate);
for (Map.Entry<?, ?> entry : properties.entrySet()) {
String name = entry.getKey().toString();
Object value = entry.getValue();
DynamicInvokeResult result = dynamicObject.trySetProperty(name, value);
if (result.isFound()) {
continue;
}
result = dynamicObject.tryInvokeMethod(name, value);
if (!result.isFound()) {
throw dynamicObject.setMissingProperty(name);
}
}
return delegate;
}
use of org.gradle.internal.metaobject.DynamicObject in project gradle by gradle.
the class ExtensibleDynamicObjectTest method parentPropertiesAreInherited.
@Test
public void parentPropertiesAreInherited() {
Bean parent = new Bean();
parent.defineProperty("parentProperty", "value");
Bean bean = new Bean();
bean.setParent(parent.getAsDynamicObject());
DynamicObject inherited = bean.getInheritable();
assertTrue(inherited.hasProperty("parentProperty"));
assertThat(inherited.getProperty("parentProperty"), equalTo((Object) "value"));
assertThat(inherited.getProperties().get("parentProperty"), equalTo((Object) "value"));
}
Aggregations