Search in sources :

Example 6 with TaskArtifactState

use of org.gradle.api.internal.changedetection.TaskArtifactState in project gradle by gradle.

the class SkipEmptySourceFilesTaskExecuter method execute.

public void execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
    TaskProperties taskProperties = context.getTaskProperties();
    FileCollection sourceFiles = taskProperties.getSourceFiles();
    if (taskProperties.hasSourceFiles() && sourceFiles.isEmpty()) {
        TaskArtifactState taskArtifactState = context.getTaskArtifactState();
        TaskExecutionHistory executionHistory = taskArtifactState.getExecutionHistory();
        Set<File> outputFiles = executionHistory.getOutputFiles();
        if (outputFiles.isEmpty()) {
            state.setOutcome(TaskExecutionOutcome.NO_SOURCE);
            LOGGER.info("Skipping {} as it has no source files and no previous output files.", task);
        } else {
            boolean cleanupDirectories = executionHistory.getOverlappingOutputs() == null;
            if (!cleanupDirectories) {
                LOGGER.info("No leftover directories for {} will be deleted since overlapping outputs were detected.", task);
            }
            taskOutputChangesListener.beforeTaskOutputChanged();
            boolean deletedFiles = false;
            boolean debugEnabled = LOGGER.isDebugEnabled();
            for (File file : outputFiles) {
                if (file.exists() && buildOutputCleanupRegistry.isOutputOwnedByBuild(file)) {
                    if (!cleanupDirectories && file.isDirectory()) {
                        continue;
                    }
                    if (debugEnabled) {
                        LOGGER.debug("Deleting stale output file '{}'.", file.getAbsolutePath());
                    }
                    GFileUtils.forceDelete(file);
                    deletedFiles = true;
                }
            }
            if (deletedFiles) {
                LOGGER.info("Cleaned previous output of {} as it has no source files.", task);
                state.setOutcome(TaskExecutionOutcome.EXECUTED);
            } else {
                state.setOutcome(TaskExecutionOutcome.NO_SOURCE);
            }
            taskArtifactState.snapshotAfterTaskExecution(null, buildInvocationScopeId.getId(), context);
        }
        taskInputsListener.onExecute(task, Cast.cast(FileCollectionInternal.class, sourceFiles));
        return;
    } else {
        taskInputsListener.onExecute(task, Cast.cast(FileCollectionInternal.class, taskProperties.getInputFiles()));
    }
    executer.execute(task, state, context);
}
Also used : TaskArtifactState(org.gradle.api.internal.changedetection.TaskArtifactState) FileCollectionInternal(org.gradle.api.internal.file.FileCollectionInternal) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File) TaskExecutionHistory(org.gradle.api.internal.TaskExecutionHistory)

Example 7 with TaskArtifactState

use of org.gradle.api.internal.changedetection.TaskArtifactState in project gradle by gradle.

the class ShortCircuitTaskArtifactStateRepository method getStateFor.

public TaskArtifactState getStateFor(final TaskInternal task, TaskProperties taskProperties) {
    // Only false if no declared outputs AND no Task.upToDateWhen spec. We force to true for incremental tasks.
    AndSpec<? super TaskInternal> upToDateSpec = task.getOutputs().getUpToDateSpec();
    if (!taskProperties.hasDeclaredOutputs() && upToDateSpec.isEmpty()) {
        if (task.hasTaskActions()) {
            return NoOutputsArtifactState.WITH_ACTIONS;
        } else {
            return NoOutputsArtifactState.WITHOUT_ACTIONS;
        }
    }
    TaskArtifactState state = repository.getStateFor(task, taskProperties);
    if (startParameter.isRerunTasks()) {
        return new RerunTaskArtifactState(state, task, "Executed with '--rerun-tasks'.");
    }
    if (!upToDateSpec.isSatisfiedBy(task)) {
        return new RerunTaskArtifactState(state, task, "Task.upToDateWhen is false.");
    }
    return state;
}
Also used : TaskArtifactState(org.gradle.api.internal.changedetection.TaskArtifactState)

Aggregations

TaskArtifactState (org.gradle.api.internal.changedetection.TaskArtifactState)7 TaskOutputCachingBuildCacheKey (org.gradle.caching.internal.tasks.TaskOutputCachingBuildCacheKey)3 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 FileCollection (org.gradle.api.file.FileCollection)1 TaskExecutionHistory (org.gradle.api.internal.TaskExecutionHistory)1 TaskOutputsInternal (org.gradle.api.internal.TaskOutputsInternal)1 FileCollectionInternal (org.gradle.api.internal.file.FileCollectionInternal)1 OriginTaskExecutionMetadata (org.gradle.api.internal.tasks.OriginTaskExecutionMetadata)1 ResolvedTaskOutputFilePropertySpec (org.gradle.api.internal.tasks.ResolvedTaskOutputFilePropertySpec)1 LogLevel (org.gradle.api.logging.LogLevel)1 UnrecoverableTaskOutputUnpackingException (org.gradle.caching.internal.tasks.UnrecoverableTaskOutputUnpackingException)1 Timer (org.gradle.internal.time.Timer)1