use of org.gradle.api.InvalidUserDataException in project gradle by gradle.
the class DefaultTaskContainer method doCreate.
private Task doCreate(Map<String, ?> options, final Action<? super Task> configureAction) {
Map<String, ?> factoryOptions = options;
final boolean replace;
if (options.containsKey(Task.TASK_OVERWRITE)) {
factoryOptions = new HashMap<String, Object>(options);
Object replaceStr = factoryOptions.remove(Task.TASK_OVERWRITE);
replace = "true".equals(replaceStr.toString());
} else {
replace = false;
}
final Map<String, ?> actualArgs = checkTaskArgsAndCreateDefaultValues(factoryOptions);
final String name = actualArgs.get(Task.TASK_NAME).toString();
if (!GUtil.isTrue(name)) {
throw new InvalidUserDataException("The task name must be provided.");
}
final Class<? extends TaskInternal> type = Cast.uncheckedCast(actualArgs.get(Task.TASK_TYPE));
final TaskIdentity<? extends TaskInternal> identity = TaskIdentity.create(name, type, project);
return buildOperationExecutor.call(new CallableBuildOperation<Task>() {
@Override
public BuildOperationDescriptor.Builder description() {
return realizeDescriptor(identity, replace, true);
}
@Override
public Task call(BuildOperationContext context) {
try {
Object[] constructorArgs = getConstructorArgs(actualArgs);
TaskInternal task = createTask(identity, constructorArgs);
statistics.eagerTask(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 = Cast.uncheckedCast(action);
task.doFirst(taskAction);
} else if (action != null) {
Closure closure = (Closure) action;
task.doFirst(closure);
}
addTask(task, replace);
configureAction.execute(task);
context.setResult(REALIZE_RESULT);
return task;
} catch (Throwable t) {
throw taskCreationException(name, t);
}
}
});
}
Aggregations