Search in sources :

Example 6 with CommandImpl

use of org.eclipse.che.ide.api.command.CommandImpl in project che by eclipse.

the class EditCommandsPresenter method onPreviewUrlChanged.

@Override
public void onPreviewUrlChanged() {
    final CommandImpl selectedCommand = view.getSelectedCommand();
    if (selectedCommand == null || !selectedCommand.equals(editedCommand)) {
        return;
    }
    selectedCommand.getAttributes().put(PREVIEW_URL_ATTR, view.getCommandPreviewUrl());
    view.setCancelButtonState(isViewModified());
    view.setSaveButtonState(isViewModified());
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl)

Example 7 with CommandImpl

use of org.eclipse.che.ide.api.command.CommandImpl in project che by eclipse.

the class EditCommandsPresenter method createNewCommand.

private void createNewCommand(final String type, final String commandLine, final String name, final Map<String, String> attributes) {
    if (!isViewModified()) {
        createCommand(type, commandLine, name, attributes);
        return;
    }
    final ConfirmCallback saveCallback = new ConfirmCallback() {

        @Override
        public void accepted() {
            updateCommand(editedCommand).then(new Operation<CommandImpl>() {

                @Override
                public void apply(CommandImpl arg) throws OperationException {
                    createCommand(type, commandLine, name, attributes);
                }
            });
        }
    };
    final ConfirmCallback discardCallback = new ConfirmCallback() {

        @Override
        public void accepted() {
            refreshView();
            createCommand(type, commandLine, name, attributes);
        }
    };
    ChoiceDialog dialog = dialogFactory.createChoiceDialog(machineLocale.editCommandsSaveChangesTitle(), machineLocale.editCommandsSaveChangesConfirmation(editedCommand.getName()), coreLocale.save(), machineLocale.editCommandsSaveChangesDiscard(), saveCallback, discardCallback);
    dialog.show();
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) ChoiceDialog(org.eclipse.che.ide.api.dialogs.ChoiceDialog) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 8 with CommandImpl

use of org.eclipse.che.ide.api.command.CommandImpl 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)));
                            }
                        });
                    }
                });
            }
        });
    });
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) CommandManager(org.eclipse.che.ide.api.command.CommandManager) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) AsyncRequestFactory(org.eclipse.che.ide.rest.AsyncRequestFactory) JsPromiseError(org.eclipse.che.api.promises.client.js.JsPromiseError) CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) Executor(org.eclipse.che.api.promises.client.js.Executor) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Promise(org.eclipse.che.api.promises.client.Promise) ExecutorBody(org.eclipse.che.api.promises.client.js.Executor.ExecutorBody) AppContext(org.eclipse.che.ide.api.app.AppContext) Map(java.util.Map) RejectFunction(org.eclipse.che.api.promises.client.js.RejectFunction) URL(com.google.gwt.http.client.URL) HTTPHeader(org.eclipse.che.ide.rest.HTTPHeader) Operation(org.eclipse.che.api.promises.client.Operation) CommandConsoleFactory(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandConsoleFactory) DtoUnmarshallerFactory(org.eclipse.che.ide.rest.DtoUnmarshallerFactory) DtoFactory(org.eclipse.che.ide.dto.DtoFactory) OperationException(org.eclipse.che.api.promises.client.OperationException) StatusNotification(org.eclipse.che.ide.api.notification.StatusNotification) PromiseProvider(org.eclipse.che.api.promises.client.PromiseProvider) MatchResult(com.google.gwt.regexp.shared.MatchResult) Machine(org.eclipse.che.api.core.model.machine.Machine) ExecAgentCommandManager(org.eclipse.che.ide.api.machine.ExecAgentCommandManager) List(java.util.List) MimeType(org.eclipse.che.ide.MimeType) TestResult(org.eclipse.che.api.testing.shared.TestResult) RegExp(com.google.gwt.regexp.shared.RegExp) ResolveFunction(org.eclipse.che.api.promises.client.js.ResolveFunction) MacroProcessor(org.eclipse.che.ide.api.macro.MacroProcessor) ProcessesPanelPresenter(org.eclipse.che.ide.extension.machine.client.processes.panel.ProcessesPanelPresenter) Singleton(com.google.inject.Singleton) TestResult(org.eclipse.che.api.testing.shared.TestResult) Operation(org.eclipse.che.api.promises.client.Operation) Machine(org.eclipse.che.api.core.model.machine.Machine) RejectFunction(org.eclipse.che.api.promises.client.js.RejectFunction) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 9 with CommandImpl

