Search in sources :

Example 26 with CommandImpl

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

the class TestServiceClientTest method runTestsDirectlyBecauseNoDevMachine.

@Test
public void runTestsDirectlyBecauseNoDevMachine() {
    Promise<CommandImpl> compileCommandPromise = createCommandPromise(new CommandImpl("test-compile", "mvn test-compile -f ${current.project.path}", "mvn"));
    when(devMachine.getDescriptor()).thenReturn(null);
    testServiceClient.runTestsAfterCompilation(projectPath, testFramework, parameters, statusNotification, compileCommandPromise);
    verify(statusNotification).setContent("Executing the tests without preliminary compilation.");
    verify(execAgentCommandManager, never()).startProcess(anyString(), Matchers.<Command>any());
    verify(testServiceClient).sendTests(projectPath, testFramework, parameters);
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) Test(org.junit.Test)

Example 27 with CommandImpl

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

the class ProcessesPanelPresenter method restoreState.

private void restoreState(final MachineEntity machine) {
    execAgentCommandManager.getProcesses(machine.getId(), false).then(new Operation<List<GetProcessesResponseDto>>() {

        @Override
        public void apply(List<GetProcessesResponseDto> processes) throws OperationException {
            for (GetProcessesResponseDto process : processes) {
                final int pid = process.getPid();
                final String type = process.getType();
                /*
                     * Do not show the process if the command line has prefix #hidden
                     */
                if (!isNullOrEmpty(process.getCommandLine()) && process.getCommandLine().startsWith("#hidden")) {
                    continue;
                }
                /*
                     * Hide the processes which are launched by command of unknown type
                     */
                if (isProcessLaunchedByCommandOfKnownType(type)) {
                    final String processName = process.getName();
                    final CommandImpl commandByName = getWorkspaceCommandByName(processName);
                    if (commandByName == null) {
                        final String commandLine = process.getCommandLine();
                        final CommandImpl command = new CommandImpl(processName, commandLine, type);
                        final CommandOutputConsole console = commandConsoleFactory.create(command, machine);
                        getAndPrintProcessLogs(console, pid);
                        subscribeToProcess(console, pid);
                        addCommandOutput(machine.getId(), console);
                    } else {
                        macroProcessor.expandMacros(commandByName.getCommandLine()).then(new Operation<String>() {

                            @Override
                            public void apply(String expandedCommandLine) throws OperationException {
                                final CommandImpl command = new CommandImpl(commandByName.getName(), expandedCommandLine, commandByName.getType(), commandByName.getAttributes());
                                final CommandOutputConsole console = commandConsoleFactory.create(command, machine);
                                getAndPrintProcessLogs(console, pid);
                                subscribeToProcess(console, pid);
                                addCommandOutput(machine.getId(), console);
                            }
                        });
                    }
                }
            }
        }

        private void getAndPrintProcessLogs(final CommandOutputConsole console, final int pid) {
            String from = null;
            String till = null;
            int limit = 50;
            int skip = 0;
            execAgentCommandManager.getProcessLogs(machine.getId(), pid, from, till, limit, skip).then(new Operation<List<GetProcessLogsResponseDto>>() {

                @Override
                public void apply(List<GetProcessLogsResponseDto> logs) throws OperationException {
                    for (GetProcessLogsResponseDto log : logs) {
                        String text = log.getText();
                        console.printOutput(text);
                    }
                }
            }).catchError(new Operation<PromiseError>() {

                @Override
                public void apply(PromiseError arg) throws OperationException {
                    String error = "Error trying to get process log with pid: " + pid + ". " + arg.getMessage();
                    Log.error(getClass(), error);
                }
            });
        }

        private void subscribeToProcess(CommandOutputConsole console, int pid) {
            String stderr = "stderr";
            String stdout = "stdout";
            String processStatus = "process_status";
            String after = null;
            execAgentCommandManager.subscribe(machine.getId(), pid, asList(stderr, stdout, processStatus), after).thenIfProcessStartedEvent(console.getProcessStartedOperation()).thenIfProcessDiedEvent(console.getProcessDiedOperation()).thenIfProcessStdOutEvent(console.getStdOutOperation()).thenIfProcessStdErrEvent(console.getStdErrOperation()).then(console.getProcessSubscribeOperation());
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            notificationManager.notify(localizationConstant.failedToGetProcesses(machine.getId()));
        }
    });
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) GetProcessLogsResponseDto(org.eclipse.che.api.machine.shared.dto.execagent.GetProcessLogsResponseDto) GetProcessesResponseDto(org.eclipse.che.api.machine.shared.dto.execagent.GetProcessesResponseDto) Operation(org.eclipse.che.api.promises.client.Operation) PromiseError(org.eclipse.che.api.promises.client.PromiseError) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ArrayList(java.util.ArrayList) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 28 with CommandImpl

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

the class EditCommandsPresenterTest method setUp.

@Before
public void setUp() {
    presenter.editedCommandNameInitial = COMMAND_NAME;
    when(commandManager.update(anyString(), anyObject())).thenReturn(commandPromise);
    CommandType commandType = mock(CommandType.class);
    when(commandType.getId()).thenReturn(COMMAND_TYPE);
    List<CommandType> commandTypes = new ArrayList<>(1);
    commandTypes.add(commandType);
    when(commandTypeRegistry.getCommandTypes()).thenReturn(commandTypes);
    when(command.getType()).thenReturn(COMMAND_TYPE);
    when(command.getName()).thenReturn(COMMAND_NAME);
    List<CommandImpl> commands = new ArrayList<>(1);
    commands.add(command);
    when(commandManager.getCommands()).thenReturn(commands);
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) CommandType(org.eclipse.che.ide.api.command.CommandType) ArrayList(java.util.ArrayList) Before(org.junit.Before)

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