use of org.gradle.api.internal.TaskExecutionHistory 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);
}
Aggregations