use of groovy.lang.Closure in project gradle by gradle.
the class CompositeFileTreeTest method visitsEachTreeWithClosure.
@Test
public void visitsEachTreeWithClosure() {
final Closure visitor = TestUtil.TEST_CLOSURE;
final FileVisitor closureAsVisitor = DefaultGroovyMethods.asType(visitor, FileVisitor.class);
context.checking(new Expectations() {
{
oneOf(source1).visit(closureAsVisitor);
oneOf(source2).visit(closureAsVisitor);
}
});
tree.visit(visitor);
}
use of groovy.lang.Closure in project gradle by gradle.
the class AntJacocoCheck method configureReport.
@Override
protected void configureReport(final GroovyObjectSupport antBuilder, final JacocoViolationRulesContainer violationRules) {
if (!violationRules.getRules().isEmpty()) {
Map<String, Object> checkArgs = ImmutableMap.<String, Object>of("failonviolation", violationRules.isFailOnViolation(), "violationsproperty", VIOLATIONS_ANT_PROPERTY);
antBuilder.invokeMethod("check", new Object[] { checkArgs, new Closure<Object>(this, this) {
@SuppressWarnings("UnusedDeclaration")
public Object doCall(Object ignore) {
for (final JacocoViolationRule rule : filter(violationRules.getRules(), RULE_ENABLED_PREDICATE)) {
Map<String, Object> ruleArgs = ImmutableMap.<String, Object>of("element", rule.getElement(), "includes", Joiner.on(':').join(rule.getIncludes()), "excludes", Joiner.on(':').join(rule.getExcludes()));
antBuilder.invokeMethod("rule", new Object[] { ruleArgs, new Closure<Object>(this, this) {
@SuppressWarnings("UnusedDeclaration")
public Object doCall(Object ignore) {
for (JacocoLimit limit : rule.getLimits()) {
Map<String, Object> limitArgs = new HashMap<String, Object>();
limitArgs.put("counter", limit.getCounter());
limitArgs.put("value", limit.getValue());
if (limit.getMinimum() != null) {
limitArgs.put("minimum", limit.getMinimum());
}
if (limit.getMaximum() != null) {
limitArgs.put("maximum", limit.getMaximum());
}
antBuilder.invokeMethod("limit", new Object[] { ImmutableMap.copyOf(limitArgs) });
}
return null;
}
} });
}
return null;
}
} });
}
}
use of groovy.lang.Closure in project gradle by gradle.
the class TestFile method copyFrom.
public void copyFrom(final URL resource) {
final TestFile testFile = this;
RetryUtil.retry(new Closure(null, null) {
@SuppressWarnings("UnusedDeclaration")
void doCall() {
try {
FileUtils.copyURLToFile(resource, testFile);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
});
}
use of groovy.lang.Closure in project grails-core by grails.
the class JspInvokeGrailsTagLibTag method doStartTagInternal.
@SuppressWarnings("rawtypes")
protected int doStartTagInternal() {
GroovyObject tagLib = getTagLib(getTagName());
if (tagLib == null) {
throw new GrailsTagException("Tag [" + getTagName() + "] does not exist. No tag library found.");
}
sw = FastStringPrintWriter.newInstance();
out = sw;
tagLib.setProperty(OUT_PROPERTY, out);
Object tagLibProp;
final Map tagLibProperties = DefaultGroovyMethods.getProperties(tagLib);
if (tagLibProperties.containsKey(getTagName())) {
tagLibProp = tagLibProperties.get(getTagName());
} else {
throw new GrailsTagException("Tag [" + getTagName() + "] does not exist in tag library [" + tagLib.getClass().getName() + "]");
}
if (!(tagLibProp instanceof Closure)) {
throw new GrailsTagException("Tag [" + getTagName() + "] does not exist in tag library [" + tagLib.getClass().getName() + "]");
}
Closure body = new Closure(this) {
private static final long serialVersionUID = 1861498565854341886L;
@SuppressWarnings("unused")
public Object doCall() {
return call();
}
@SuppressWarnings("unused")
public Object doCall(Object o) {
return call(new Object[] { o });
}
@SuppressWarnings("unused")
public Object doCall(Object[] args) {
return call(args);
}
@Override
public Object call(Object... args) {
invocationCount++;
if (args.length > 0) {
invocationArgs.add(args[0]);
} else {
invocationArgs.add(ZERO_ARGUMENTS);
}
out.print("<jsp-body-gen" + invocationCount + ">");
return "";
}
};
Closure tag = (Closure) tagLibProp;
if (tag.getParameterTypes().length == 1) {
tag.call(new Object[] { attributes });
if (body != null) {
body.call();
}
}
if (tag.getParameterTypes().length == 2) {
tag.call(new Object[] { attributes, body });
}
Collections.reverse(invocationArgs);
setCurrentArgument();
return EVAL_BODY_BUFFERED;
}
use of groovy.lang.Closure in project gradle by gradle.
the class TaskFactory method createTask.
public TaskInternal createTask(Map<String, ?> args) {
Map<String, Object> actualArgs = new HashMap<String, Object>(args);
checkTaskArgsAndCreateDefaultValues(actualArgs);
String name = actualArgs.get(Task.TASK_NAME).toString();
if (!GUtil.isTrue(name)) {
throw new InvalidUserDataException("The task name must be provided.");
}
Class<? extends TaskInternal> type = (Class) actualArgs.get(Task.TASK_TYPE);
TaskInternal task = create(name, type);
Object dependsOnTasks = actualArgs.get(Task.TASK_DEPENDS_ON);
if (dependsOnTasks != null) {
task.dependsOn(dependsOnTasks);
}
Object description = actualArgs.get(Task.TASK_DESCRIPTION);
if (description != null) {
task.setDescription(description.toString());
}
Object group = actualArgs.get(Task.TASK_GROUP);
if (group != null) {
task.setGroup(group.toString());
}
Object action = actualArgs.get(Task.TASK_ACTION);
if (action instanceof Action) {
Action<? super Task> taskAction = (Action<? super Task>) action;
task.doFirst(taskAction);
} else if (action != null) {
Closure closure = (Closure) action;
task.doFirst(closure);
}
return task;
}
Aggregations