Search in sources :

Example 1 with TaskOutputs

use of org.gradle.api.tasks.TaskOutputs in project gradle by gradle.

the class DefaultTaskGraphExecuterTest method createTask.

private TaskInternal createTask(final String name) {
    TaskInternal task = context.mock(TaskInternal.class);
    TaskStateInternal state = context.mock(TaskStateInternal.class);
    final TaskOutputs outputs = context.mock(DefaultTaskOutputs.class);
    setExpectations(name, task, state, outputs);
    return task;
}
Also used : 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)

Example 2 with TaskOutputs

use of org.gradle.api.tasks.TaskOutputs in project gradle by gradle.

the class DefaultTaskGraphExecuterTest method task.

private Task task(final String name, 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(null));
        }
    });
    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 3 with TaskOutputs

use of org.gradle.api.tasks.TaskOutputs in project gradle by gradle.

the class BuildDependenciesOnlyFileCollectionResolveContext method add.

@Override
public FileCollectionResolveContext add(Object element) {
    // TODO - need to sync with DefaultFileCollectionResolveContext
    if (element instanceof Buildable) {
        taskContext.add(element);
    } else if (element instanceof Task) {
        taskContext.add(element);
    } else if (element instanceof TaskOutputs) {
        TaskOutputs outputs = (TaskOutputs) element;
        taskContext.add(outputs.getFiles());
    } else if (element instanceof RegularFileProperty || element instanceof DirectoryProperty) {
        taskContext.add(element);
    } else if (element instanceof Closure) {
        Closure closure = (Closure) element;
        Object closureResult = closure.call();
        if (closureResult != null) {
            add(closureResult);
        }
    } else if (element instanceof Callable) {
        Callable callable = (Callable) element;
        Object callableResult = uncheckedCall(callable);
        if (callableResult != null) {
            add(callableResult);
        }
    } else if (element instanceof Iterable && !(element instanceof Path)) {
        // Ignore Path
        Iterable<?> iterable = (Iterable) element;
        for (Object value : iterable) {
            add(value);
        }
    } else if (element instanceof Object[]) {
        Object[] array = (Object[]) element;
        for (Object value : array) {
            add(value);
        }
    }
    // Everything else assume has no dependencies
    return this;
}
Also used : Path(java.nio.file.Path) Task(org.gradle.api.Task) DirectoryProperty(org.gradle.api.file.DirectoryProperty) Closure(groovy.lang.Closure) RegularFileProperty(org.gradle.api.file.RegularFileProperty) TaskOutputs(org.gradle.api.tasks.TaskOutputs) Buildable(org.gradle.api.Buildable) Callable(java.util.concurrent.Callable)

Example 4 with TaskOutputs

use of org.gradle.api.tasks.TaskOutputs 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 5 with TaskOutputs

use of org.gradle.api.tasks.TaskOutputs in project gradle by gradle.

the class DefaultFileCollectionResolveContext method doResolve.

private <T> List<T> doResolve(Converter<? extends T> converter) {
    List<T> result = new ArrayList<T>();
    while (!queue.isEmpty()) {
        Object element = queue.remove(0);
        // TODO - need to sync with BuildDependenciesOnlyFileCollectionResolveContext
        if (element instanceof DefaultFileCollectionResolveContext) {
            DefaultFileCollectionResolveContext nestedContext = (DefaultFileCollectionResolveContext) element;
            converter.convertInto(nestedContext, result, fileResolver);
        } else if (element instanceof FileCollectionContainer) {
            FileCollectionContainer fileCollection = (FileCollectionContainer) element;
            resolveNested(fileCollection, result, converter);
        } else if (element instanceof FileCollection || element instanceof MinimalFileCollection) {
            converter.convertInto(element, result, fileResolver);
        } else if (element instanceof Task) {
            Task task = (Task) element;
            queue.add(0, task.getOutputs().getFiles());
        } else if (element instanceof TaskOutputs) {
            TaskOutputs outputs = (TaskOutputs) element;
            queue.add(0, outputs.getFiles());
        } else if (element instanceof Callable) {
            Callable callable = (Callable) element;
            Object callableResult = uncheckedCall(callable);
            if (callableResult != null) {
                queue.add(0, callableResult);
            }
        } else if (element instanceof Provider) {
            Provider provider = (Provider) element;
            Object providerResult = provider.get();
            queue.add(0, providerResult);
        } else if (element instanceof Path) {
            queue.add(0, ((Path) element).toFile());
        } else if (element instanceof Iterable) {
            Iterable<?> iterable = (Iterable) element;
            GUtil.addToCollection(queue.subList(0, 0), iterable);
        } else if (element instanceof Object[]) {
            Object[] array = (Object[]) element;
            GUtil.addToCollection(queue.subList(0, 0), Arrays.asList(array));
        } else {
            converter.convertInto(element, result, fileResolver);
        }
    }
    return result;
}
Also used : Path(java.nio.file.Path) Task(org.gradle.api.Task) ArrayList(java.util.ArrayList) TaskOutputs(org.gradle.api.tasks.TaskOutputs) FileCollection(org.gradle.api.file.FileCollection) Callable(java.util.concurrent.Callable) Provider(org.gradle.api.provider.Provider)

Aggregations

TaskOutputs (org.gradle.api.tasks.TaskOutputs)5 TaskInternal (org.gradle.api.internal.TaskInternal)3 DefaultTaskOutputs (org.gradle.api.internal.tasks.DefaultTaskOutputs)3 TaskStateInternal (org.gradle.api.internal.tasks.TaskStateInternal)3 Path (java.nio.file.Path)2 Callable (java.util.concurrent.Callable)2 Task (org.gradle.api.Task)2 TaskExecutionContext (org.gradle.api.internal.tasks.TaskExecutionContext)2 Expectations (org.jmock.Expectations)2 Closure (groovy.lang.Closure)1 ArrayList (java.util.ArrayList)1 Buildable (org.gradle.api.Buildable)1 DirectoryProperty (org.gradle.api.file.DirectoryProperty)1 FileCollection (org.gradle.api.file.FileCollection)1 RegularFileProperty (org.gradle.api.file.RegularFileProperty)1 Provider (org.gradle.api.provider.Provider)1