use of org.eclipse.che.ide.api.command.CommandImpl in project che by eclipse.

the class TestServiceClientTest method cancelledTestsBecauseCompilationNotStarted.

@Test
public void cancelledTestsBecauseCompilationNotStarted() {
    Promise<CommandImpl> compileCommandPromise = createCommandPromise(new CommandImpl("test-compile", "mvn test-compile -f ${current.project.path}", "mvn"));
    when(devMachine.getDescriptor()).thenReturn(machine);
    Promise<TestResult> result = testServiceClient.runTestsAfterCompilation(projectPath, testFramework, parameters, statusNotification, compileCommandPromise);
    triggerProcessEvents(processStartResponse(false));
    verify(testServiceClient, never()).sendTests(anyString(), anyString(), anyMapOf(String.class, String.class));
    verify(statusNotification).setContent("Compiling the project before starting the test session.");
    result.catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError promiseError) throws OperationException {
            Throwable cause = promiseError.getCause();
            Assert.assertNotNull(cause);
            Assert.assertEquals(TestServiceClient.PROJECT_BUILD_NOT_STARTED_MESSAGE, cause.getMessage());
        }
    });
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) PromiseError(org.eclipse.che.api.promises.client.PromiseError) TestResult(org.eclipse.che.api.testing.shared.TestResult) Matchers.anyString(org.mockito.Matchers.anyString) OperationException(org.eclipse.che.api.promises.client.OperationException) Test(org.junit.Test)

Example 10 with CommandImpl

use of org.eclipse.che.ide.api.command.CommandImpl in project che by eclipse.

the class TestServiceClientTest method cancelledTestsBecauseCompilationFailed.

@Test
public void cancelledTestsBecauseCompilationFailed() {
    Promise<CommandImpl> compileCommandPromise = createCommandPromise(new CommandImpl("test-compile", "mvn test-compile -f ${current.project.path}", "mvn"));
    when(devMachine.getDescriptor()).thenReturn(machine);
    Promise<TestResult> result = testServiceClient.runTestsAfterCompilation(projectPath, testFramework, parameters, statusNotification, compileCommandPromise);
    triggerProcessEvents(processStartResponse(true), processStarted(), processStdErr("A small warning"), processStdOut("BUILD FAILURE"), processDied());
    verify(testServiceClient, never()).sendTests(anyString(), anyString(), anyMapOf(String.class, String.class));
    verify(statusNotification).setContent("Compiling the project before starting the test session.");
    result.catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError promiseError) throws OperationException {
            Throwable cause = promiseError.getCause();
            Assert.assertNotNull(cause);
            Assert.assertEquals(TestServiceClient.PROJECT_BUILD_FAILED_MESSAGE, cause.getMessage());
        }
    });
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) PromiseError(org.eclipse.che.api.promises.client.PromiseError) TestResult(org.eclipse.che.api.testing.shared.TestResult) Matchers.anyString(org.mockito.Matchers.anyString) OperationException(org.eclipse.che.api.promises.client.OperationException) Test(org.junit.Test)

Aggregations

CommandImpl (org.eclipse.che.ide.api.command.CommandImpl)28 OperationException (org.eclipse.che.api.promises.client.OperationException)9 CommandType (org.eclipse.che.ide.api.command.CommandType)6 ArrayList (java.util.ArrayList)5 PromiseError (org.eclipse.che.api.promises.client.PromiseError)5 Test (org.junit.Test)5 TestResult (org.eclipse.che.api.testing.shared.TestResult)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Operation (org.eclipse.che.api.promises.client.Operation)3 ConfirmCallback (org.eclipse.che.ide.api.dialogs.ConfirmCallback)3 CommandOutputConsole (org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole)3 Matchers.anyString (org.mockito.Matchers.anyString)3 MatchResult (com.google.gwt.regexp.shared.MatchResult)2 Machine (org.eclipse.che.api.core.model.machine.Machine)2 ChoiceDialog (org.eclipse.che.ide.api.dialogs.ChoiceDialog)2 URL (com.google.gwt.http.client.URL)1 RegExp (com.google.gwt.regexp.shared.RegExp)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1