From f48e9c35f2256597c5805c2232a57806d843fcba Mon Sep 17 00:00:00 2001 From: Greg Watson Date: Thu, 18 Jun 2015 16:16:18 -0400 Subject: [PATCH] Bug 470525 - Handle remote connection parser initialization failure gracefully Change-Id: Ie6440b3c0310e15ebb404d5e0deff48eb9722635 Signed-off-by: Greg Watson --- .../internal/RemoteConnectionManager.java | 22 +++++++++---------- .../connector/remote/nls/Messages.java | 2 ++ .../connector/remote/nls/Messages.properties | 1 + 3 files changed, 14 insertions(+), 11 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 f80db0ebe2b..0811508f426 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 @@ -77,45 +77,45 @@ public class RemoteConnectionManager extends Job { remoteConnection = connType.getConnection(connector.getRemoteSettings().getConnectionName()); } if (remoteConnection == null) { - throw new RemoteConnectionException( + return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), NLS.bind(Messages.RemoteConnectionManager_0, connector.getRemoteSettings().getConnectionName())); } if (!remoteConnection.isOpen()) { remoteConnection.open(monitor); if (!remoteConnection.isOpen()) { - throw new RemoteConnectionException( + return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), NLS.bind(Messages.RemoteConnectionManager_1, connector.getRemoteSettings().getConnectionName())); } } if (parser != null) { - synchronized (this) { - remoteProcess = parser.initialize(remoteConnection); - } - } else { + remoteProcess = parser.initialize(remoteConnection); + } + + if (remoteProcess == null) { /* * Check the terminal shell command preference. If the preference is empty and we support a command shell, * just use that. Otherwise use the preference value if it is set, or fall back to a default if not. */ IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(Activator.getUniqueIdentifier()); String terminalShellCommand = prefs.get(IRemoteTerminalConstants.PREF_TERMINAL_SHELL_COMMAND, ""); //$NON-NLS-1$ - if (!("".equals(terminalShellCommand)) //$NON-NLS-1$ + if ("".equals(terminalShellCommand) //$NON-NLS-1$ && remoteConnection.hasService(IRemoteCommandShellService.class)) { IRemoteCommandShellService cmdShellSvc = remoteConnection.getService(IRemoteCommandShellService.class); synchronized (this) { remoteProcess = cmdShellSvc.getCommandShell(IRemoteProcessBuilder.ALLOCATE_PTY); } - } else { + } else if (remoteConnection.hasService(IRemoteProcessService.class)) { if ("".equals(terminalShellCommand)) { //$NON-NLS-1$ terminalShellCommand = "/bin/bash -l"; //$NON-NLS-1$ } IRemoteProcessService procSvc = remoteConnection.getService(IRemoteProcessService.class); IRemoteProcessBuilder processBuilder = procSvc .getProcessBuilder(new ArgumentParser(terminalShellCommand).getTokenList()); - synchronized (this) { - remoteProcess = processBuilder.start(IRemoteProcessBuilder.ALLOCATE_PTY); - } + remoteProcess = processBuilder.start(IRemoteProcessBuilder.ALLOCATE_PTY); + } else { + return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), Messages.RemoteConnectionManager_2); } } diff --git a/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/nls/Messages.java b/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/nls/Messages.java index b544abe7400..2634243ce1b 100644 --- a/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/nls/Messages.java +++ b/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/nls/Messages.java @@ -16,6 +16,8 @@ public class Messages extends NLS { public static String RemoteConnectionManager_1; + public static String RemoteConnectionManager_2; + public static String RemoteTerminalPreferencePage_0; public static String TERMINAL_EXCEPTION; diff --git a/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/nls/Messages.properties b/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/nls/Messages.properties index 427a2ef1018..94584b504a3 100644 --- a/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/nls/Messages.properties +++ b/plugins/org.eclipse.tm.terminal.connector.remote/src/org/eclipse/tm/terminal/connector/remote/nls/Messages.properties @@ -9,6 +9,7 @@ ############################################################################### RemoteConnectionManager_0=Unable to create connection: {0} RemoteConnectionManager_1=Unable to to open connection: {0} +RemoteConnectionManager_2=Connection type does not support the required services RemoteTerminalPreferencePage_0=Initial Shell Command TERMINAL_EXCEPTION=Remote Terminal Exception