use of org.eclipse.che.api.promises.client.js.Executor.ExecutorBody in project che by eclipse.
the class TestServiceClient method runTestsAfterCompilation.
Promise<TestResult> runTestsAfterCompilation(String projectPath, String testFramework, Map<String, String> parameters, StatusNotification statusNotification, Promise<CommandImpl> compileCommand) {
return compileCommand.thenPromise(command -> {
final Machine machine;
if (command == null) {
machine = null;
} else {
machine = appContext.getDevMachine().getDescriptor();
}
if (machine == null) {
if (statusNotification != null) {
statusNotification.setContent("Executing the tests without preliminary compilation.");
}
return sendTests(projectPath, testFramework, parameters);
}
if (statusNotification != null) {
statusNotification.setContent("Compiling the project before starting the test session.");
}
return promiseFromExecutorBody(new ExecutorBody<TestResult>() {
boolean compiled = false;
@Override
public void apply(final ResolveFunction<TestResult> resolve, RejectFunction reject) {
macroProcessor.expandMacros(command.getCommandLine()).then(new Operation<String>() {
@Override
public void apply(String expandedCommandLine) throws OperationException {
CommandImpl expandedCommand = new CommandImpl(command.getName(), expandedCommandLine, command.getType(), command.getAttributes());
final CommandOutputConsole console = commandConsoleFactory.create(expandedCommand, machine);
final String machineId = machine.getId();
processesPanelPresenter.addCommandOutput(machineId, console);
execAgentCommandManager.startProcess(machineId, expandedCommand).then(startResonse -> {
if (!startResonse.getAlive()) {
reject.apply(promiseFromThrowable(new Throwable(PROJECT_BUILD_NOT_STARTED_MESSAGE)));
}
}).thenIfProcessStartedEvent(console.getProcessStartedOperation()).thenIfProcessStdErrEvent(evt -> {
if (evt.getText().contains("BUILD SUCCESS")) {
compiled = true;
}
console.getStdErrOperation().apply(evt);
}).thenIfProcessStdOutEvent(evt -> {
if (evt.getText().contains("BUILD SUCCESS")) {
compiled = true;
}
console.getStdOutOperation().apply(evt);
}).thenIfProcessDiedEvent(evt -> {
console.getProcessDiedOperation().apply(evt);
if (compiled) {
if (statusNotification != null) {
statusNotification.setContent(EXECUTING_TESTS_MESSAGE);
}
sendTests(projectPath, testFramework, parameters).then(new Operation<TestResult>() {
@Override
public void apply(TestResult result) throws OperationException {
resolve.apply(result);
}
});
} else {
reject.apply(promiseFromThrowable(new Throwable(PROJECT_BUILD_FAILED_MESSAGE)));
}
});
}
});
}
});
});
}
Aggregations