Search in sources :

Example 61 with InvalidUserDataException

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);
            }
        }
    });
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) Task(org.gradle.api.Task) DefaultTask(org.gradle.api.DefaultTask) Action(org.gradle.api.Action) Closure(groovy.lang.Closure) TaskInternal(org.gradle.api.internal.TaskInternal) InvalidUserDataException(org.gradle.api.InvalidUserDataException) DynamicObject(org.gradle.internal.metaobject.DynamicObject)

Aggregations

InvalidUserDataException (org.gradle.api.InvalidUserDataException)61 File (java.io.File)18 Task (org.gradle.api.Task)6 ArrayList (java.util.ArrayList)5 LinkedHashSet (java.util.LinkedHashSet)5 Action (org.gradle.api.Action)5 TaskAction (org.gradle.api.tasks.TaskAction)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 DefaultTask (org.gradle.api.DefaultTask)4 ImmutableList (com.google.common.collect.ImmutableList)3 Closure (groovy.lang.Closure)3 Map (java.util.Map)3 MavenArtifactRepository (org.gradle.api.artifacts.repositories.MavenArtifactRepository)3 TaskInternal (org.gradle.api.internal.TaskInternal)3 MavenPublicationInternal (org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal)3 DirectorySensitivity (org.gradle.internal.fingerprint.DirectorySensitivity)3 LineEndingSensitivity (org.gradle.internal.fingerprint.LineEndingSensitivity)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Nullable (javax.annotation.Nullable)2