Search in sources :

Example 86 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class DefaultTaskExecutionGraph method getDependencies.

@Override
public Set<Task> getDependencies(Task task) {
    Node node = executionPlan.getNode(task);
    ImmutableSet.Builder<Task> builder = ImmutableSet.builder();
    for (Node dependencyNode : node.getDependencySuccessors()) {
        if (dependencyNode instanceof TaskNode) {
            builder.add(((TaskNode) dependencyNode).getTask());
        }
    }
    return builder.build();
}
Also used : Task(org.gradle.api.Task) TaskNode(org.gradle.execution.plan.TaskNode) ImmutableSet(com.google.common.collect.ImmutableSet) TaskNode(org.gradle.execution.plan.TaskNode) Node(org.gradle.execution.plan.Node)

Example 87 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class TaskFactory method create.

@Override
@SuppressWarnings("deprecation")
public <S extends Task> S create(final TaskIdentity<S> identity, @Nullable final Object[] constructorArgs) {
    if (!Task.class.isAssignableFrom(identity.type)) {
        throw new InvalidUserDataException(String.format("Cannot create task '%s' of type '%s' as it does not implement the Task interface.", identity.identityPath.toString(), identity.type.getSimpleName()));
    }
    NameValidator.validate(identity.name, "task name", "");
    final Class<? extends DefaultTask> implType;
    if (identity.type == Task.class) {
        implType = DefaultTask.class;
    } else if (DefaultTask.class.isAssignableFrom(identity.type)) {
        implType = identity.type.asSubclass(DefaultTask.class);
    } else if (identity.type == org.gradle.api.internal.AbstractTask.class || identity.type == TaskInternal.class) {
        throw new InvalidUserDataException(String.format("Cannot create task '%s' of type '%s' as this type is not supported for task registration.", identity.identityPath.toString(), identity.type.getSimpleName()));
    } else {
        throw new InvalidUserDataException(String.format("Cannot create task '%s' of type '%s' as directly extending AbstractTask is not supported.", identity.identityPath.toString(), identity.type.getSimpleName()));
    }
    Describable displayName = Describables.withTypeAndName("task", identity.getIdentityPath());
    return org.gradle.api.internal.AbstractTask.injectIntoNewInstance(project, identity, new Callable<S>() {

        @Override
        public S call() {
            try {
                Task instance;
                if (constructorArgs != null) {
                    instance = instantiationScheme.instantiator().newInstanceWithDisplayName(implType, displayName, constructorArgs);
                } else {
                    instance = instantiationScheme.deserializationInstantiator().newInstance(implType, org.gradle.api.internal.AbstractTask.class);
                }
                return identity.type.cast(instance);
            } catch (ObjectInstantiationException e) {
                throw new TaskInstantiationException(String.format("Could not create task of type '%s'.", identity.type.getSimpleName()), e.getCause());
            }
        }
    });
}
Also used : Task(org.gradle.api.Task) DefaultTask(org.gradle.api.DefaultTask) ObjectInstantiationException(org.gradle.api.reflect.ObjectInstantiationException) Describable(org.gradle.api.Describable) TaskInternal(org.gradle.api.internal.TaskInternal) TaskInstantiationException(org.gradle.api.tasks.TaskInstantiationException) InvalidUserDataException(org.gradle.api.InvalidUserDataException) DefaultTask(org.gradle.api.DefaultTask)

Example 88 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class DefaultProject method getTasksByName.

@Override
public Set<Task> getTasksByName(final String name, boolean recursive) {
    if (isNullOrEmpty(name)) {
        throw new InvalidUserDataException("Name is not specified!");
    }
    final Set<Task> foundTasks = new HashSet<Task>();
    Action<Project> action = new Action<Project>() {

        @Override
        public void execute(Project project) {
            // Don't force evaluation of rules here, let the task container do what it needs to
            ((ProjectInternal) project).getOwner().ensureTasksDiscovered();
            Task task = project.getTasks().findByName(name);
            if (task != null) {
                foundTasks.add(task);
            }
        }
    };
    if (recursive) {
        allprojects(action);
    } else {
        action.execute(this);
    }
    return foundTasks;
}
Also used : Project(org.gradle.api.Project) Task(org.gradle.api.Task) ClosureBackedAction(org.gradle.util.internal.ClosureBackedAction) Action(org.gradle.api.Action) DefaultObjectConfigurationAction(org.gradle.api.internal.plugins.DefaultObjectConfigurationAction) InvalidUserDataException(org.gradle.api.InvalidUserDataException) HashSet(java.util.HashSet)

Example 89 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class LazyPublishArtifact method getDelegate.

private PublishArtifactInternal getDelegate() {
    if (delegate == null) {
        Object value = provider.get();
        if (value instanceof FileSystemLocation) {
            FileSystemLocation location = (FileSystemLocation) value;
            delegate = fromFile(location.getAsFile());
        } else if (value instanceof File) {
            delegate = fromFile((File) value);
        } else if (value instanceof AbstractArchiveTask) {
            delegate = new ArchivePublishArtifact((AbstractArchiveTask) value);
        } else if (value instanceof Task) {
            delegate = fromFile(((Task) value).getOutputs().getFiles().getSingleFile());
        } else if (fileResolver != null) {
            delegate = fromFile(fileResolver.resolve(value));
        } else {
            throw new InvalidUserDataException(String.format("Cannot convert provided value (%s) to a file.", value));
        }
    }
    return delegate;
}
Also used : AbstractArchiveTask(org.gradle.api.tasks.bundling.AbstractArchiveTask) Task(org.gradle.api.Task) ArchivePublishArtifact(org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact) FileSystemLocation(org.gradle.api.file.FileSystemLocation) AbstractArchiveTask(org.gradle.api.tasks.bundling.AbstractArchiveTask) InvalidUserDataException(org.gradle.api.InvalidUserDataException) File(java.io.File)

Example 90 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class SkipTaskWithNoActionsExecuter method execute.

@Override
public TaskExecuterResult execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
    if (!task.hasTaskActions()) {
        LOGGER.info("Skipping {} as it has no actions.", task);
        boolean upToDate = true;
        for (Task dependency : taskExecutionGraph.getDependencies(task)) {
            if (!dependency.getState().getSkipped()) {
                upToDate = false;
                break;
            }
        }
        state.setActionable(false);
        state.setOutcome(upToDate ? TaskExecutionOutcome.UP_TO_DATE : TaskExecutionOutcome.EXECUTED);
        return TaskExecuterResult.WITHOUT_OUTPUTS;
    }
    return executer.execute(task, state, context);
}
Also used : Task(org.gradle.api.Task)

Aggregations

Task (org.gradle.api.Task)222 Project (org.gradle.api.Project)66 File (java.io.File)54 Action (org.gradle.api.Action)31 ArrayList (java.util.ArrayList)27 Plugin (org.gradle.api.Plugin)27 Configuration (org.gradle.api.artifacts.Configuration)27 Test (org.junit.Test)23 List (java.util.List)22 TaskProvider (org.gradle.api.tasks.TaskProvider)22 DefaultTask (org.gradle.api.DefaultTask)21 IOException (java.io.IOException)20 Set (java.util.Set)18 SourceSet (org.gradle.api.tasks.SourceSet)18 Map (java.util.Map)17 GradleException (org.gradle.api.GradleException)17 FileCollection (org.gradle.api.file.FileCollection)16 Inject (javax.inject.Inject)15 JavaPlugin (org.gradle.api.plugins.JavaPlugin)15 LifecycleBasePlugin (org.gradle.language.base.plugins.LifecycleBasePlugin)15