public TaskArtifactState getStateFor(final TaskInternal task) { if (!task.getOutputs().getHasOutput()) { // Only false if no declared outputs AND no Task.upToDateWhen spec. We force to true for incremental tasks. return new NoHistoryArtifactState(); } final TaskArtifactState state = repository.getStateFor(task); if (startParameter.isRerunTasks()) { return new RerunTaskArtifactState(state, task, "Executed with '--rerun-tasks'."); } if (!task.getOutputs().getUpToDateSpec().isSatisfiedBy(task)) { return new RerunTaskArtifactState(state, task, "Task.upToDateWhen is false."); } return state; }
public void execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) { LOGGER.debug("Determining if {} is up-to-date", task); Timer clock = Timers.startTimer(); TaskArtifactState taskArtifactState = context.getTaskArtifactState(); try { List<String> messages = LOGGER.isInfoEnabled() ? new ArrayList<String>() : null; if (taskArtifactState.isUpToDate(messages)) { LOGGER.info("Skipping {} as it is up-to-date (took {}).", task, clock.getElapsed()); state.setOutcome(TaskExecutionOutcome.UP_TO_DATE); return; } logOutOfDateMessages(messages, task, clock.getElapsed()); task.getOutputs().setHistory(taskArtifactState.getExecutionHistory()); taskArtifactState.beforeTask(); try { executer.execute(task, state, context); if (state.getFailure() == null) { taskArtifactState.afterTask(); } } finally { task.getOutputs().setHistory(null); } } finally { taskArtifactState.finished(); } }
public void execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) { LOGGER.debug("Determining if {} is up-to-date", task); Clock clock = new Clock(); TaskArtifactState taskArtifactState = repository.getStateFor(task); try { List<String> messages = new ArrayList<String>(); if (taskArtifactState.isUpToDate(messages)) { LOGGER.info("Skipping {} as it is up-to-date (took {}).", task, clock.getTime()); state.upToDate(); return; } logOutOfDateMessages(messages, task, clock.getTime()); task.getOutputs().setHistory(taskArtifactState.getExecutionHistory()); context.setTaskArtifactState(taskArtifactState); taskArtifactState.beforeTask(); try { executer.execute(task, state, context); if (state.getFailure() == null) { taskArtifactState.afterTask(); } } finally { task.getOutputs().setHistory(null); context.setTaskArtifactState(null); } } finally { taskArtifactState.finished(); } }
@Override public void setTaskArtifactState(TaskArtifactState taskArtifactState) { if (taskArtifactState != null) { mTaskArtifactState = new IgnoreResFilesTaskArtifactStateWrapper(taskArtifactState, mResFiles); } else { mTaskArtifactState = null; } }
public IgnoreResFilesTaskArtifactStateWrapper(TaskArtifactState taskArtifactState, Set<File> resFiles) { mTaskArtifactState = taskArtifactState; mIncrementalTaskInputs = new IgnoreResFilesIncrementalTaskInputsWrapper(taskArtifactState.getInputChanges(), resFiles); mTaskExecutionHistory = new IgnoreResFilesTaskExecutionHistoryWrapper(taskArtifactState.getExecutionHistory(), resFiles); }
public TaskArtifactState getTaskArtifactState() { return taskArtifactState; }
public void setTaskArtifactState(TaskArtifactState taskArtifactState) { this.taskArtifactState = taskArtifactState; }
public void execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) { FileCollection sourceFiles = task.getInputs().getSourceFiles(); if (task.getInputs().getHasSourceFiles() && sourceFiles.isEmpty()) { TaskArtifactState taskArtifactState = context.getTaskArtifactState(); FileCollection outputFiles = taskArtifactState.getExecutionHistory().getOutputFiles(); if (outputFiles == null) { state.setOutcome(TaskExecutionOutcome.UP_TO_DATE); LOGGER.info("Skipping {} as it has no source files and no history of previous output files.", task); } else if (outputFiles.isEmpty()) { state.setOutcome(TaskExecutionOutcome.UP_TO_DATE); LOGGER.info("Skipping {} as it has no source files and no previous output files.", task); } else { Set<File> outputFileSet = outputFiles.getFiles(); boolean deletedFiles = false; boolean debugEnabled = LOGGER.isDebugEnabled(); for (File file : outputFileSet) { if (file.isFile()) { if (file.delete()) { if (debugEnabled) { LOGGER.debug("Deleted stale output file '{}'.", file.getAbsolutePath()); } } else { state.setOutcome(new GradleException(String.format("Could not delete file: '%s'.", file.getAbsolutePath()))); return; } 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.UP_TO_DATE); } } taskInputsListener.onExecute(task, Cast.cast(FileCollectionInternal.class, sourceFiles)); return; } else { taskInputsListener.onExecute(task, Cast.cast(FileCollectionInternal.class, task.getInputs().getFiles())); } executer.execute(task, state, context); }
public TaskArtifactState getStateFor(final TaskInternal task) { return new TaskArtifactStateImpl(task, taskHistoryRepository.getHistory(task)); }
private RerunTaskArtifactState(TaskArtifactState delegate, TaskInternal task, String reason) { this.delegate = delegate; this.task = task; this.reason = reason; }
@Override public TaskArtifactState getTaskArtifactState() { return mTaskArtifactState; }
TaskArtifactState getTaskArtifactState();
void setTaskArtifactState(TaskArtifactState taskArtifactState);