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);
}
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;
}
Aggregations