Search in sources :

Example 11 with TaskInternal

use of org.gradle.api.internal.TaskInternal in project gradle by gradle.

the class DefaultTaskGraphExecuterTest method brokenTask.

private Task brokenTask(String name, final RuntimeException failure, final Task... dependsOn) {
    final TaskInternal task = context.mock(TaskInternal.class);
    final TaskStateInternal state = context.mock(TaskStateInternal.class);
    final TaskOutputs outputs = context.mock(DefaultTaskOutputs.class);
    setExpectations(name, task, state, outputs);
    dependsOn(task, dependsOn);
    context.checking(new Expectations() {

        {
            atMost(1).of(executer).execute(with(sameInstance(task)), with(sameInstance(state)), with(notNullValue(TaskExecutionContext.class)));
            will(new ExecuteTaskAction(task));
            allowing(state).getFailure();
            will(returnValue(failure));
            allowing(state).rethrowFailure();
            will(throwException(failure));
        }
    });
    return task;
}
Also used : Expectations(org.jmock.Expectations) TaskStateInternal(org.gradle.api.internal.tasks.TaskStateInternal) TaskInternal(org.gradle.api.internal.TaskInternal) DefaultTaskOutputs(org.gradle.api.internal.tasks.DefaultTaskOutputs) TaskOutputs(org.gradle.api.tasks.TaskOutputs) TaskExecutionContext(org.gradle.api.internal.tasks.TaskExecutionContext)

Example 12 with TaskInternal

use of org.gradle.api.internal.TaskInternal in project gradle by gradle.

the class JacocoPluginExtension method applyTo.

/**
     * Applies Jacoco to the given task.
     * Configuration options will be provided on a task extension named 'jacoco'.
     * Jacoco will be run as an agent during the execution of the task.
     *
     * @param task the task to apply Jacoco to.
     * @see JacocoPluginExtension#TASK_EXTENSION_NAME
     */
public <T extends Task & JavaForkOptions> void applyTo(final T task) {
    final String taskName = task.getName();
    logger.debug("Applying Jacoco to " + taskName);
    final JacocoTaskExtension extension = task.getExtensions().create(TASK_EXTENSION_NAME, JacocoTaskExtension.class, agent, task);
    ((IConventionAware) extension).getConventionMapping().map("destinationFile", new Callable<File>() {

        @Override
        public File call() {
            return project.file(String.valueOf(project.getBuildDir()) + "/jacoco/" + taskName + ".exec");
        }
    });
    task.getInputs().property("jacoco.enabled", new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return extension.isEnabled();
        }
    });
    task.getInputs().property("jacoco.jvmArgs", new Callable<String>() {

        @Override
        public String call() throws Exception {
            return extension.getAsJvmArg();
        }
    });
    TaskInternal taskInternal = (TaskInternal) task;
    taskInternal.getOutputs().doNotCacheIf("Jacoco configured to not produce its output as a file", new Spec<Task>() {

        @Override
        public boolean isSatisfiedBy(Task element) {
            // Do not cache Test task if Jacoco doesn't produce its output as files
            return extension.isEnabled() && extension.getOutput() != JacocoTaskExtension.Output.FILE;
        }
    });
    taskInternal.getOutputs().file(new Callable<File>() {

        @Override
        public File call() throws Exception {
            return extension.getDestinationFile();
        }
    }).optional().withPropertyName("jacoco.destinationFile");
    taskInternal.getOutputs().dir(new Callable<File>() {

        @Override
        public File call() throws Exception {
            return extension.getClassDumpDir();
        }
    }).optional().withPropertyName("jacoco.classDumpDir");
    taskInternal.prependParallelSafeAction(new Action<Task>() {

        @Override
        public void execute(Task input) {
            if (extension.isEnabled()) {
                task.jvmArgs(extension.getAsJvmArg());
            }
        }
    });
    // Do not cache the Test task if we are appending to the Jacoco output
    taskInternal.getOutputs().doNotCacheIf("Jacoco agent configured with `append = true`", new Spec<Task>() {

        @Override
        public boolean isSatisfiedBy(Task element) {
            return extension.isAppend();
        }
    });
}
Also used : Task(org.gradle.api.Task) TaskInternal(org.gradle.api.internal.TaskInternal) File(java.io.File)

