From f1322013216739598f40818b440807fa3ce8bde1 Mon Sep 17 00:00:00 2001 From: Vitalii Parfonov Date: Sun, 15 Jul 2018 10:35:13 +0300 Subject: [PATCH 01/10] Add ability to open selected folder in terminal Signed-off-by: Vitalii Parfonov --- .../che/ide/CoreLocalizationConstant.java | 7 ++ .../core/StandardComponentInitializer.java | 5 + .../panel/ProcessesPanelPresenter.java | 2 +- .../che/ide/terminal/TerminalOptionsJso.java | 12 ++- .../che/ide/terminal/TerminalPresenter.java | 16 +++- .../ide/CoreLocalizationConstant.properties | 1 + .../org/eclipse/che/ide/public/loader.html | 10 ++ ...stProjectExplorerContextMenuConstants.java | 1 + .../miscellaneous/OpenInTerminalTest.java | 92 +++++++++++++++++++ 9 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 ide/che-ide-gwt-app/src/main/resources/org/eclipse/che/ide/public/loader.html create mode 100644 selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/CoreLocalizationConstant.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/CoreLocalizationConstant.java index 6d7c775de10..a292c15d87e 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/CoreLocalizationConstant.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/CoreLocalizationConstant.java @@ -1229,6 +1229,13 @@ String sshConnectInfo( @Key("control.terminal.create.description") String newTerminalDescription(); + @Key("control.open.in.terminal") + @DefaultMessage("Open in Terminal") + String openInTerminalAction(); + + @Key("open.in.terminal.command") + String openInTerminalCommand(String path); + @Key("machine.output.action.title") String machineOutputActionTitle(); diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/core/StandardComponentInitializer.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/core/StandardComponentInitializer.java index 7b3bfede0fe..e722d749b8d 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/core/StandardComponentInitializer.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/core/StandardComponentInitializer.java @@ -144,6 +144,7 @@ import org.eclipse.che.ide.part.explorer.project.TreeResourceRevealer; import org.eclipse.che.ide.part.explorer.project.synchronize.ProjectConfigSynchronized; import org.eclipse.che.ide.processes.NewTerminalAction; +import org.eclipse.che.ide.processes.OpenInTerminalAction; import org.eclipse.che.ide.processes.actions.CloseConsoleAction; import org.eclipse.che.ide.processes.actions.DisplayMachineOutputAction; import org.eclipse.che.ide.processes.actions.PreviewSSHAction; @@ -403,6 +404,8 @@ public interface ParserResource extends ClientBundle { @Inject private MoveCommandAction moveCommandAction; + @Inject private OpenInTerminalAction openInTerminalAction; + @Inject @Named("XMLFileType") private FileType xmlFile; @@ -744,6 +747,8 @@ public void initialize() { mainContextMenuGroup.add(newGroup, FIRST); mainContextMenuGroup.addSeparator(); mainContextMenuGroup.add(resourceOperation); + mainContextMenuGroup.add(openInTerminalAction); + actionManager.registerAction("openInTerminal", openInTerminalAction); DefaultActionGroup partMenuGroup = (DefaultActionGroup) actionManager.getAction(GROUP_PART_MENU); diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/panel/ProcessesPanelPresenter.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/panel/ProcessesPanelPresenter.java index cb0341e565e..faf55c29bcd 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/panel/ProcessesPanelPresenter.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/panel/ProcessesPanelPresenter.java @@ -521,7 +521,7 @@ public void onAddTerminal(final String machineId, TerminalOptionsJso options, bo workspaceAgentProvider.get().setActivePart(this); newTerminal.setVisible(true); - newTerminal.connect(); + newTerminal.connect(options); newTerminal.setListener(() -> onCloseTerminal(terminalNode)); } diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalOptionsJso.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalOptionsJso.java index 4dc641d9086..71f80f37353 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalOptionsJso.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalOptionsJso.java @@ -21,7 +21,8 @@ public static native TerminalOptionsJso createDefault() /*-{ cols: 80, rows: 24, screenKeys: true, - focusOnOpen: true + focusOnOpen: true, + command: "" } }-*/; @@ -29,4 +30,13 @@ public final native TerminalOptionsJso withFocusOnOpen(boolean focusOnOpen) /*-{ this.focusOnOpen = focusOnOpen; return this; }-*/; + + public final native TerminalOptionsJso withCommand(String command) /*-{ + this.command = command; + return this; + }-*/; + + public final native String getCommand() /*-{ + return this.command; + }-*/; } diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java index 418b958ac82..62ad6f36739 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java @@ -16,6 +16,7 @@ import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; import static org.eclipse.che.ide.websocket.events.WebSocketClosedEvent.CLOSE_NORMAL; +import com.google.common.base.Strings; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArrayInteger; import com.google.gwt.user.client.Timer; @@ -92,7 +93,7 @@ public TerminalPresenter( * Connects to special WebSocket which allows get information from terminal on server side. The * terminal is initialized only when the method is called the first time. */ - public void connect() { + public void connect(TerminalOptionsJso options) { if (countRetry == 0) { return; } @@ -111,7 +112,7 @@ public void connect() { "Machine " + machine.getName() + " doesn't provide terminal server.")); - connectToTerminal(agentURLModifier.modify(terminalServer.getUrl())); + connectToTerminal(agentURLModifier.modify(terminalServer.getUrl()), options); }) .catchError( arg -> { @@ -133,13 +134,17 @@ private void reconnect() { new Timer() { @Override public void run() { - connect(); + connect(TerminalOptionsJso.createDefault()); } }.schedule(TIME_BETWEEN_CONNECTIONS); } } - private void connectToTerminal(@NotNull String wsUrl) { + public void sendCommand(String command) { + socket.send("{\"type\":\"data\",\"data\":\"" + command +"\"}"); + } + + private void connectToTerminal(@NotNull String wsUrl, TerminalOptionsJso options) { countRetry--; socket = WebSocket.create(wsUrl); @@ -170,6 +175,9 @@ private void connectToTerminal(@NotNull String wsUrl) { jso.addField("data", data); socket.send(jso.serialize()); }); + if (!Strings.isNullOrEmpty(options.getCommand())) { + sendCommand(options.getCommand()); + } }); socket.setOnErrorHandler( diff --git a/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties b/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties index cad5d7ddec3..6bceeae5f52 100644 --- a/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties +++ b/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties @@ -449,6 +449,7 @@ terminal.restart.trying=Terminal is currently unavailable. Retrying in 2 seconds terminal.error.start=Cannot launch Terminal. Try re-starting current machine and contact support if Terminal keeps failing. failed.to.connect.the.terminal=Failed to connect the terminal view.processes.terminal.node.title=Terminal-{0} +open.in.terminal.command=cd {0} && clear\\r ################ Macros's descriptions ############# macro.editor.current.project.name.description=Project name of the file currently selected in editor diff --git a/ide/che-ide-gwt-app/src/main/resources/org/eclipse/che/ide/public/loader.html b/ide/che-ide-gwt-app/src/main/resources/org/eclipse/che/ide/public/loader.html new file mode 100644 index 00000000000..566549bdf8f --- /dev/null +++ b/ide/che-ide-gwt-app/src/main/resources/org/eclipse/che/ide/public/loader.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + \ No newline at end of file diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/core/constant/TestProjectExplorerContextMenuConstants.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/core/constant/TestProjectExplorerContextMenuConstants.java index 8823027cea7..c2698b5c5d3 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/core/constant/TestProjectExplorerContextMenuConstants.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/core/constant/TestProjectExplorerContextMenuConstants.java @@ -25,6 +25,7 @@ public enum ContextMenuFirstLevelItems implements ContextMenuItems { SHOW_REFERENCES("gwt-debug-contextMenu/showReference"), GO_INTO("gwt-debug-contextMenu/goInto"), GO_BACK("gwt-debug-contextMenu/goInto"), + OPEN_IN_TERMINAL("gwt-debug-contextMenu/openInTerminal"), CUT("gwt-debug-contextMenu/cut"), COPY("gwt-debug-contextMenu/copy"), PASTE("gwt-debug-contextMenu/paste"), diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java new file mode 100644 index 00000000000..343ba08c20d --- /dev/null +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.selenium.miscellaneous; + +import static org.eclipse.che.commons.lang.NameGenerator.generate; +import static org.eclipse.che.selenium.core.constant.TestProjectExplorerContextMenuConstants.ContextMenuFirstLevelItems.OPEN_IN_TERMINAL; + +import com.google.common.base.Strings; +import com.google.inject.Inject; +import java.net.URL; +import java.nio.file.Paths; +import org.eclipse.che.selenium.core.client.TestProjectServiceClient; +import org.eclipse.che.selenium.core.project.ProjectTemplates; +import org.eclipse.che.selenium.core.workspace.TestWorkspace; +import org.eclipse.che.selenium.pageobject.CheTerminal; +import org.eclipse.che.selenium.pageobject.Ide; +import org.eclipse.che.selenium.pageobject.ProjectExplorer; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @author Musienko Maxim + * @author Aleksandr Shmaraev + */ +public class OpenInTerminalTest { + private static final String PROJECT_NAME = generate("project", 4); + private static final String PATH_TO_EXPAND = "/src/main/java"; + private static final String FILE = "/README.md"; + + @Inject private TestWorkspace workspace; + @Inject private Ide ide; + @Inject private ProjectExplorer projectExplorer; + @Inject private TestProjectServiceClient testProjectServiceClient; + @Inject private CheTerminal terminal; + + @BeforeClass + public void setUp() throws Exception { + URL resource = this.getClass().getResource("/projects/default-spring-project"); + testProjectServiceClient.importProject( + workspace.getId(), + Paths.get(resource.toURI()), + PROJECT_NAME, + ProjectTemplates.MAVEN_SPRING); + + ide.open(workspace); + projectExplorer.waitProjectExplorer(); + projectExplorer.waitVisibleItem(PROJECT_NAME); + projectExplorer.waitAndSelectItem(PROJECT_NAME); + } + + @Test + public void openInTerminalTest() { + ide.waitOpenedWorkspaceIsReadyToUse(); + projectExplorer.waitItem(PROJECT_NAME); + projectExplorer.openContextMenuByPathSelectedItem(PROJECT_NAME); + projectExplorer.waitContextMenu(); + projectExplorer.clickOnItemInContextMenu(OPEN_IN_TERMINAL); + terminal.waitNumberTerminalTab(2); + String terminalWorkDir = terminal.getVisibleTextFromTerminal(); + Assert.assertTrue(terminalWorkDir.trim().endsWith(PROJECT_NAME + "$")); + } + + @Test + public void openFolderInTerminalTest() { + projectExplorer.expandPathInProjectExplorer(PROJECT_NAME + PATH_TO_EXPAND); + projectExplorer.waitAndSelectItem(PROJECT_NAME + PATH_TO_EXPAND); + projectExplorer.openContextMenuByPathSelectedItem(PROJECT_NAME + PATH_TO_EXPAND); + projectExplorer.waitContextMenu(); + projectExplorer.clickOnItemInContextMenu(OPEN_IN_TERMINAL); + terminal.waitNumberTerminalTab(2); + String terminalWorkDir = terminal.getVisibleTextFromTerminal(); + Assert.assertTrue(terminalWorkDir.trim().endsWith(PROJECT_NAME + PATH_TO_EXPAND + "$")); + + projectExplorer.waitAndSelectItem(PROJECT_NAME + FILE); + projectExplorer.openContextMenuByPathSelectedItem(PROJECT_NAME + FILE); + projectExplorer.waitContextMenu(); + projectExplorer.clickOnItemInContextMenu(OPEN_IN_TERMINAL); + terminal.waitNumberTerminalTab(3); + terminalWorkDir = terminal.getVisibleTextFromTerminal(); + Assert.assertTrue(terminalWorkDir.trim().endsWith(PROJECT_NAME + "$")); + } + +} From 35eb88990930c10084ea92710cc04658962ed9eb Mon Sep 17 00:00:00 2001 From: Vitalii Parfonov Date: Sun, 15 Jul 2018 10:36:43 +0300 Subject: [PATCH 02/10] Add action in context menu Signed-off-by: Vitalii Parfonov --- .../ide/processes/OpenInTerminalAction.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java new file mode 100644 index 00000000000..cb450615dd2 --- /dev/null +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.ide.processes; + +import static com.google.common.base.Preconditions.checkState; +import static org.eclipse.che.ide.part.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.google.web.bindery.event.shared.EventBus; +import java.util.Collections; +import org.eclipse.che.ide.CoreLocalizationConstant; +import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; +import org.eclipse.che.ide.api.action.ActionEvent; +import org.eclipse.che.ide.api.resources.Container; +import org.eclipse.che.ide.api.resources.Resource; +import org.eclipse.che.ide.machine.MachineResources; +import org.eclipse.che.ide.processes.panel.ProcessesPanelPresenter; +import org.eclipse.che.ide.resource.Path; +import org.eclipse.che.ide.terminal.TerminalOptionsJso; + +/** + * Action to open new terminal and navigate to selected directory. + * + * @author Vitalii Parfonov + */ +@Singleton +public class OpenInTerminalAction extends AbstractPerspectiveAction { + + private CoreLocalizationConstant locale; + private final ProcessesPanelPresenter processesPanelPresenter; + + @Inject + public OpenInTerminalAction( + CoreLocalizationConstant locale, + MachineResources machineResources, + ProcessesPanelPresenter processesPanelPresenter, + EventBus eventBus) { + super( + Collections.singletonList(PROJECT_PERSPECTIVE_ID), + locale.openInTerminalAction(), + null, + machineResources.addTerminalIcon()); + this.locale = locale; + + this.processesPanelPresenter = processesPanelPresenter; + } + + @Override + public void updateInPerspective(ActionEvent event) { + event.getPresentation().setEnabled(true); + } + + @Override + public void actionPerformed(ActionEvent event) { + Resource resource = appContext.get().getResource(); + + if (!(resource instanceof Container)) { + final Container parent = resource.getParent(); + + checkState(parent != null, "Parent should be a container"); + + resource = parent; + } + + Path path = resource.getLocation().makeRelative(); + + String command = locale.openInTerminalCommand(path.toString()); + processesPanelPresenter.newTerminal( + TerminalOptionsJso.createDefault().withCommand(command).withFocusOnOpen(true)); + } + + +} From f27d81d528cb6184ace7ee3dff1e502afaa8fa08 Mon Sep 17 00:00:00 2001 From: Vitalii Parfonov Date: Mon, 16 Jul 2018 09:00:47 +0300 Subject: [PATCH 03/10] Fix formatting Signed-off-by: Vitalii Parfonov --- .../org/eclipse/che/ide/processes/OpenInTerminalAction.java | 2 -- .../java/org/eclipse/che/ide/terminal/TerminalPresenter.java | 2 +- .../eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java index cb450615dd2..ebf5a6761ee 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java @@ -77,6 +77,4 @@ public void actionPerformed(ActionEvent event) { processesPanelPresenter.newTerminal( TerminalOptionsJso.createDefault().withCommand(command).withFocusOnOpen(true)); } - - } diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java index 62ad6f36739..178b69ea93c 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java @@ -141,7 +141,7 @@ public void run() { } public void sendCommand(String command) { - socket.send("{\"type\":\"data\",\"data\":\"" + command +"\"}"); + socket.send("{\"type\":\"data\",\"data\":\"" + command + "\"}"); } private void connectToTerminal(@NotNull String wsUrl, TerminalOptionsJso options) { diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java index 343ba08c20d..104d7ab191d 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java @@ -13,7 +13,6 @@ import static org.eclipse.che.commons.lang.NameGenerator.generate; import static org.eclipse.che.selenium.core.constant.TestProjectExplorerContextMenuConstants.ContextMenuFirstLevelItems.OPEN_IN_TERMINAL; -import com.google.common.base.Strings; import com.google.inject.Inject; import java.net.URL; import java.nio.file.Paths; @@ -88,5 +87,4 @@ public void openFolderInTerminalTest() { terminalWorkDir = terminal.getVisibleTextFromTerminal(); Assert.assertTrue(terminalWorkDir.trim().endsWith(PROJECT_NAME + "$")); } - } From bd4ca656e7f5c5d7a7968c731ef7ff8d7e41fcd8 Mon Sep 17 00:00:00 2001 From: Vitalii Parfonov Date: Mon, 16 Jul 2018 12:21:16 +0300 Subject: [PATCH 04/10] Remove not needed file Signed-off-by: Vitalii Parfonov --- .../resources/org/eclipse/che/ide/public/loader.html | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 ide/che-ide-gwt-app/src/main/resources/org/eclipse/che/ide/public/loader.html diff --git a/ide/che-ide-gwt-app/src/main/resources/org/eclipse/che/ide/public/loader.html b/ide/che-ide-gwt-app/src/main/resources/org/eclipse/che/ide/public/loader.html deleted file mode 100644 index 566549bdf8f..00000000000 --- a/ide/che-ide-gwt-app/src/main/resources/org/eclipse/che/ide/public/loader.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Title - - - - - \ No newline at end of file From 183747ac5c9602ce0af23b8a70bbcfe63842d3e8 Mon Sep 17 00:00:00 2001 From: Vitalii Parfonov Date: Mon, 16 Jul 2018 14:13:02 +0300 Subject: [PATCH 05/10] Code cleanup Signed-off-by: Vitalii Parfonov --- .../ide/processes/OpenInTerminalAction.java | 13 +---- .../che/ide/terminal/TerminalPresenter.java | 41 ++++++++------- .../ide/CoreLocalizationConstant.properties | 2 +- .../miscellaneous/OpenInTerminalTest.java | 50 +++++++++++++++---- 4 files changed, 66 insertions(+), 40 deletions(-) diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java index ebf5a6761ee..fbdbeed2fea 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java @@ -10,12 +10,10 @@ */ package org.eclipse.che.ide.processes; -import static com.google.common.base.Preconditions.checkState; import static org.eclipse.che.ide.part.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; import com.google.inject.Inject; import com.google.inject.Singleton; -import com.google.web.bindery.event.shared.EventBus; import java.util.Collections; import org.eclipse.che.ide.CoreLocalizationConstant; import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; @@ -42,8 +40,7 @@ public class OpenInTerminalAction extends AbstractPerspectiveAction { public OpenInTerminalAction( CoreLocalizationConstant locale, MachineResources machineResources, - ProcessesPanelPresenter processesPanelPresenter, - EventBus eventBus) { + ProcessesPanelPresenter processesPanelPresenter) { super( Collections.singletonList(PROJECT_PERSPECTIVE_ID), locale.openInTerminalAction(), @@ -62,17 +59,11 @@ public void updateInPerspective(ActionEvent event) { @Override public void actionPerformed(ActionEvent event) { Resource resource = appContext.get().getResource(); - - if (!(resource instanceof Container)) { + if (resource.isFile()) { final Container parent = resource.getParent(); - - checkState(parent != null, "Parent should be a container"); - resource = parent; } - Path path = resource.getLocation().makeRelative(); - String command = locale.openInTerminalCommand(path.toString()); processesPanelPresenter.newTerminal( TerminalOptionsJso.createDefault().withCommand(command).withFocusOnOpen(true)); diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java index 178b69ea93c..bcd5febf27e 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java @@ -34,7 +34,6 @@ import org.eclipse.che.ide.collections.Jso; import org.eclipse.che.ide.core.AgentURLModifier; import org.eclipse.che.ide.websocket.WebSocket; -import org.eclipse.che.ide.websocket.events.ConnectionErrorHandler; import org.eclipse.che.requirejs.ModuleHolder; /** @@ -140,8 +139,16 @@ public void run() { } } + /** + * Give command will be executed + * + * @param command + */ public void sendCommand(String command) { - socket.send("{\"type\":\"data\",\"data\":\"" + command + "\"}"); + Jso jso = Jso.create(); + jso.addField("type", DATA_EVENT_NAME); + jso.addField(DATA_EVENT_NAME, command); + socket.send(jso.serialize()); } private void connectToTerminal(@NotNull String wsUrl, TerminalOptionsJso options) { @@ -171,31 +178,29 @@ private void connectToTerminal(@NotNull String wsUrl, TerminalOptionsJso options DATA_EVENT_NAME, data -> { Jso jso = Jso.create(); - jso.addField("type", "data"); - jso.addField("data", data); + jso.addField("type", DATA_EVENT_NAME); + jso.addField(DATA_EVENT_NAME, data); socket.send(jso.serialize()); }); if (!Strings.isNullOrEmpty(options.getCommand())) { sendCommand(options.getCommand()); + sendCommand("\r"); } }); socket.setOnErrorHandler( - new ConnectionErrorHandler() { - @Override - public void onError() { - connected = false; + () -> { + connected = false; - if (countRetry == 0) { - view.showErrorMessage(locale.terminalErrorStart()); - notificationManager.notify( - locale.connectionFailedWithTerminal(), - locale.terminalErrorConnection(), - FAIL, - FLOAT_MODE); - } else { - reconnect(); - } + if (countRetry == 0) { + view.showErrorMessage(locale.terminalErrorStart()); + notificationManager.notify( + locale.connectionFailedWithTerminal(), + locale.terminalErrorConnection(), + FAIL, + FLOAT_MODE); + } else { + reconnect(); } }); } diff --git a/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties b/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties index 6bceeae5f52..4ca88a5cf1f 100644 --- a/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties +++ b/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties @@ -449,7 +449,7 @@ terminal.restart.trying=Terminal is currently unavailable. Retrying in 2 seconds terminal.error.start=Cannot launch Terminal. Try re-starting current machine and contact support if Terminal keeps failing. failed.to.connect.the.terminal=Failed to connect the terminal view.processes.terminal.node.title=Terminal-{0} -open.in.terminal.command=cd {0} && clear\\r +open.in.terminal.command=cd {0} && clear ################ Macros's descriptions ############# macro.editor.current.project.name.description=Project name of the file currently selected in editor diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java index 104d7ab191d..552d9c81e60 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java @@ -27,19 +27,35 @@ import org.testng.annotations.Test; /** - * @author Musienko Maxim - * @author Aleksandr Shmaraev + * Test "Open in Terminal" action. Will check action calling from context menu on selected project, + * folder and file + * + * @author Vitalii Parfonov */ public class OpenInTerminalTest { private static final String PROJECT_NAME = generate("project", 4); private static final String PATH_TO_EXPAND = "/src/main/java"; private static final String FILE = "/README.md"; - @Inject private TestWorkspace workspace; - @Inject private Ide ide; - @Inject private ProjectExplorer projectExplorer; - @Inject private TestProjectServiceClient testProjectServiceClient; - @Inject private CheTerminal terminal; + @SuppressWarnings("unused") + @Inject + private TestWorkspace workspace; + + @SuppressWarnings("unused") + @Inject + private Ide ide; + + @SuppressWarnings("unused") + @Inject + private ProjectExplorer projectExplorer; + + @SuppressWarnings("unused") + @Inject + private TestProjectServiceClient testProjectServiceClient; + + @SuppressWarnings("unused") + @Inject + private CheTerminal terminal; @BeforeClass public void setUp() throws Exception { @@ -53,13 +69,16 @@ public void setUp() throws Exception { ide.open(workspace); projectExplorer.waitProjectExplorer(); projectExplorer.waitVisibleItem(PROJECT_NAME); - projectExplorer.waitAndSelectItem(PROJECT_NAME); } + /** + * - Select project in project explorer - Open context menu on selected project - Click on "Open + * in Terminal" action - Wait on opening new terminal, number of opened terminal should increase - + * Check working directory in open terminal, should point to the selected project + */ @Test public void openInTerminalTest() { - ide.waitOpenedWorkspaceIsReadyToUse(); - projectExplorer.waitItem(PROJECT_NAME); + projectExplorer.waitAndSelectItem(PROJECT_NAME); projectExplorer.openContextMenuByPathSelectedItem(PROJECT_NAME); projectExplorer.waitContextMenu(); projectExplorer.clickOnItemInContextMenu(OPEN_IN_TERMINAL); @@ -68,8 +87,19 @@ public void openInTerminalTest() { Assert.assertTrue(terminalWorkDir.trim().endsWith(PROJECT_NAME + "$")); } + /** + * First check: - Expend project tree - Select some folder - Open context menu on selected folder + * - Click on "Open in Terminal" action - Wait on opening new terminal, number of opened terminal + * should increase - Check working directory in open terminal, should point to the selected folder + * + *

Second check: - Select some file in project tree - Open context menu on selected folder - + * Click on "Open in Terminal" action - Wait on opening new terminal, number of opened terminal + * should increase - Check working directory in open terminal, should point to the parent of + * selected file + */ @Test public void openFolderInTerminalTest() { + projectExplorer.waitAndSelectItem(PROJECT_NAME); projectExplorer.expandPathInProjectExplorer(PROJECT_NAME + PATH_TO_EXPAND); projectExplorer.waitAndSelectItem(PROJECT_NAME + PATH_TO_EXPAND); projectExplorer.openContextMenuByPathSelectedItem(PROJECT_NAME + PATH_TO_EXPAND); From 53ed94a3bf5ca109620e6c546ba47b3e1d94f65d Mon Sep 17 00:00:00 2001 From: Vitalii Parfonov Date: Mon, 16 Jul 2018 18:28:43 +0300 Subject: [PATCH 06/10] Add javadocs Signed-off-by: Vitalii Parfonov --- .../che/ide/processes/OpenInTerminalAction.java | 5 ++++- .../che/ide/terminal/TerminalOptionsJso.java | 13 +++++++++---- .../eclipse/che/ide/terminal/TerminalPresenter.java | 11 +++++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java index fbdbeed2fea..5c17d60f12b 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java @@ -26,7 +26,10 @@ import org.eclipse.che.ide.terminal.TerminalOptionsJso; /** - * Action to open new terminal and navigate to selected directory. + * Action to open new terminal and navigate to selected directory. E.g. if in Project Explorer will + * be selected 'project1/src/main/java' and action will be called MUST be opened new terminal with + * working dir '{workspace-root-folder}/project1/src/main/java'. (bash command cd + * project1/src/main/java) * * @author Vitalii Parfonov */ diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalOptionsJso.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalOptionsJso.java index 71f80f37353..59a03284fb9 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalOptionsJso.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalOptionsJso.java @@ -26,17 +26,22 @@ public static native TerminalOptionsJso createDefault() /*-{ } }-*/; + /** + * @param focusOnOpen set true it need to set focus on just opened terminal + * @return + */ public final native TerminalOptionsJso withFocusOnOpen(boolean focusOnOpen) /*-{ this.focusOnOpen = focusOnOpen; return this; }-*/; + /** + * @param command initial command what will be executed immediately after connection to the + * terminal will established + * @return + */ public final native TerminalOptionsJso withCommand(String command) /*-{ this.command = command; return this; }-*/; - - public final native String getCommand() /*-{ - return this.command; - }-*/; } diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java index bcd5febf27e..666561437d2 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java @@ -48,7 +48,6 @@ public class TerminalPresenter implements Presenter, TerminalView.ActionDelegate private static final int TIME_BETWEEN_CONNECTIONS = 2_000; private final TerminalView view; - private final TerminalOptionsJso options; private final NotificationManager notificationManager; private final CoreLocalizationConstant locale; private final MachineImpl machine; @@ -75,7 +74,7 @@ public TerminalPresenter( final ModuleHolder moduleHolder, AgentURLModifier agentURLModifier) { this.view = view; - this.options = options != null ? options : TerminalOptionsJso.createDefault(); + TerminalOptionsJso options1 = options != null ? options : TerminalOptionsJso.createDefault(); this.agentURLModifier = agentURLModifier; view.setDelegate(this); this.notificationManager = notificationManager; @@ -91,6 +90,10 @@ public TerminalPresenter( /** * Connects to special WebSocket which allows get information from terminal on server side. The * terminal is initialized only when the method is called the first time. + * + * @param options with options param can be set some initial states for new terminal like: - + * initial size (number of rows and cols); - set focused on open; - initial command (like + * change working dir 'cd directory' and etc) */ public void connect(TerminalOptionsJso options) { if (countRetry == 0) { @@ -182,8 +185,8 @@ private void connectToTerminal(@NotNull String wsUrl, TerminalOptionsJso options jso.addField(DATA_EVENT_NAME, data); socket.send(jso.serialize()); }); - if (!Strings.isNullOrEmpty(options.getCommand())) { - sendCommand(options.getCommand()); + if (!Strings.isNullOrEmpty(options.getStringField("command"))) { + sendCommand(options.getStringField("command")); sendCommand("\r"); } }); From ee06fc0abff448152ce38d82f755ae40283e7260 Mon Sep 17 00:00:00 2001 From: Vitalii Parfonov Date: Tue, 17 Jul 2018 09:54:19 +0300 Subject: [PATCH 07/10] Add test to the suite Signed-off-by: Vitalii Parfonov --- .../che-selenium-test/src/test/resources/suites/CheSuite.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/selenium/che-selenium-test/src/test/resources/suites/CheSuite.xml b/selenium/che-selenium-test/src/test/resources/suites/CheSuite.xml index 0044f82b803..f8f18e36d5d 100644 --- a/selenium/che-selenium-test/src/test/resources/suites/CheSuite.xml +++ b/selenium/che-selenium-test/src/test/resources/suites/CheSuite.xml @@ -174,6 +174,7 @@ + From f9f8f88577f31f4fd705813c4d257704fee646db Mon Sep 17 00:00:00 2001 From: Vitalii Parfonov Date: Tue, 17 Jul 2018 15:58:58 +0300 Subject: [PATCH 08/10] Add hotkeys and test Signed-off-by: Vitalii Parfonov --- .../core/StandardComponentInitializer.java | 6 +- .../ide/processes/OpenInTerminalAction.java | 8 +- .../che/ide/terminal/TerminalPresenter.java | 13 ++- .../miscellaneous/OpenInTerminalTest.java | 79 ++++++++++++++++--- 4 files changed, 84 insertions(+), 22 deletions(-) diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/core/StandardComponentInitializer.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/core/StandardComponentInitializer.java index e722d749b8d..6e016e75558 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/core/StandardComponentInitializer.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/core/StandardComponentInitializer.java @@ -202,6 +202,7 @@ public class StandardComponentInitializer { public static final String SHOW_REFERENCE = "showReference"; public static final String SHOW_COMMANDS_PALETTE = "showCommandsPalette"; public static final String NEW_TERMINAL = "newTerminal"; + public static final String OPEN_IN_TERMINAL = "openInTerminal"; public static final String PROJECT_EXPLORER_DISPLAYING_MODE = "projectExplorerDisplayingMode"; public static final String COMMAND_EXPLORER_DISPLAYING_MODE = "commandExplorerDisplayingMode"; public static final String FIND_RESULT_DISPLAYING_MODE = "findResultDisplayingMode"; @@ -748,7 +749,7 @@ public void initialize() { mainContextMenuGroup.addSeparator(); mainContextMenuGroup.add(resourceOperation); mainContextMenuGroup.add(openInTerminalAction); - actionManager.registerAction("openInTerminal", openInTerminalAction); + actionManager.registerAction(OPEN_IN_TERMINAL, openInTerminalAction); DefaultActionGroup partMenuGroup = (DefaultActionGroup) actionManager.getAction(GROUP_PART_MENU); @@ -908,6 +909,9 @@ public void initialize() { keyBinding .getGlobal() .addKey(new KeyBuilder().alt().charCode(KeyCodeMap.F12).build(), NEW_TERMINAL); + keyBinding + .getGlobal() + .addKey(new KeyBuilder().alt().shift().charCode(KeyCodeMap.F12).build(), OPEN_IN_TERMINAL); keyBinding.getGlobal().addKey(new KeyBuilder().alt().charCode('N').build(), NEW_FILE); keyBinding.getGlobal().addKey(new KeyBuilder().alt().charCode('x').build(), CREATE_PROJECT); diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java index 5c17d60f12b..4fbb182854d 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java @@ -26,10 +26,10 @@ import org.eclipse.che.ide.terminal.TerminalOptionsJso; /** - * Action to open new terminal and navigate to selected directory. E.g. if in Project Explorer will - * be selected 'project1/src/main/java' and action will be called MUST be opened new terminal with - * working dir '{workspace-root-folder}/project1/src/main/java'. (bash command cd - * project1/src/main/java) + * Action to open new terminal and navigate to selected directory. If on selected folder in Project + * Explorer call this action MUST be opened new terminal with selected working dir. + * + *

bash command 'cd {selected-folder}' * * @author Vitalii Parfonov */ diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java index 666561437d2..e688b6b4351 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java @@ -88,12 +88,17 @@ public TerminalPresenter( } /** - * Connects to special WebSocket which allows get information from terminal on server side. The + *

+   * Connects to Terminal Server by WebSocket. Which allows get information from terminal on server side. The
    * terminal is initialized only when the method is called the first time.
    *
-   * @param options with options param can be set some initial states for new terminal like: -
-   *     initial size (number of rows and cols); - set focused on open; - initial command (like
-   *     change working dir 'cd directory' and etc)
+   * @param options with options param can be set some initial states for new terminal like:
+   *               - initial size (number of rows and cols);
+   *               - set focused on open;
+   *               - initial command (like change working dir 'cd directory' and etc)
+   *
+   * More details {@link TerminalOptionsJso}
+   * 
*/ public void connect(TerminalOptionsJso options) { if (countRetry == 0) { diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java index 552d9c81e60..4c3c0ff18f1 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java @@ -12,16 +12,22 @@ import static org.eclipse.che.commons.lang.NameGenerator.generate; import static org.eclipse.che.selenium.core.constant.TestProjectExplorerContextMenuConstants.ContextMenuFirstLevelItems.OPEN_IN_TERMINAL; +import static org.openqa.selenium.Keys.ALT; +import static org.openqa.selenium.Keys.F12; +import static org.openqa.selenium.Keys.SHIFT; import com.google.inject.Inject; import java.net.URL; import java.nio.file.Paths; +import org.eclipse.che.selenium.core.SeleniumWebDriver; import org.eclipse.che.selenium.core.client.TestProjectServiceClient; import org.eclipse.che.selenium.core.project.ProjectTemplates; +import org.eclipse.che.selenium.core.webdriver.SeleniumWebDriverHelper; import org.eclipse.che.selenium.core.workspace.TestWorkspace; import org.eclipse.che.selenium.pageobject.CheTerminal; import org.eclipse.che.selenium.pageobject.Ide; import org.eclipse.che.selenium.pageobject.ProjectExplorer; +import org.openqa.selenium.Keys; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -57,6 +63,14 @@ public class OpenInTerminalTest { @Inject private CheTerminal terminal; + @SuppressWarnings("unused") + @Inject + private SeleniumWebDriverHelper seleniumWebDriverHelper; + + @SuppressWarnings("unused") + @Inject + private SeleniumWebDriver seleniumWebDriver; + @BeforeClass public void setUp() throws Exception { URL resource = this.getClass().getResource("/projects/default-spring-project"); @@ -65,19 +79,24 @@ public void setUp() throws Exception { Paths.get(resource.toURI()), PROJECT_NAME, ProjectTemplates.MAVEN_SPRING); - ide.open(workspace); - projectExplorer.waitProjectExplorer(); - projectExplorer.waitVisibleItem(PROJECT_NAME); } /** - * - Select project in project explorer - Open context menu on selected project - Click on "Open - * in Terminal" action - Wait on opening new terminal, number of opened terminal should increase - - * Check working directory in open terminal, should point to the selected project + * + * + *
+   *  - Select project in project explorer
+   *  - Open context menu on selected project
+   *  - Click on "Open in Terminal" action
+   *  - Wait on opening new terminal, number of opened terminal should increase
+   *  - Check working directory in open terminal, should point to the selected project
+   * 
*/ @Test public void openInTerminalTest() { + seleniumWebDriver.navigate().refresh(); + projectExplorer.waitProjectExplorer(); projectExplorer.waitAndSelectItem(PROJECT_NAME); projectExplorer.openContextMenuByPathSelectedItem(PROJECT_NAME); projectExplorer.waitContextMenu(); @@ -88,17 +107,29 @@ public void openInTerminalTest() { } /** - * First check: - Expend project tree - Select some folder - Open context menu on selected folder - * - Click on "Open in Terminal" action - Wait on opening new terminal, number of opened terminal - * should increase - Check working directory in open terminal, should point to the selected folder * - *

Second check: - Select some file in project tree - Open context menu on selected folder - - * Click on "Open in Terminal" action - Wait on opening new terminal, number of opened terminal - * should increase - Check working directory in open terminal, should point to the parent of - * selected file + * + *

+   * First check:
+   *  - Expend project tree
+   *  - Select some folder
+   *  - Open context menu on selected folder
+   *  - Click on "Open in Terminal" action
+   *  - Wait on opening new terminal, number of opened terminal should increase
+   *  - Check working directory in open terminal, should point to the selected folder
+   *
+   * Second check:
+   *  - Select some file in project tree
+   *  - Open context menu on selected folder
+   *  - Click on "Open in Terminal" action
+   *  - Wait on opening new terminal, number of opened terminal should increase
+   *  - Check working directory in open terminal, should point to the parent of selected file
+   * 
*/ @Test public void openFolderInTerminalTest() { + seleniumWebDriver.navigate().refresh(); + projectExplorer.waitProjectExplorer(); projectExplorer.waitAndSelectItem(PROJECT_NAME); projectExplorer.expandPathInProjectExplorer(PROJECT_NAME + PATH_TO_EXPAND); projectExplorer.waitAndSelectItem(PROJECT_NAME + PATH_TO_EXPAND); @@ -117,4 +148,26 @@ public void openFolderInTerminalTest() { terminalWorkDir = terminal.getVisibleTextFromTerminal(); Assert.assertTrue(terminalWorkDir.trim().endsWith(PROJECT_NAME + "$")); } + + /** + * + * + *
+   *  - Select project in project explorer
+   *  - Open context menu on selected project
+   *  - Click on "Open in Terminal" action
+   *  - Wait on opening new terminal, number of opened terminal should increase
+   *  - Check working directory in open terminal, should point to the selected project
+   * 
+ */ + @Test + public void openInTerminalTestByHotKey() { + seleniumWebDriver.navigate().refresh(); + projectExplorer.waitProjectExplorer(); + projectExplorer.waitAndSelectItem(PROJECT_NAME); + seleniumWebDriverHelper.sendKeys(Keys.chord(ALT, SHIFT, F12)); + terminal.waitNumberTerminalTab(2); + String terminalWorkDir = terminal.getVisibleTextFromTerminal(); + Assert.assertTrue(terminalWorkDir.trim().endsWith(PROJECT_NAME + "$")); + } } From cbfad66f15b7b42a652a2d70f75144bee33362aa Mon Sep 17 00:00:00 2001 From: Vitalii Parfonov Date: Tue, 17 Jul 2018 17:30:31 +0300 Subject: [PATCH 09/10] code clean up Signed-off-by: Vitalii Parfonov --- .../che/ide/CoreLocalizationConstant.java | 3 --- .../ide/processes/OpenInTerminalAction.java | 12 ++++++++- .../che/ide/terminal/TerminalPresenter.java | 26 ++++++++++++------- .../ide/CoreLocalizationConstant.properties | 1 - .../miscellaneous/OpenInTerminalTest.java | 17 +++++------- 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/CoreLocalizationConstant.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/CoreLocalizationConstant.java index a292c15d87e..7abb8c471fa 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/CoreLocalizationConstant.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/CoreLocalizationConstant.java @@ -1233,9 +1233,6 @@ String sshConnectInfo( @DefaultMessage("Open in Terminal") String openInTerminalAction(); - @Key("open.in.terminal.command") - String openInTerminalCommand(String path); - @Key("machine.output.action.title") String machineOutputActionTitle(); diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java index 4fbb182854d..02cce993b4a 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/processes/OpenInTerminalAction.java @@ -12,6 +12,9 @@ import static org.eclipse.che.ide.part.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; +import com.google.gwt.core.client.GWT; +import com.google.gwt.safehtml.client.SafeHtmlTemplates; +import com.google.gwt.safehtml.shared.SafeHtml; import com.google.inject.Inject; import com.google.inject.Singleton; import java.util.Collections; @@ -39,6 +42,12 @@ public class OpenInTerminalAction extends AbstractPerspectiveAction { private CoreLocalizationConstant locale; private final ProcessesPanelPresenter processesPanelPresenter; + interface Command extends SafeHtmlTemplates { + + @Template("cd {0} && clear") + SafeHtml openInTerminalCommand(String path); + } + @Inject public OpenInTerminalAction( CoreLocalizationConstant locale, @@ -67,7 +76,8 @@ public void actionPerformed(ActionEvent event) { resource = parent; } Path path = resource.getLocation().makeRelative(); - String command = locale.openInTerminalCommand(path.toString()); + Command cmdTmpl = GWT.create(Command.class); + String command = cmdTmpl.openInTerminalCommand(path.toString()).asString(); processesPanelPresenter.newTerminal( TerminalOptionsJso.createDefault().withCommand(command).withFocusOnOpen(true)); } diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java index e688b6b4351..4f3d63cc8bb 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java @@ -45,6 +45,7 @@ public class TerminalPresenter implements Presenter, TerminalView.ActionDelegate // event which is performed when user input data into terminal private static final String DATA_EVENT_NAME = "data"; + private static final String TYPE = "type"; private static final int TIME_BETWEEN_CONNECTIONS = 2_000; private final TerminalView view; @@ -69,12 +70,10 @@ public TerminalPresenter( NotificationManager notificationManager, CoreLocalizationConstant locale, @NotNull @Assisted MachineImpl machine, - @Assisted TerminalOptionsJso options, final TerminalInitializePromiseHolder terminalHolder, final ModuleHolder moduleHolder, AgentURLModifier agentURLModifier) { this.view = view; - TerminalOptionsJso options1 = options != null ? options : TerminalOptionsJso.createDefault(); this.agentURLModifier = agentURLModifier; view.setDelegate(this); this.notificationManager = notificationManager; @@ -87,6 +86,14 @@ public TerminalPresenter( this.moduleHolder = moduleHolder; } + /** + * Connects to Terminal Server by WebSocket. Which allows get information from terminal on server + * side. The terminal is initialized only when the method is called the first time. + */ + public void connect() { + connect(TerminalOptionsJso.createDefault()); + } + /** *
    * Connects to Terminal Server by WebSocket. Which allows get information from terminal on server side. The
@@ -154,7 +161,7 @@ public void run() {
    */
   public void sendCommand(String command) {
     Jso jso = Jso.create();
-    jso.addField("type", DATA_EVENT_NAME);
+    jso.addField(TYPE, DATA_EVENT_NAME);
     jso.addField(DATA_EVENT_NAME, command);
     socket.send(jso.serialize());
   }
@@ -186,12 +193,13 @@ private void connectToTerminal(@NotNull String wsUrl, TerminalOptionsJso options
               DATA_EVENT_NAME,
               data -> {
                 Jso jso = Jso.create();
-                jso.addField("type", DATA_EVENT_NAME);
+                jso.addField(TYPE, DATA_EVENT_NAME);
                 jso.addField(DATA_EVENT_NAME, data);
                 socket.send(jso.serialize());
               });
-          if (!Strings.isNullOrEmpty(options.getStringField("command"))) {
-            sendCommand(options.getStringField("command"));
+          String command = options.getStringField("command");
+          if (!Strings.isNullOrEmpty(command)) {
+            sendCommand(command);
             sendCommand("\r");
           }
         });
@@ -217,7 +225,7 @@ private void connectToTerminal(@NotNull String wsUrl, TerminalOptionsJso options
   public void stopTerminal() {
     if (connected) {
       Jso jso = Jso.create();
-      jso.addField("type", "close");
+      jso.addField(TYPE, "close");
       socket.send(jso.serialize());
     }
   }
@@ -255,8 +263,8 @@ public void setTerminalSize(int x, int y) {
     JsArrayInteger arr = Jso.createArray().cast();
     arr.set(0, x);
     arr.set(1, y);
-    jso.addField("type", "resize");
-    jso.addField("data", arr);
+    jso.addField(TYPE, "resize");
+    jso.addField(DATA_EVENT_NAME, arr);
     socket.send(jso.serialize());
   }
 
diff --git a/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties b/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties
index 4ca88a5cf1f..cad5d7ddec3 100644
--- a/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties
+++ b/ide/che-core-ide-app/src/main/resources/org/eclipse/che/ide/CoreLocalizationConstant.properties
@@ -449,7 +449,6 @@ terminal.restart.trying=Terminal is currently unavailable. Retrying in 2 seconds
 terminal.error.start=Cannot launch Terminal. Try re-starting current machine and contact support if Terminal keeps failing.
 failed.to.connect.the.terminal=Failed to connect the terminal
 view.processes.terminal.node.title=Terminal-{0}
-open.in.terminal.command=cd {0} && clear
 
 ################ Macros's descriptions #############
 macro.editor.current.project.name.description=Project name of the file currently selected in editor
diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java
index 4c3c0ff18f1..b5ba1398b5b 100644
--- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java
+++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/OpenInTerminalTest.java
@@ -28,7 +28,6 @@
 import org.eclipse.che.selenium.pageobject.Ide;
 import org.eclipse.che.selenium.pageobject.ProjectExplorer;
 import org.openqa.selenium.Keys;
-import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
@@ -94,7 +93,7 @@ public void setUp() throws Exception {
    * 
*/ @Test - public void openInTerminalTest() { + public void openProjectInTerminalTest() { seleniumWebDriver.navigate().refresh(); projectExplorer.waitProjectExplorer(); projectExplorer.waitAndSelectItem(PROJECT_NAME); @@ -102,8 +101,7 @@ public void openInTerminalTest() { projectExplorer.waitContextMenu(); projectExplorer.clickOnItemInContextMenu(OPEN_IN_TERMINAL); terminal.waitNumberTerminalTab(2); - String terminalWorkDir = terminal.getVisibleTextFromTerminal(); - Assert.assertTrue(terminalWorkDir.trim().endsWith(PROJECT_NAME + "$")); + terminal.waitExpectedTextIntoTerminal(PROJECT_NAME + "$"); } /** @@ -137,16 +135,14 @@ public void openFolderInTerminalTest() { projectExplorer.waitContextMenu(); projectExplorer.clickOnItemInContextMenu(OPEN_IN_TERMINAL); terminal.waitNumberTerminalTab(2); - String terminalWorkDir = terminal.getVisibleTextFromTerminal(); - Assert.assertTrue(terminalWorkDir.trim().endsWith(PROJECT_NAME + PATH_TO_EXPAND + "$")); + terminal.waitExpectedTextIntoTerminal(PROJECT_NAME + PATH_TO_EXPAND + "$"); projectExplorer.waitAndSelectItem(PROJECT_NAME + FILE); projectExplorer.openContextMenuByPathSelectedItem(PROJECT_NAME + FILE); projectExplorer.waitContextMenu(); projectExplorer.clickOnItemInContextMenu(OPEN_IN_TERMINAL); terminal.waitNumberTerminalTab(3); - terminalWorkDir = terminal.getVisibleTextFromTerminal(); - Assert.assertTrue(terminalWorkDir.trim().endsWith(PROJECT_NAME + "$")); + terminal.waitExpectedTextIntoTerminal(PROJECT_NAME + "$"); } /** @@ -155,7 +151,7 @@ public void openFolderInTerminalTest() { *
    *  - Select project in project explorer
    *  - Open context menu on selected project
-   *  - Click on "Open in Terminal" action
+   *  - Call hot key Alt+Shift+F12
    *  - Wait on opening new terminal, number of opened terminal should increase
    *  - Check working directory in open terminal, should point to the selected project
    * 
@@ -167,7 +163,6 @@ public void openInTerminalTestByHotKey() { projectExplorer.waitAndSelectItem(PROJECT_NAME); seleniumWebDriverHelper.sendKeys(Keys.chord(ALT, SHIFT, F12)); terminal.waitNumberTerminalTab(2); - String terminalWorkDir = terminal.getVisibleTextFromTerminal(); - Assert.assertTrue(terminalWorkDir.trim().endsWith(PROJECT_NAME + "$")); + terminal.waitExpectedTextIntoTerminal(PROJECT_NAME + "$"); } } From da3b4ee530ac4ef66e7b8e1d0c5f060d8bfd9f83 Mon Sep 17 00:00:00 2001 From: Vitalii Parfonov Date: Tue, 17 Jul 2018 18:00:38 +0300 Subject: [PATCH 10/10] code clean up Signed-off-by: Vitalii Parfonov --- .../java/org/eclipse/che/ide/terminal/TerminalPresenter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java index 4f3d63cc8bb..6f2bd9de56a 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/terminal/TerminalPresenter.java @@ -148,7 +148,7 @@ private void reconnect() { new Timer() { @Override public void run() { - connect(TerminalOptionsJso.createDefault()); + connect(); } }.schedule(TIME_BETWEEN_CONNECTIONS); }