Search in sources :

Example 1 with ContextAwareTaskAction

use of org.gradle.api.internal.tasks.ContextAwareTaskAction in project gradle by gradle.

the class CacheBackedTaskHistoryRepository method createExecution.

private CurrentTaskExecution createExecution(TaskInternal task, TaskProperties taskProperties, @Nullable HistoricalTaskExecution previousExecution, InputNormalizationStrategy normalizationStrategy) {
    Class<? extends TaskInternal> taskClass = task.getClass();
    List<ContextAwareTaskAction> taskActions = task.getTaskActions();
    ImplementationSnapshot taskImplementation = new ImplementationSnapshot(taskClass.getName(), classLoaderHierarchyHasher.getClassLoaderHash(taskClass.getClassLoader()));
    ImmutableList<ImplementationSnapshot> taskActionImplementations = collectActionImplementations(taskActions, classLoaderHierarchyHasher);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Implementation for {}: {}", task, taskImplementation);
        LOGGER.debug("Action implementations for {}: {}", task, taskActionImplementations);
    }
    ImmutableSortedMap<String, ValueSnapshot> previousInputProperties = previousExecution == null ? ImmutableSortedMap.<String, ValueSnapshot>of() : previousExecution.getInputProperties();
    ImmutableSortedMap<String, ValueSnapshot> inputProperties = snapshotTaskInputProperties(task, taskProperties, previousInputProperties, valueSnapshotter);
    ImmutableSortedSet<String> outputPropertyNames = getOutputPropertyNamesForCacheKey(taskProperties);
    ImmutableSet<String> declaredOutputFilePaths = getDeclaredOutputFilePaths(taskProperties, stringInterner);
    ImmutableSortedMap<String, FileCollectionSnapshot> inputFiles = snapshotTaskFiles(task, "Input", normalizationStrategy, taskProperties.getInputFileProperties(), snapshotterRegistry);
    ImmutableSortedMap<String, FileCollectionSnapshot> outputFiles = snapshotTaskFiles(task, "Output", normalizationStrategy, taskProperties.getOutputFileProperties(), snapshotterRegistry);
    FileCollectionSnapshot previousDiscoveredInputs = previousExecution == null ? null : previousExecution.getDiscoveredInputFilesSnapshot();
    FileCollectionSnapshot discoveredInputs;
    if (previousDiscoveredInputs != null) {
        discoveredInputs = snapshotDiscoveredInputs(task, normalizationStrategy, previousDiscoveredInputs.getElements(), snapshotterRegistry, fileCollectionFactory);
    } else {
        discoveredInputs = EmptyFileCollectionSnapshot.INSTANCE;
    }
    OverlappingOutputs overlappingOutputs = detectOverlappingOutputs(outputFiles, previousExecution);
    return new CurrentTaskExecution(taskImplementation, taskActionImplementations, inputProperties, outputPropertyNames, declaredOutputFilePaths, inputFiles, discoveredInputs, outputFiles, overlappingOutputs);
}
Also used : OverlappingOutputs(org.gradle.api.internal.OverlappingOutputs) ContextAwareTaskAction(org.gradle.api.internal.tasks.ContextAwareTaskAction)

Example 2 with ContextAwareTaskAction

use of org.gradle.api.internal.tasks.ContextAwareTaskAction in project gradle by gradle.

the class ExecuteActionsTaskExecuter method executeActions.

private GradleException executeActions(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
    LOGGER.debug("Executing actions for {}.", task);
    final List<ContextAwareTaskAction> actions = new ArrayList<ContextAwareTaskAction>(task.getTaskActions());
    for (ContextAwareTaskAction action : actions) {
        state.setDidWork(true);
        task.getStandardOutputCapture().start();
        try {
            executeAction(action.getDisplayName(), task, action, context);
        } catch (StopActionException e) {
            // Ignore
            LOGGER.debug("Action stopped by some action with message: {}", e.getMessage());
        } catch (StopExecutionException e) {
            LOGGER.info("Execution stopped by some action with message: {}", e.getMessage());
            break;
        } catch (Throwable t) {
            return new TaskExecutionException(task, t);
        } finally {
            task.getStandardOutputCapture().stop();
        }
    }
    return null;
}
Also used : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) StopExecutionException(org.gradle.api.tasks.StopExecutionException) ContextAwareTaskAction(org.gradle.api.internal.tasks.ContextAwareTaskAction) StopActionException(org.gradle.api.tasks.StopActionException) ArrayList(java.util.ArrayList)

Example 3 with ContextAwareTaskAction

use of org.gradle.api.internal.tasks.ContextAwareTaskAction in project gradle by gradle.

the class CacheBackedTaskHistoryRepository method collectActionImplementations.

private static ImmutableList<ImplementationSnapshot> collectActionImplementations(Collection<ContextAwareTaskAction> taskActions, ClassLoaderHierarchyHasher classLoaderHierarchyHasher) {
    if (taskActions.isEmpty()) {
        return ImmutableList.of();
    }
    ImmutableList.Builder<ImplementationSnapshot> actionImplementations = ImmutableList.builder();
    for (ContextAwareTaskAction taskAction : taskActions) {
        String typeName = taskAction.getActionClassName();
        HashCode classLoaderHash = classLoaderHierarchyHasher.getClassLoaderHash(taskAction.getClassLoader());
        actionImplementations.add(new ImplementationSnapshot(typeName, classLoaderHash));
    }
    return actionImplementations.build();
}
Also used : HashCode(org.gradle.internal.hash.HashCode) ContextAwareTaskAction(org.gradle.api.internal.tasks.ContextAwareTaskAction) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

ContextAwareTaskAction (org.gradle.api.internal.tasks.ContextAwareTaskAction)3 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 OverlappingOutputs (org.gradle.api.internal.OverlappingOutputs)1 StopActionException (org.gradle.api.tasks.StopActionException)1 StopExecutionException (org.gradle.api.tasks.StopExecutionException)1 TaskExecutionException (org.gradle.api.tasks.TaskExecutionException)1 HashCode (org.gradle.internal.hash.HashCode)1