TaskOutputDef outputDef = taskDef.getOutputDef();
TaskOutputKey outputDefKey = outputDef.getKey();
String outputDefCaption = outputDef.getCaption();
try (IOTabRef<TaskIOTab> ioRef = IOTabs.taskTabs().getTab(outputDefKey, outputDefCaption)) {
TaskIOTab tab = ioRef.getTab();
tab.setLastTask(buildItem.getSourceTaskDef(), adjust(taskDef));
tab.taskStarted();
BuildExecutionSupport.registerRunningItem(buildItem);
try {
OutputWriter buildOutput = tab.getIo().getOutRef();
if (GlobalGradleSettings.getAlwaysClearOutput().getValue()
|| taskDef.isCleanOutput()) {
buildOutput.reset();
// There is no need to reset buildErrOutput,
// at least this is what NetBeans tells you in its
// logs if you do.
}
printCommand(buildOutput, command, taskDef);
try (OutputRef outputRef = configureOutput(project, taskDef, buildLauncher, tab)) {
assert outputRef != null; // Avoid warning
InputOutputWrapper io = tab.getIo();
io.getIo().select();
if (checkTaskExecutable(projectConnection, taskDef, targetSetup, io)) {
runBuild(cancelToken, buildLauncher);
taskDef.getSuccessfulCommandFinalizer().finalizeSuccessfulCommand(
buildOutput,
io.getErrRef());
}
}
} catch (Throwable ex) {
Level logLevel;
if (taskDef.getCommandExceptionHider().hideException(ex)) {
logLevel = Level.INFO;
}
else {
commandError = ex;
logLevel = ex instanceof Exception ? Level.INFO : Level.SEVERE;
}
LOGGER.log(logLevel, "Gradle build failure: " + command, ex);
String buildFailureMessage = NbStrings.getBuildFailure(command);
OutputWriter buildErrOutput = tab.getIo().getErrRef();
buildErrOutput.println();
buildErrOutput.println(buildFailureMessage);
if (commandError != null) {
project.displayError(buildFailureMessage, commandError);
}
}
tab.taskCompleted();
}
buildItem.markFinished();
BuildExecutionSupport.registerFinishedItem(buildItem);
} finally {
closeAll(initScripts);