From c0335a085eb4aef3708812170b624cc658b1588a Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Tue, 22 Nov 2016 16:22:57 -0500 Subject: [PATCH] Bug 507989 - Allow choosing of o.e.remote connection type Collect the list of connection types that support the command shell service and pass that to the RemoteConnectionWidget so that you can select which one you want. Also adds a fix to the connection manager that was closing the terminal of read returned 0 bytes. That's generally not an end of file condition, especially with Serial Ports. There ugliness to them where you can't close the port while it's blocked on the read, which means it needs to return once in a while. Fix setting of title and force new to match the other delegates. Change-Id: I6b78d789ca28284379d8f1136062ec180e1a8f5c Signed-off-by: Doug Schaefer --- .../internal/RemoteConnectionManager.java | 6 ++--- .../remote/internal/RemoteSettingsPage.java | 18 +++++++++++-- .../launcher/RemoteLauncherDelegate.java | 26 +++++++++---------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteConnectionManager.java b/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteConnectionManager.java index 0811508f426..c7dd6161ef9 100644 --- a/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteConnectionManager.java +++ b/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteConnectionManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 IBM Corporation and others. + * Copyright (c) 2015,2016 IBM Corporation and others. * 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 @@ -169,8 +169,8 @@ public class RemoteConnectionManager extends Job { private void readData(InputStream in) throws IOException { byte[] buf = new byte[32 * 1024]; int n; - while ((n = in.read(buf, 0, buf.length)) > 0) { - if (parser == null || parser.parse(buf)) { + while ((n = in.read(buf, 0, buf.length)) >= 0) { + if (n != 0 && (parser == null || parser.parse(buf))) { control.getRemoteToTerminalOutputStream().write(buf, 0, n); } } diff --git a/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteSettingsPage.java b/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteSettingsPage.java index 2ea7ecdb0f2..d8d944bdd34 100644 --- a/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteSettingsPage.java +++ b/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/internal/RemoteSettingsPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 IBM Corporation and others. + * Copyright (c) 2015,2016 IBM Corporation and others. * 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 @@ -7,6 +7,11 @@ *******************************************************************************/ package org.eclipse.tm.terminal.connector.remote.internal; +import java.util.List; + +import org.eclipse.remote.core.IRemoteCommandShellService; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteServicesManager; import org.eclipse.remote.ui.widgets.RemoteConnectionWidget; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; @@ -15,6 +20,9 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.tm.internal.terminal.provisional.api.AbstractSettingsPage; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; @SuppressWarnings("restriction") public class RemoteSettingsPage extends AbstractSettingsPage { @@ -69,7 +77,13 @@ public class RemoteSettingsPage extends AbstractSettingsPage { composite.setLayout(gridLayout); composite.setLayoutData(gridData); - fRemoteConnectionWidget = new RemoteConnectionWidget(composite, SWT.NONE, null, 0); + BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); + ServiceReference ref = context.getServiceReference(IRemoteServicesManager.class); + IRemoteServicesManager manager = context.getService(ref); + @SuppressWarnings("unchecked") + List types = manager.getConnectionTypesSupporting(IRemoteCommandShellService.class); + + fRemoteConnectionWidget = new RemoteConnectionWidget(composite, SWT.NONE, null, 0, types); fRemoteConnectionWidget.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { diff --git a/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteLauncherDelegate.java b/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteLauncherDelegate.java index 587d425a786..d5f8d7abe4b 100644 --- a/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteLauncherDelegate.java +++ b/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/launcher/RemoteLauncherDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015,2016 Wind River Systems, Inc. and others. 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 @@ -66,6 +66,18 @@ public class RemoteLauncherDelegate extends AbstractLauncherDelegate { public void execute(Map properties, ITerminalService.Done done) { Assert.isNotNull(properties); + // Set the terminal tab title + String terminalTitle = getTerminalTitle(properties); + if (terminalTitle != null) { + properties.put(ITerminalsConnectorConstants.PROP_TITLE, terminalTitle); + } + + // Force a new terminal tab each time it is launched, if not set otherwise from outside + // TODO need a command shell service routing to get this + if (!properties.containsKey(ITerminalsConnectorConstants.PROP_FORCE_NEW)) { + properties.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, Boolean.TRUE); + } + // Get the terminal service ITerminalService terminal = TerminalServiceFactory.getService(); // If not available, we cannot fulfill this request @@ -145,18 +157,6 @@ public class RemoteLauncherDelegate extends AbstractLauncherDelegate { connector.load(store); } - // Set the terminal tab title - String terminalTitle = getTerminalTitle(properties); - if (terminalTitle != null) { - properties.put(ITerminalsConnectorConstants.PROP_TITLE, terminalTitle); - } - - // For Telnet terminals, force a new terminal tab each time it is launched, - // if not set otherwise from outside - if (!properties.containsKey(ITerminalsConnectorConstants.PROP_FORCE_NEW)) { - properties.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, Boolean.TRUE); - } - if (!properties.containsKey(ITerminalsConnectorConstants.PROP_ENCODING)) { IRemoteServicesManager svcMgr = Activator.getService(IRemoteServicesManager.class);