Example 13 with TaskInternal

use of org.gradle.api.internal.TaskInternal in project gradle by gradle.

the class DefaultTaskExecutionPlan method recordTaskCompleted.

private void recordTaskCompleted(TaskInfo taskInfo) {
    TaskInternal task = taskInfo.getTask();
    String projectPath = task.getProject().getPath();
    if (!isParallelizable(task)) {
        projectsWithRunningNonParallelizableTasks.remove(projectPath);
    }
    projectsWithRunningTasks.remove(projectPath);
    canonicalizedOutputCache.remove(task);
    isParallelSafeCache.remove(task);
    runningTasks.remove(task);
}
Also used : TaskInternal(org.gradle.api.internal.TaskInternal)

Example 14 with TaskInternal

use of org.gradle.api.internal.TaskInternal in project gradle by gradle.

the class DefaultTaskExecutionPlan method recordTaskStarted.

private void recordTaskStarted(TaskInfo taskInfo) {
    TaskInternal task = taskInfo.getTask();
    String projectPath = task.getProject().getPath();
    if (!isParallelizable(task)) {
        projectsWithRunningNonParallelizableTasks.add(projectPath);
    }
    projectsWithRunningTasks.add(projectPath);
    runningTasks.add(task);
}
Also used : TaskInternal(org.gradle.api.internal.TaskInternal)

Example 15 with TaskInternal

use of org.gradle.api.internal.TaskInternal in project gradle by gradle.

the class ClientForwardingTaskOperationListener method started.

@Override
public void started(BuildOperationInternal buildOperation, OperationStartEvent startEvent) {
    if (skipEvents.contains(buildOperation.getParentId())) {
        skipEvents.add(buildOperation.getId());
        return;
    }
    if (buildOperation.getOperationDescriptor() instanceof TaskOperationDescriptor) {
        if (clientSubscriptions.isSendTaskProgressEvents()) {
            TaskInternal task = ((TaskOperationDescriptor) buildOperation.getOperationDescriptor()).getTask();
            eventConsumer.dispatch(new DefaultTaskStartedProgressEvent(startEvent.getStartTime(), toTaskDescriptor(buildOperation, task)));
        } else {
            // Discard this operation and all children
            skipEvents.add(buildOperation.getId());
        }
    } else {
        delegate.started(buildOperation, startEvent);
    }
}
Also used : DefaultTaskStartedProgressEvent(org.gradle.tooling.internal.provider.events.DefaultTaskStartedProgressEvent) TaskInternal(org.gradle.api.internal.TaskInternal) TaskOperationDescriptor(org.gradle.api.execution.internal.TaskOperationDescriptor)

Aggregations

TaskInternal (org.gradle.api.internal.TaskInternal)18 Task (org.gradle.api.Task)4 TaskOperationDescriptor (org.gradle.api.execution.internal.TaskOperationDescriptor)4 DefaultTaskOutputs (org.gradle.api.internal.tasks.DefaultTaskOutputs)3 TaskStateInternal (org.gradle.api.internal.tasks.TaskStateInternal)3 TaskOutputs (org.gradle.api.tasks.TaskOutputs)3 Expectations (org.jmock.Expectations)3 Closure (groovy.lang.Closure)2 Action (org.gradle.api.Action)2 InvalidUserDataException (org.gradle.api.InvalidUserDataException)2 TaskExecutionContext (org.gradle.api.internal.tasks.TaskExecutionContext)2 DefaultTaskFinishedProgressEvent (org.gradle.tooling.internal.provider.events.DefaultTaskFinishedProgressEvent)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 DefaultTask (org.gradle.api.DefaultTask)1 ExecuteTaskBuildOperationDetails (org.gradle.api.execution.internal.ExecuteTaskBuildOperationDetails)1 TaskInputsListener (org.gradle.api.execution.internal.TaskInputsListener)1