View | Details | Raw Unified | Return to bug 226301
Collapse All | Expand All

(-)src/org/eclipse/rse/internal/remotecdt/RemoteRunLaunchDelegate.java (-47 / +47 lines)
Lines 1-14 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 PalmSource, Inc. and others.
2
 * Copyright (c) 2006, 2008 PalmSource, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0 
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at 
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html 
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
7
 *
8
 * Contributors: 
8
 * Contributors:
9
 * Ewa Matejska (PalmSource) - Adapted from LocalRunLaunchDelegate
9
 * Ewa Matejska (PalmSource) - Adapted from LocalRunLaunchDelegate
10
 * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
10
 * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
11
 * Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry
11
 * Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry
12
 * Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
12
 *******************************************************************************/
13
 *******************************************************************************/
13
14
14
15
Lines 55-73 Link Here
55
import org.eclipse.swt.widgets.Display;
56
import org.eclipse.swt.widgets.Display;
56
57
57
public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate {
58
public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate {
58
	
59
59
	private final static String SHELL_SERVICE = "shell.service";  //$NON-NLS-1$
60
	private final static String SHELL_SERVICE = "shell.service";  //$NON-NLS-1$
60
	private final static String FILE_SERVICE = "file.service";  //$NON-NLS-1$
61
	private final static String FILE_SERVICE = "file.service";  //$NON-NLS-1$
61
	private final static String EXIT_CMD = "exit"; //$NON-NLS-1$
62
	private final static String EXIT_CMD = "exit"; //$NON-NLS-1$
62
	private final static String CMD_DELIMITER = ";"; //$NON-NLS-1$
63
	private final static String CMD_DELIMITER = ";"; //$NON-NLS-1$
63
	
64
64
	/*
65
	/*
65
	 *  (non-Javadoc)
66
	 *  (non-Javadoc)
66
	 * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch
67
	 * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch
67
	 */
68
	 */
68
	public void launch(ILaunchConfiguration config, String mode, ILaunch launch,
69
	public void launch(ILaunchConfiguration config, String mode, ILaunch launch,
69
			IProgressMonitor monitor)  throws CoreException {
70
			IProgressMonitor monitor)  throws CoreException {
70
		
71
71
		IBinaryObject exeFile = null;
72
		IBinaryObject exeFile = null;
72
		IPath exePath = verifyProgramPath(config);
73
		IPath exePath = verifyProgramPath(config);
73
		ICProject project = verifyCProject(config);
74
		ICProject project = verifyCProject(config);
Lines 77-85 Link Here
77
78
78
		String arguments = getProgramArguments(config);
79
		String arguments = getProgramArguments(config);
79
		String remoteExePath = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_REMOTE_PATH, ""); //$NON-NLS-1$
80
		String remoteExePath = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_REMOTE_PATH, ""); //$NON-NLS-1$
80
		
81
81
		if(mode.equals(ILaunchManager.DEBUG_MODE)){
82
		if(mode.equals(ILaunchManager.DEBUG_MODE)){
82
			setDefaultSourceLocator(launch, config);			
83
			setDefaultSourceLocator(launch, config);
83
			String debugMode = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
84
			String debugMode = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
84
					ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
85
					ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
85
			if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
86
			if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
Lines 88-94 Link Here
88
				try {
89
				try {
89
					// Download the binary to the remote before debugging.
90
					// Download the binary to the remote before debugging.
90
					remoteFileDownload(config, launch, exePath.toString(), remoteExePath);
91
					remoteFileDownload(config, launch, exePath.toString(), remoteExePath);
91
				
92
92
					// Automatically start up the gdbserver.  In the future this should be expanded to launch
93
					// Automatically start up the gdbserver.  In the future this should be expanded to launch
93
					// an arbitrary remote damon.
94
					// an arbitrary remote damon.
94
					String gdbserver_port_number = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_GDBSERVER_PORT,
95
					String gdbserver_port_number = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_GDBSERVER_PORT,
Lines 102-129 Link Here
102
					remoteShellProcess = remoteShellExec(config, gdbserver_command,
103
					remoteShellProcess = remoteShellExec(config, gdbserver_command,
103
														 command_arguments);
104
														 command_arguments);
104
					DebugPlugin.newProcess(launch, remoteShellProcess, Messages.RemoteRunLaunchDelegate_RemoteShell);
105
					DebugPlugin.newProcess(launch, remoteShellProcess, Messages.RemoteRunLaunchDelegate_RemoteShell);
105
				
106
106
					// Pre-set configuration constants for the GDBSERVERCDIDebugger to indicate how the gdbserver
107
					// Pre-set configuration constants for the GDBSERVERCDIDebugger to indicate how the gdbserver
107
					// was automatically started on the remote.  GDBServerCDIDebugger uses these to figure out how
108
					// was automatically started on the remote.  GDBServerCDIDebugger uses these to figure out how
108
					// to connect to the remote gdbserver.
109
					// to connect to the remote gdbserver.
109
					ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
110
					ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
110
					wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, true);
111
					wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, true);
111
					wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_HOST, getRemoteHostname(config)); 
112
					wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_HOST, getRemoteHostname(config));
112
					wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, 
113
					wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT,
113
						gdbserver_port_number);
114
						gdbserver_port_number);
114
					wc.doSave();
115
					wc.doSave();
115
116
116
					// Default to using the GDBServerCDIDebugger.
117
					// Default to using the GDBServerCDIDebugger.
117
					GDBServerCDIDebugger2 debugger = new GDBServerCDIDebugger2();
118
					GDBServerCDIDebugger2 debugger = new GDBServerCDIDebugger2();
118
					dsession = ((ICDIDebugger2)debugger).createSession(launch, exePath.toFile(), 
119
					dsession = ((ICDIDebugger2)debugger).createSession(launch, exePath.toFile(),
119
																	   new SubProgressMonitor(monitor, 8));
120
																	   new SubProgressMonitor(monitor, 8));
120
121
121
					boolean stopInMain = config
122
					boolean stopInMain = config
122
					.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);
123
					.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);
123
					String stopSymbol = null;
124
					String stopSymbol = null;
124
					if ( stopInMain )
125
					if ( stopInMain )
125
						stopSymbol = launch.getLaunchConfiguration().getAttribute( 
126
						stopSymbol = launch.getLaunchConfiguration().getAttribute(
126
								ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, 
127
								ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL,
127
								ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT );
128
								ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT );
128
129
129
					ICDITarget[] targets = dsession.getTargets();
130
					ICDITarget[] targets = dsession.getTargets();
Lines 133-140 Link Here
133
						if (process != null) {
134
						if (process != null) {
134
							iprocess = DebugPlugin.newProcess(launch, process,
135
							iprocess = DebugPlugin.newProcess(launch, process,
135
										renderProcessLabel(exePath.toOSString()), getDefaultProcessMap());
136
										renderProcessLabel(exePath.toOSString()), getDefaultProcessMap());
136
						} 
137
						}
137
						CDIDebugModel.newDebugTarget(launch, project.getProject(), targets[i], 
138
						CDIDebugModel.newDebugTarget(launch, project.getProject(), targets[i],
138
										renderProcessLabel("gdbserver debugger"), //$NON-NLS-1$
139
										renderProcessLabel("gdbserver debugger"), //$NON-NLS-1$
139
										iprocess, exeFile, true, false, stopSymbol, true);
140
										iprocess, exeFile, true, false, stopSymbol, true);
140
					}
141
					}
Lines 164-184 Link Here
164
					remoteProcess.destroy();
165
					remoteProcess.destroy();
165
				throw e;
166
				throw e;
166
			}
167
			}
167
			
168
168
		} else {
169
		} else {
169
			IStatus status = new Status(IStatus.ERROR, getPluginID(),
170
			IStatus status = new Status(IStatus.ERROR, getPluginID(),
170
								 IStatus.OK, NLS.bind(Messages.RemoteRunLaunchDelegate_1, mode), null);
171
								 IStatus.OK, NLS.bind(Messages.RemoteRunLaunchDelegate_1, mode), null);
171
			throw new CoreException(status);
172
			throw new CoreException(status);
172
		}		
173
		}
173
	}
174
	}
174
	
175
175
	private String spaceEscapify(String inputString) {
176
	private String spaceEscapify(String inputString) {
176
		if(inputString == null)
177
		if(inputString == null)
177
			return null;
178
			return null;
178
		
179
179
		return inputString.replaceAll(" ", "\\\\ "); //$NON-NLS-1$ //$NON-NLS-2$
180
		return inputString.replaceAll(" ", "\\\\ "); //$NON-NLS-1$ //$NON-NLS-2$
180
	}
181
	}
181
	
182
182
	protected IHost getCurrentConnection(ILaunchConfiguration config) throws CoreException {
183
	protected IHost getCurrentConnection(ILaunchConfiguration config) throws CoreException {
183
		String remoteConnection = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_REMOTE_CONNECTION, ""); //$NON-NLS-1$
184
		String remoteConnection = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_REMOTE_CONNECTION, ""); //$NON-NLS-1$
184
185
Lines 192-207 Link Here
192
		}
193
		}
193
		return connections[i];
194
		return connections[i];
194
	}
195
	}
195
	
196
196
	protected IService getConnectedRemoteService(ILaunchConfiguration config, String kindOfService)
197
	protected IService getConnectedRemoteService(ILaunchConfiguration config, String kindOfService)
197
		throws CoreException {
198
		throws CoreException {
198
		
199
199
		// Check that the service requested is file or shell.
200
		// Check that the service requested is file or shell.
200
		if(!kindOfService.equals(SHELL_SERVICE) && !kindOfService.equals(FILE_SERVICE))
201
		if(!kindOfService.equals(SHELL_SERVICE) && !kindOfService.equals(FILE_SERVICE))
201
			abort(Messages.RemoteRunLaunchDelegate_3, null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
202
			abort(Messages.RemoteRunLaunchDelegate_3, null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
202
		
203
203
		IHost currentConnection = getCurrentConnection(config);
204
		IHost currentConnection = getCurrentConnection(config);
204
		
205
205
		ISubSystem[] subSystems = currentConnection.getSubSystems();
206
		ISubSystem[] subSystems = currentConnection.getSubSystems();
206
		int i = 0;
207
		int i = 0;
207
		for(i = 0; i < subSystems.length; i++) {
208
		for(i = 0; i < subSystems.length; i++) {
Lines 226-246 Link Here
226
				}
227
				}
227
			}
228
			}
228
		});
229
		});
229
		
230
230
		if(!subsystem.isConnected())
231
		if(!subsystem.isConnected())
231
			abort(Messages.RemoteRunLaunchDelegate_5, null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
232
			abort(Messages.RemoteRunLaunchDelegate_5, null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
232
		
233
233
		if(kindOfService.equals(SHELL_SERVICE))
234
		if(kindOfService.equals(SHELL_SERVICE))
234
			return  ((IShellServiceSubSystem) subsystem).getShellService();
235
			return  ((IShellServiceSubSystem) subsystem).getShellService();
235
		else
236
		else
236
			return  ((IFileServiceSubSystem) subsystem).getFileService();
237
			return  ((IFileServiceSubSystem) subsystem).getFileService();
237
	}
238
	}
238
	
239
239
	protected Process remoteFileDownload(ILaunchConfiguration config,  ILaunch launch,
240
	protected Process remoteFileDownload(ILaunchConfiguration config,  ILaunch launch,
240
			String localExePath, String remoteExePath) throws CoreException {
241
			String localExePath, String remoteExePath) throws CoreException {
241
		
242
242
		boolean skipDownload = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_SKIP_DOWNLOAD_TO_TARGET, false);
243
		boolean skipDownload = config.getAttribute(IRemoteConnectionConfigurationConstants.ATTR_SKIP_DOWNLOAD_TO_TARGET, false);
243
		
244
244
		if(skipDownload)
245
		if(skipDownload)
245
			// Nothing to do.  Download is skipped.
246
			// Nothing to do.  Download is skipped.
246
			return null;
247
			return null;
Lines 257-300 Link Here
257
			p.destroy();
258
			p.destroy();
258
		} catch (Exception e) {
259
		} catch (Exception e) {
259
			abort(Messages.RemoteRunLaunchDelegate_6, e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR );
260
			abort(Messages.RemoteRunLaunchDelegate_6, e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR );
260
		}	
261
		}
261
		return null;
262
		return null;
262
	}
263
	}
263
	
264
264
	protected String getRemoteHostname(ILaunchConfiguration config) throws CoreException {
265
	protected String getRemoteHostname(ILaunchConfiguration config) throws CoreException {
265
		IHost currentConnection = getCurrentConnection(config);
266
		IHost currentConnection = getCurrentConnection(config);
266
		return currentConnection.getHostName();
267
		return currentConnection.getHostName();
267
	}
268
	}
268
	
269
269
	protected Process remoteShellExec(ILaunchConfiguration config, String remoteCommandPath,
270
	protected Process remoteShellExec(ILaunchConfiguration config, String remoteCommandPath,
270
			String arguments) throws CoreException {
271
			String arguments) throws CoreException {
271
		// The exit command is called to force the remote shell to close after our command 
272
		// The exit command is called to force the remote shell to close after our command
272
		// is executed. This is to prevent a running process at the end of the debug session.
273
		// is executed. This is to prevent a running process at the end of the debug session.
273
		// See Bug 158786.
274
		// See Bug 158786.
274
		String real_remote_command = arguments == null ? spaceEscapify(remoteCommandPath) :
275
		String real_remote_command = arguments == null ? spaceEscapify(remoteCommandPath) :
275
												    spaceEscapify(remoteCommandPath) + " " + arguments; //$NON-NLS-1$
276
												    spaceEscapify(remoteCommandPath) + " " + arguments; //$NON-NLS-1$
276
		String remote_command = real_remote_command + CMD_DELIMITER + EXIT_CMD;
277
		String remote_command = real_remote_command + CMD_DELIMITER + EXIT_CMD;
277
		
278
278
		IShellService shellService = (IShellService) getConnectedRemoteService(config, SHELL_SERVICE);
279
		IShellService shellService = (IShellService) getConnectedRemoteService(config, SHELL_SERVICE);
279
		
280
280
		// This is necessary because runCommand does not actually run the command right now.
281
		// This is necessary because runCommand does not actually run the command right now.
281
		String env[] = new String[0];
282
		String env[] = new String[0];
282
		IHostShell hostShell = shellService.launchShell("", env,new NullProgressMonitor()); //$NON-NLS-1$
283
		hostShell.writeToShell(remote_command);
284
		
285
		Process p = null;
283
		Process p = null;
286
		try {
284
		try {
285
			IHostShell hostShell = shellService.launchShell("", env, new NullProgressMonitor()); //$NON-NLS-1$
286
			hostShell.writeToShell(remote_command);
287
			p = new HostShellProcessAdapter(hostShell);
287
			p = new HostShellProcessAdapter(hostShell);
288
		} catch (Exception e) {
288
		} catch (Exception e) {
289
			if (p != null) {
289
			if (p != null) {
290
				p.destroy();
290
				p.destroy();
291
			}
291
			}
292
			abort(Messages.RemoteRunLaunchDelegate_7, null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
292
			abort(Messages.RemoteRunLaunchDelegate_7, e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
293
		}
293
		}
294
		return p;
294
		return p;
295
	
295
296
	}
296
	}
297
	
297
298
	protected String getPluginID() {
298
	protected String getPluginID() {
299
		return "org.eclipse.rse.internal.remotecdt"; //$NON-NLS-1$
299
		return "org.eclipse.rse.internal.remotecdt"; //$NON-NLS-1$
300
	}
300
	}
(-)src/org/eclipse/rse/internal/services/ssh/shell/SshShellService.java (-7 / +4 lines)
Lines 15-20 Link Here
15
 * Martin Oberhuber (Wind River) - Adapted from LocalShellService.
15
 * Martin Oberhuber (Wind River) - Adapted from LocalShellService.
16
 * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
16
 * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
17
 * Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable
17
 * Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable
18
 * Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
18
 *******************************************************************************/
19
 *******************************************************************************/
19
20
20
package org.eclipse.rse.internal.services.ssh.shell;
21
package org.eclipse.rse.internal.services.ssh.shell;
Lines 24-29 Link Here
24
import org.eclipse.rse.internal.services.ssh.ISshService;
25
import org.eclipse.rse.internal.services.ssh.ISshService;
25
import org.eclipse.rse.internal.services.ssh.ISshSessionProvider;
26
import org.eclipse.rse.internal.services.ssh.ISshSessionProvider;
26
import org.eclipse.rse.internal.services.ssh.SshServiceResources;
27
import org.eclipse.rse.internal.services.ssh.SshServiceResources;
28
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
27
import org.eclipse.rse.services.shells.AbstractShellService;
29
import org.eclipse.rse.services.shells.AbstractShellService;
28
import org.eclipse.rse.services.shells.IHostShell;
30
import org.eclipse.rse.services.shells.IHostShell;
29
31
Lines 41-63 Link Here
41
43
42
	public IHostShell launchShell(String initialWorkingDirectory,
44
	public IHostShell launchShell(String initialWorkingDirectory,
43
			String encoding, String[] environment,
45
			String encoding, String[] environment,
44
			IProgressMonitor monitor) {
46
			IProgressMonitor monitor) throws SystemMessageException {
45
		SshHostShell hostShell = new SshHostShell(fSessionProvider, initialWorkingDirectory, SshHostShell.SHELL_INVOCATION, encoding, environment);
47
		SshHostShell hostShell = new SshHostShell(fSessionProvider, initialWorkingDirectory, SshHostShell.SHELL_INVOCATION, encoding, environment);
46
		return hostShell;
48
		return hostShell;
47
	}
49
	}
48
50
49
	public IHostShell runCommand(String initialWorkingDirectory,
51
	public IHostShell runCommand(String initialWorkingDirectory,
50
			String command, String encoding, String[] environment,
52
			String command, String encoding, String[] environment,
51
			IProgressMonitor monitor) {
53
			IProgressMonitor monitor) throws SystemMessageException {
52
		SshHostShell hostShell = new SshHostShell(fSessionProvider, initialWorkingDirectory, command, encoding, environment);
54
		SshHostShell hostShell = new SshHostShell(fSessionProvider, initialWorkingDirectory, command, encoding, environment);
53
		return hostShell;
55
		return hostShell;
54
	}
56
	}
55
57
56
	public String[] getHostEnvironment() {
57
		//TODO getHostEnvironment is not yet implemented for ssh (needs running remote command and parsing)
58
		return new String[0];
59
	}
60
61
	public String getName() {
58
	public String getName() {
62
		return SshServiceResources.SshShellService_Name;
59
		return SshServiceResources.SshShellService_Name;
63
	}
60
	}
(-)src/org/eclipse/rse/services/shells/AbstractShellService.java (-6 / +17 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 * Martin Oberhuber (Wind River) - initial API and implementation
9
 * Martin Oberhuber (Wind River) - initial API and implementation
10
 * Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
12
package org.eclipse.rse.services.shells;
13
package org.eclipse.rse.services.shells;
Lines 14-44 Link Here
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IProgressMonitor;
15
16
16
import org.eclipse.rse.services.AbstractService;
17
import org.eclipse.rse.services.AbstractService;
18
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
17
19
18
/**
20
/**
19
 * Abstract base class for RSE Shell Service implementations.
21
 * Abstract base class for RSE Shell Service implementations.
22
 * 
23
 * @since org.eclipse.rse.services 3.0
20
 */
24
 */
21
public abstract class AbstractShellService extends AbstractService implements IShellService {
25
public abstract class AbstractShellService extends AbstractService implements IShellService {
22
26
23
	/* (non-Javadoc)
27
	private static final String[] EMPTY_ARRAY = new String[0];
24
	 * @see org.eclipse.rse.services.shells.IShellService#getHostEnvironment()
28
29
	/**
30
	 * Return an empty host environment. Extenders should override this method
31
	 * if they are able to return environment on the remote side. If they do not
32
	 * implement this feature, they must not override this method.
33
	 *
34
	 * @see IShellService#getHostEnvironment()
25
	 */
35
	 */
26
	public String[] getHostEnvironment() {
36
	public String[] getHostEnvironment() throws SystemMessageException {
27
		// not implemented by default
37
		// not implemented by default
28
		return null;
38
		// TODO SSH https://bugs.eclipse.org/bugs/show_bug.cgi?id=162018
39
		return EMPTY_ARRAY;
29
	}
40
	}
30
41
31
	/* (non-Javadoc)
42
	/* (non-Javadoc)
32
	 * @see org.eclipse.rse.services.shells.IShellService#launchShell(java.lang.String, java.lang.String[], org.eclipse.core.runtime.IProgressMonitor)
43
	 * @see org.eclipse.rse.services.shells.IShellService#launchShell(java.lang.String, java.lang.String[], org.eclipse.core.runtime.IProgressMonitor)
33
	 */
44
	 */
34
	public IHostShell launchShell(String initialWorkingDirectory, String[] environment, IProgressMonitor monitor) {
45
	public IHostShell launchShell(String initialWorkingDirectory, String[] environment, IProgressMonitor monitor) throws SystemMessageException {
35
		return launchShell(initialWorkingDirectory, null, environment, monitor);
46
		return launchShell(initialWorkingDirectory, null, environment, monitor);
36
	}
47
	}
37
48
38
	/* (non-Javadoc)
49
	/* (non-Javadoc)
39
	 * @see org.eclipse.rse.services.shells.IShellService#runCommand(java.lang.String, java.lang.String, java.lang.String[], org.eclipse.core.runtime.IProgressMonitor)
50
	 * @see org.eclipse.rse.services.shells.IShellService#runCommand(java.lang.String, java.lang.String, java.lang.String[], org.eclipse.core.runtime.IProgressMonitor)
40
	 */
51
	 */
41
	public IHostShell runCommand(String initialWorkingDirectory, String command, String[] environment, IProgressMonitor monitor) {
52
	public IHostShell runCommand(String initialWorkingDirectory, String command, String[] environment, IProgressMonitor monitor) throws SystemMessageException {
42
		return runCommand(initialWorkingDirectory, command, null, environment, monitor);
53
		return runCommand(initialWorkingDirectory, command, null, environment, monitor);
43
	}
54
	}
44
55
(-)src/org/eclipse/rse/services/shells/IShellService.java (-23 / +37 lines)
Lines 13-18 Link Here
13
 * Contributors:
13
 * Contributors:
14
 * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
14
 * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
15
 * Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable and add Javadoc
15
 * Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable and add Javadoc
16
 * Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
16
 ********************************************************************************/
17
 ********************************************************************************/
17
18
18
package org.eclipse.rse.services.shells;
19
package org.eclipse.rse.services.shells;
Lines 20-25 Link Here
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IProgressMonitor;
21
22
22
import org.eclipse.rse.services.IService;
23
import org.eclipse.rse.services.IService;
24
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
23
25
24
/**
26
/**
25
 * IShellService is an abstraction for running shells and shell commands.
27
 * IShellService is an abstraction for running shells and shell commands.
Lines 36-51 Link Here
36
	 *
38
	 *
37
	 * This is a convenience method, passing <code>null</code> as encoding
39
	 * This is a convenience method, passing <code>null</code> as encoding
38
	 * into {@link #launchShell(String, String, String[], IProgressMonitor)}.
40
	 * into {@link #launchShell(String, String, String[], IProgressMonitor)}.
41
	 *
42
	 * @throws SystemMessageException in case an error occurred or the user
43
	 *             chose to cancel the operation via the progress monitor.
39
	 */
44
	 */
40
	public IHostShell launchShell(String initialWorkingDirectory, String[] environment, IProgressMonitor monitor);
45
	public IHostShell launchShell(String initialWorkingDirectory, String[] environment, IProgressMonitor monitor) throws SystemMessageException;
41
46
42
	/**
47
	/**
43
	 * Launch a new shell in the specified directory.
48
	 * Launch a new shell in the specified directory.
44
	 *
49
	 *
45
	 * @param initialWorkingDirectory initial working directory or
50
	 * @param initialWorkingDirectory initial working directory or empty String
46
	 *            <code>null</code> if not relevant. The remote shell will
51
	 *            ("") if not relevant. The remote shell will launch in a
47
	 *            launch in a directory of its own choice in that case
52
	 *            directory of its own choice in that case (typically a user's
48
	 *            (typically a user's home directory).
53
	 *            home directory).
49
	 * @param encoding Stream encoding to use, or <code>null</code> to fall
54
	 * @param encoding Stream encoding to use, or <code>null</code> to fall
50
	 *            back to a default encoding. The Shell Service will make
55
	 *            back to a default encoding. The Shell Service will make
51
	 *            efforts to determine a proper default encoding on the remote
56
	 *            efforts to determine a proper default encoding on the remote
Lines 57-67 Link Here
57
	 *            set.
62
	 *            set.
58
	 * @param monitor Progress Monitor for monitoring and cancellation
63
	 * @param monitor Progress Monitor for monitoring and cancellation
59
	 * @return the shell object. Note that the shell may not actually be usable
64
	 * @return the shell object. Note that the shell may not actually be usable
60
	 *         in case an error occurred or the operation was canceled. In this
65
	 *         in case the remote side allows opening a channel but immediately
61
	 *         case, {@link IHostShell#isActive()} returns <code>false</code>
66
	 *         closes it again. In this case, {@link IHostShell#isActive()}
62
	 *         on the created Shell object.
67
	 *         returns <code>false</code> on the created Shell object.
68
	 * @throws SystemMessageException in case an error occurred or the user
69
	 *             chose to cancel the operation via the progress monitor.
63
	 */
70
	 */
64
	public IHostShell launchShell(String initialWorkingDirectory, String encoding, String[] environment, IProgressMonitor monitor);
71
	public IHostShell launchShell(String initialWorkingDirectory, String encoding, String[] environment, IProgressMonitor monitor) throws SystemMessageException;
65
72
66
	/**
73
	/**
67
	 *
74
	 *
Lines 70-77 Link Here
70
	 * This is a convenience method, passing <code>null</code> as encoding
77
	 * This is a convenience method, passing <code>null</code> as encoding
71
	 * into
78
	 * into
72
	 * {@link #runCommand(String, String, String, String[], IProgressMonitor)}.
79
	 * {@link #runCommand(String, String, String, String[], IProgressMonitor)}.
80
	 *
81
	 * @throws SystemMessageException in case an error occurred or the user
82
	 *             chose to cancel the operation via the progress monitor.
73
	 */
83
	 */
74
	public IHostShell runCommand(String initialWorkingDirectory, String command, String[] environment, IProgressMonitor monitor);
84
	public IHostShell runCommand(String initialWorkingDirectory, String command, String[] environment, IProgressMonitor monitor) throws SystemMessageException;
75
85
76
	/**
86
	/**
77
	 * Run a single command in it's own shell.
87
	 * Run a single command in it's own shell.
Lines 85-94 Link Here
85
	 * connection automatically. Clients need to call {@link IHostShell#exit()}
95
	 * connection automatically. Clients need to call {@link IHostShell#exit()}
86
	 * in case the shell remains active after the initial command is completed.
96
	 * in case the shell remains active after the initial command is completed.
87
	 *
97
	 *
88
	 * @param initialWorkingDirectory initial working directory or
98
	 * @param initialWorkingDirectory initial working directory or empty String
89
	 *            <code>null</code> if not relevant. The remote shell will
99
	 *            ("") if not relevant. The remote command will launch in a
90
	 *            launch in a directory of its own choice in that case
100
	 *            directory of its own choice in that case (typically a user's
91
	 *            (typically a user's home directory).
101
	 *            home directory).
92
	 * @param encoding Stream encoding to use, or <code>null</code> to fall
102
	 * @param encoding Stream encoding to use, or <code>null</code> to fall
93
	 *            back to a default encoding. The Shell Service will make
103
	 *            back to a default encoding. The Shell Service will make
94
	 *            efforts to determine a proper default encoding on the remote
104
	 *            efforts to determine a proper default encoding on the remote
Lines 100-122 Link Here
100
	 *            set.
110
	 *            set.
101
	 * @param monitor Progress Monitor for monitoring and cancellation
111
	 * @param monitor Progress Monitor for monitoring and cancellation
102
	 * @return the shell object for getting output and error streams. Note that
112
	 * @return the shell object for getting output and error streams. Note that
103
	 *         the shell may not actually be usable in case an error occurred or
113
	 *         the shell may not actually be usable in case an error occurred on
104
	 *         the operation was canceled. In this case,
114
	 *         the remote side, such as the command not being executable. In
105
	 *         {@link IHostShell#isActive()} returns <code>false</code> on the
115
	 *         this case, {@link IHostShell#isActive()} returns
106
	 *         created Shell object.
116
	 *         <code>false</code> on the created Shell object.
117
	 * @throws SystemMessageException in case an error occurred or the user
118
	 *             chose to cancel the operation via the progress monitor.
107
	 */
119
	 */
108
	public IHostShell runCommand(String initialWorkingDirectory, String command, String encoding, String[] environment, IProgressMonitor monitor);
120
	public IHostShell runCommand(String initialWorkingDirectory, String command, String encoding, String[] environment, IProgressMonitor monitor) throws SystemMessageException;
109
121
110
	/**
122
	/**
111
	 * Return an array of environment variables that describe the environment on
123
	 * Return an array of environment variables that describe the environment on
112
	 * the remote system. Each String returned is of the format "var=text":
124
	 * the remote system. Each String returned is of the format "var=text":
113
	 * Everything up to the first equals sign is the name of the given
125
	 * Everything up to the first equals sign is the name of the given
114
	 * environment variable, everything after the equals sign is its contents.
126
	 * environment variable, everything after the equals sign is its contents.
115
	 * 
127
	 *
116
	 * @return Array of environment variable Strings of the form "var=text" if
128
	 * @return Array of environment variable Strings of the form "var=text" if
117
	 *         supported by a shell service implementation. May return
129
	 *         supported by a shell service implementation. Should return an
118
	 *         <code>null</code> in case environment variable retrieval is not
130
	 *         empty array in case environment variable retrieval is not
119
	 *         supported on a particular shell service implementation.
131
	 *         supported on a particular shell service implementation.
132
	 * @throws SystemMessageException in case an error occurred or the user
133
	 *             chose to cancel the operation via the progress monitor.
120
	 */
134
	 */
121
	public String[] getHostEnvironment();
135
	public String[] getHostEnvironment() throws SystemMessageException;
122
}
136
}
(-)src/org/eclipse/rse/services/AbstractService.java (-2 / +2 lines)
Lines 16-24 Link Here
16
/**
16
/**
17
 * Abstract default implementation of an RSE Service. Clients are expected to
17
 * Abstract default implementation of an RSE Service. Clients are expected to
18
 * extend this class.
18
 * extend this class.
19
 *
19
 * 
20
 * @see IService
20
 * @see IService
21
 * @since org.eclipse.rse.core 3.0
21
 * @since org.eclipse.rse.services 3.0
22
 */
22
 */
23
public abstract class AbstractService extends PlatformObject implements IService {
23
public abstract class AbstractService extends PlatformObject implements IService {
24
24
(-)src/org/eclipse/rse/internal/services/telnet/shell/TelnetShellService.java (-7 / +5 lines)
Lines 15-27 Link Here
15
 * Martin Oberhuber (Wind River) - Adapted from LocalShellService.
15
 * Martin Oberhuber (Wind River) - Adapted from LocalShellService.
16
 * Sheldon D'souza (Celunite) - Adapted from SshShellService.
16
 * Sheldon D'souza (Celunite) - Adapted from SshShellService.
17
 * Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable
17
 * Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable
18
 *******************************************************************************/
18
 * Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
19
s *******************************************************************************/
19
package org.eclipse.rse.internal.services.telnet.shell;
20
package org.eclipse.rse.internal.services.telnet.shell;
20
21
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.rse.internal.services.telnet.ITelnetService;
23
import org.eclipse.rse.internal.services.telnet.ITelnetService;
23
import org.eclipse.rse.internal.services.telnet.ITelnetSessionProvider;
24
import org.eclipse.rse.internal.services.telnet.ITelnetSessionProvider;
24
import org.eclipse.rse.internal.services.telnet.TelnetServiceResources;
25
import org.eclipse.rse.internal.services.telnet.TelnetServiceResources;
26
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
25
import org.eclipse.rse.services.shells.AbstractShellService;
27
import org.eclipse.rse.services.shells.AbstractShellService;
26
import org.eclipse.rse.services.shells.IHostShell;
28
import org.eclipse.rse.services.shells.IHostShell;
27
29
Lines 33-52 Link Here
33
		this.fTelnetSessionProvider = sessionProvider;
35
		this.fTelnetSessionProvider = sessionProvider;
34
	}
36
	}
35
37
36
	public String[] getHostEnvironment() {
37
		return new String[0];
38
	}
39
40
	public IHostShell launchShell(String initialWorkingDirectory,
38
	public IHostShell launchShell(String initialWorkingDirectory,
41
			String encoding, String[] environment,
39
			String encoding, String[] environment,
42
			IProgressMonitor monitor) {
40
			IProgressMonitor monitor) throws SystemMessageException {
43
		TelnetHostShell hostShell = new TelnetHostShell(fTelnetSessionProvider, initialWorkingDirectory, TelnetHostShell.SHELL_INVOCATION, encoding, environment);
41
		TelnetHostShell hostShell = new TelnetHostShell(fTelnetSessionProvider, initialWorkingDirectory, TelnetHostShell.SHELL_INVOCATION, encoding, environment);
44
		return hostShell;
42
		return hostShell;
45
	}
43
	}
46
44
47
	public IHostShell runCommand(String initialWorkingDirectory,
45
	public IHostShell runCommand(String initialWorkingDirectory,
48
			String command, String encoding, String[] environment,
46
			String command, String encoding, String[] environment,
49
			IProgressMonitor monitor) {
47
			IProgressMonitor monitor) throws SystemMessageException {
50
		TelnetHostShell hostShell = new TelnetHostShell(fTelnetSessionProvider, initialWorkingDirectory, TelnetHostShell.SHELL_INVOCATION, encoding, environment);
48
		TelnetHostShell hostShell = new TelnetHostShell(fTelnetSessionProvider, initialWorkingDirectory, TelnetHostShell.SHELL_INVOCATION, encoding, environment);
51
		return hostShell;
49
		return hostShell;
52
	}
50
	}
(-)src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/ShellServiceSubSystem.java (-29 / +36 lines)
Lines 1-23 Link Here
1
/********************************************************************************
1
/********************************************************************************
2
 * Copyright (c) 2006, 2008 IBM Corporation and others. All rights reserved.
2
 * Copyright (c) 2006, 2008 IBM Corporation and others. All rights reserved.
3
 * This program and the accompanying materials are made available under the terms
3
 * This program and the accompanying materials are made available under the terms
4
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is 
4
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
6
 *
7
 * Initial Contributors:
7
 * Initial Contributors:
8
 * The following IBM employees contributed to the Remote System Explorer
8
 * The following IBM employees contributed to the Remote System Explorer
9
 * component that contains this file: David McKnight, Kushal Munir, 
9
 * component that contains this file: David McKnight, Kushal Munir,
10
 * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, 
10
 * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
11
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
11
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
12
 * 
12
 *
13
 * Contributors:
13
 * Contributors:
14
 * Martin Oberhuber (Wind River) - [175262] IHost.getSystemType() should return IRSESystemType 
14
 * Martin Oberhuber (Wind River) - [175262] IHost.getSystemType() should return IRSESystemType
15
 * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
15
 * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
16
 * Martin Oberhuber (Wind River) - [186640] Add IRSESystemType.testProperty() 
16
 * Martin Oberhuber (Wind River) - [186640] Add IRSESystemType.testProperty()
17
 * David McKnight   (IBM)        - [191599] Need to pass in shell encoding
17
 * David McKnight   (IBM)        - [191599] Need to pass in shell encoding
18
 * David Dykstal (IBM) - [197036] refactored switch configuration
18
 * David Dykstal (IBM) - [197036] refactored switch configuration
19
 * David Dykstal (IBM) - [217556] remove service subsystem types
19
 * David Dykstal (IBM) - [217556] remove service subsystem types
20
 * David McKnight (IBM) - [220524] internalSwitchServiceSubSystemConfiguration -> internalSwitchSubSystemConfiguration
20
 * David McKnight (IBM) - [220524] internalSwitchServiceSubSystemConfiguration -> internalSwitchSubSystemConfiguration
21
 * Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
21
 ********************************************************************************/
22
 ********************************************************************************/
22
23
23
package org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem;
24
package org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem;
Lines 38-45 Link Here
38
import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem;
39
import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem;
39
import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell;
40
import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell;
40
import org.eclipse.rse.subsystems.shells.core.subsystems.RemoteCmdSubSystem;
41
import org.eclipse.rse.subsystems.shells.core.subsystems.RemoteCmdSubSystem;
42
import org.eclipse.rse.ui.SystemBasePlugin;
41
43
42
public final class ShellServiceSubSystem extends RemoteCmdSubSystem implements IShellServiceSubSystem 
44
public final class ShellServiceSubSystem extends RemoteCmdSubSystem implements IShellServiceSubSystem
43
{
45
{
44
	protected String _userHome = null;
46
	protected String _userHome = null;
45
	protected IShellService _hostService;
47
	protected IShellService _hostService;
Lines 49-65 Link Here
49
		super(host, connectorService);
51
		super(host, connectorService);
50
		_hostService = hostService;
52
		_hostService = hostService;
51
	}
53
	}
52
	
54
53
	public IShellService getShellService()
55
	public IShellService getShellService()
54
	{
56
	{
55
		return _hostService;
57
		return _hostService;
56
	}
58
	}
57
	
59
58
	public void setShellService(IShellService service)
60
	public void setShellService(IShellService service)
59
	{
61
	{
60
		_hostService = service;
62
		_hostService = service;
61
	}
63
	}
62
	
64
63
	protected String getUserHome()
65
	protected String getUserHome()
64
	{
66
	{
65
		if (_userHome == null)
67
		if (_userHome == null)
Lines 82-88 Link Here
82
		return _userHome;
84
		return _userHome;
83
	}
85
	}
84
86
85
	
87
86
	protected Object[] internalRunCommand(String cmd, Object context, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException, SystemMessageException
88
	protected Object[] internalRunCommand(String cmd, Object context, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException, SystemMessageException
87
	{
89
	{
88
		return internalRunCommand(cmd, context, false, monitor);
90
		return internalRunCommand(cmd, context, false, monitor);
Lines 107-118 Link Here
107
		}
109
		}
108
110
109
111
110
		IShellService service = getShellService();	
112
		IShellService service = getShellService();
111
		IHostShell hostShell = service.runCommand(cwd, cmd, getUserAndHostEnvVarsAsStringArray(), monitor);
113
		IHostShell hostShell = service.runCommand(cwd, cmd, getUserAndHostEnvVarsAsStringArray(), monitor);
112
		IServiceCommandShell cmdShell = createRemoteCommandShell(this, hostShell);
114
		IServiceCommandShell cmdShell = createRemoteCommandShell(this, hostShell);
113
		hostShell.addOutputListener(cmdShell);
115
		hostShell.addOutputListener(cmdShell);
114
	
116
115
	
117
116
		if (_cmdShells.size() == 0)
118
		if (_cmdShells.size() == 0)
117
		{
119
		{
118
			// if this is first shell, start listening so that on disconnect, we persist
120
			// if this is first shell, start listening so that on disconnect, we persist
Lines 144-158 Link Here
144
		}
146
		}
145
147
146
148
147
		IShellService service = getShellService();	
149
		IShellService service = getShellService();
148
		String encoding = getHost().getDefaultEncoding(true);
150
		String encoding = getHost().getDefaultEncoding(true);
149
		IHostShell hostShell = service.launchShell(cwd, encoding, getUserAndHostEnvVarsAsStringArray(), monitor);
151
		IHostShell hostShell = service.launchShell(cwd, encoding, getUserAndHostEnvVarsAsStringArray(), monitor);
150
		IServiceCommandShell cmdShell = createRemoteCommandShell(this, hostShell);
152
		IServiceCommandShell cmdShell = createRemoteCommandShell(this, hostShell);
151
		if (cmdShell != null)
153
		if (cmdShell != null)
152
		{
154
		{
153
			hostShell.addOutputListener(cmdShell);
155
			hostShell.addOutputListener(cmdShell);
154
		
156
155
		
157
156
			if (_cmdShells.size() == 0)
158
			if (_cmdShells.size() == 0)
157
			{
159
			{
158
				// if this is first shell, start listening so that on disconnect, we persist
160
				// if this is first shell, start listening so that on disconnect, we persist
Lines 164-170 Link Here
164
166
165
		return cmdShell;
167
		return cmdShell;
166
	}
168
	}
167
	
169
168
170
169
	protected void internalCancelShell(Object command, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
171
	protected void internalCancelShell(Object command, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
170
	{
172
	{
Lines 182-201 Link Here
182
			IServiceCommandShell cmdWrapper = (IServiceCommandShell)command;
184
			IServiceCommandShell cmdWrapper = (IServiceCommandShell)command;
183
			cmdWrapper.writeToShell(cmd);
185
			cmdWrapper.writeToShell(cmd);
184
			cmdWrapper.updateHistory(cmd);
186
			cmdWrapper.updateHistory(cmd);
185
		}			
187
		}
186
	}
188
	}
187
	
189
188
	protected IServiceCommandShell createRemoteCommandShell(IRemoteCmdSubSystem cmdSS, IHostShell hostShell)
190
	protected IServiceCommandShell createRemoteCommandShell(IRemoteCmdSubSystem cmdSS, IHostShell hostShell)
189
	{
191
	{
190
		IShellServiceSubSystemConfiguration config = (IShellServiceSubSystemConfiguration)getParentRemoteCmdSubSystemConfiguration();
192
		IShellServiceSubSystemConfiguration config = (IShellServiceSubSystemConfiguration)getParentRemoteCmdSubSystemConfiguration();
191
		return config.createRemoteCommandShell(cmdSS, hostShell);
193
		return config.createRemoteCommandShell(cmdSS, hostShell);
192
	}
194
	}
193
	
195
194
	public String[] getHostEnvironment()
196
	public String[] getHostEnvironment()
195
	{
197
	{
196
		return getShellService().getHostEnvironment();
198
		try {
199
			return getShellService().getHostEnvironment();
200
		} catch (SystemMessageException e) {
201
			SystemBasePlugin.logError(e.getSystemMessage().getLevelOneText(), e);
202
		}
203
		return new String[0];
197
	}
204
	}
198
	
205
199
	public List getHostEnvironmentVariables()
206
	public List getHostEnvironmentVariables()
200
	{
207
	{
201
		List l = new ArrayList();
208
		List l = new ArrayList();
Lines 213-219 Link Here
213
	public boolean canSwitchTo(ISubSystemConfiguration configuration) {
220
	public boolean canSwitchTo(ISubSystemConfiguration configuration) {
214
		return configuration instanceof IShellServiceSubSystemConfiguration;
221
		return configuration instanceof IShellServiceSubSystemConfiguration;
215
	}
222
	}
216
	
223
217
	/* (non-Javadoc)
224
	/* (non-Javadoc)
218
	 * @see org.eclipse.rse.core.subsystems.SubSystem#internalServiceSubSystemConfiguration(org.eclipse.rse.core.subsystems.ISubSystemConfiguration)
225
	 * @see org.eclipse.rse.core.subsystems.SubSystem#internalServiceSubSystemConfiguration(org.eclipse.rse.core.subsystems.ISubSystemConfiguration)
219
	 */
226
	 */
Lines 222-228 Link Here
222
		IHost host = getHost();
229
		IHost host = getHost();
223
		setShellService(configuration.getShellService(host));
230
		setShellService(configuration.getShellService(host));
224
	}
231
	}
225
	
232
226
	/* (non-Javadoc)
233
	/* (non-Javadoc)
227
	 * @see org.eclipse.rse.core.subsystems.SubSystem#getServiceType()
234
	 * @see org.eclipse.rse.core.subsystems.SubSystem#getServiceType()
228
	 */
235
	 */
Lines 232-238 Link Here
232
	}
239
	}
233
240
234
	public void initializeSubSystem(IProgressMonitor monitor)
241
	public void initializeSubSystem(IProgressMonitor monitor)
235
	{ 
242
	{
236
		getShellService().initService(monitor);
243
		getShellService().initService(monitor);
237
	}
244
	}
238
245
Lines 241-245 Link Here
241
		cancelAllShells();
248
		cancelAllShells();
242
		getShellService().uninitService(monitor);
249
		getShellService().uninitService(monitor);
243
	}
250
	}
244
	
251
245
} 
252
}
(-)src/org/eclipse/rse/internal/services/local/shells/LocalShellService.java (-3 / +5 lines)
Lines 13-18 Link Here
13
 * Contributors:
13
 * Contributors:
14
 * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
14
 * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
15
 * Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable
15
 * Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable
16
 * Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
16
 ********************************************************************************/
17
 ********************************************************************************/
17
18
18
package org.eclipse.rse.internal.services.local.shells;
19
package org.eclipse.rse.internal.services.local.shells;
Lines 26-31 Link Here
26
import org.eclipse.core.runtime.IProgressMonitor;
27
import org.eclipse.core.runtime.IProgressMonitor;
27
import org.eclipse.rse.internal.services.local.ILocalService;
28
import org.eclipse.rse.internal.services.local.ILocalService;
28
import org.eclipse.rse.internal.services.local.LocalServiceResources;
29
import org.eclipse.rse.internal.services.local.LocalServiceResources;
30
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
29
import org.eclipse.rse.services.shells.AbstractShellService;
31
import org.eclipse.rse.services.shells.AbstractShellService;
30
import org.eclipse.rse.services.shells.IHostShell;
32
import org.eclipse.rse.services.shells.IHostShell;
31
33
Lines 48-68 Link Here
48
		return LocalServiceResources.Local_Shell_Service_Description;
50
		return LocalServiceResources.Local_Shell_Service_Description;
49
	}
51
	}
50
52
51
	public IHostShell launchShell(String initialWorkingDirectory, String encoding, String[] environment, IProgressMonitor monitor)
53
	public IHostShell launchShell(String initialWorkingDirectory, String encoding, String[] environment, IProgressMonitor monitor) throws SystemMessageException
52
	{
54
	{
53
		LocalHostShell hostShell = new LocalHostShell(initialWorkingDirectory,SHELL_INVOCATION, encoding, environment);
55
		LocalHostShell hostShell = new LocalHostShell(initialWorkingDirectory,SHELL_INVOCATION, encoding, environment);
54
		hostShell.run(monitor);
56
		hostShell.run(monitor);
55
		return hostShell;
57
		return hostShell;
56
	}
58
	}
57
59
58
	public IHostShell runCommand(String initialWorkingDirectory, String command, String encoding, String[] environment, IProgressMonitor monitor)
60
	public IHostShell runCommand(String initialWorkingDirectory, String command, String encoding, String[] environment, IProgressMonitor monitor) throws SystemMessageException
59
	{
61
	{
60
		LocalHostShell hostShell = new LocalHostShell(initialWorkingDirectory,command, encoding, environment);
62
		LocalHostShell hostShell = new LocalHostShell(initialWorkingDirectory,command, encoding, environment);
61
		hostShell.run(monitor);
63
		hostShell.run(monitor);
62
		return hostShell;
64
		return hostShell;
63
	}
65
	}
64
66
65
	public String[] getHostEnvironment()
67
	public String[] getHostEnvironment() throws SystemMessageException
66
	{
68
	{
67
		if (_envVars == null)
69
		if (_envVars == null)
68
		{
70
		{
(-)src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxShellProcessService.java (-4 / +4 lines)
Lines 11-16 Link Here
11
 * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
11
 * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
12
 * David McKnight   (IBM)        - [175308] Need to use a job to wait for shell to exit
12
 * David McKnight   (IBM)        - [175308] Need to use a job to wait for shell to exit
13
 * Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable and add Javadoc
13
 * Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable and add Javadoc
14
 * Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
14
 *******************************************************************************/
15
 *******************************************************************************/
15
16
16
package org.eclipse.rse.internal.subsystems.processes.shell.linux;
17
package org.eclipse.rse.internal.subsystems.processes.shell.linux;
Lines 212-226 Link Here
212
     */
213
     */
213
    protected String[] internalGetSignalTypes() {
214
    protected String[] internalGetSignalTypes() {
214
        IShellService shellService = Activator.getShellService(host);
215
        IShellService shellService = Activator.getShellService(host);
215
        IHostShell hostShell = shellService.launchShell(
216
                "", null, new NullProgressMonitor()); //$NON-NLS-1$
217
        hostShell.writeToShell(getSignalTypesCommand());
218
        Process p = null;
216
        Process p = null;
219
        try {
217
        try {
218
            IHostShell hostShell = shellService.launchShell("", null, new NullProgressMonitor()); //$NON-NLS-1$
219
			hostShell.writeToShell(getSignalTypesCommand());
220
            p = new HostShellProcessAdapter(hostShell);
220
            p = new HostShellProcessAdapter(hostShell);
221
            // p.waitFor();
221
            // p.waitFor();
222
        } catch (Exception e) {
222
        } catch (Exception e) {
223
            e.printStackTrace();
223
            Activator.log(e);
224
            if (p != null) {
224
            if (p != null) {
225
                p.destroy();
225
                p.destroy();
226
            }
226
            }
(-)src/org/eclipse/rse/internal/subsystems/processes/shell/linux/LinuxProcessHelper.java (-12 / +12 lines)
Lines 1-20 Link Here
1
/********************************************************************************
1
/********************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others. All rights reserved.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others. All rights reserved.
3
 * This program and the accompanying materials are made available under the terms
3
 * This program and the accompanying materials are made available under the terms
4
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is 
4
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
6
 *
7
 * Initial Contributors:
7
 * Initial Contributors:
8
 * The following IBM employees contributed to the Remote System Explorer
8
 * The following IBM employees contributed to the Remote System Explorer
9
 * component that contains this file: David McKnight, Kushal Munir, 
9
 * component that contains this file: David McKnight, Kushal Munir,
10
 * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, 
10
 * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
11
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
11
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
12
 * 
12
 *
13
 * Contributors: 
13
 * Contributors:
14
 * Yu-Fen Kuo (MontaVista) - adapted from RSE UniversalLinuxProcessHandler
14
 * Yu-Fen Kuo (MontaVista) - adapted from RSE UniversalLinuxProcessHandler
15
 * Martin Oberhuber (Wind River) - [refactor] "shell" instead of "ssh" everywhere
15
 * Martin Oberhuber (Wind River) - [refactor] "shell" instead of "ssh" everywhere
16
 * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
16
 * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
17
 * David McKnight   (IBM)        - [175308] Need to use a job to wait for shell to exit
17
 * David McKnight   (IBM)        - [175308] Need to use a job to wait for shell to exit
18
 * Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
18
 *******************************************************************************/
19
 *******************************************************************************/
19
20
20
package org.eclipse.rse.internal.subsystems.processes.shell.linux;
21
package org.eclipse.rse.internal.subsystems.processes.shell.linux;
Lines 34-40 Link Here
34
35
35
/**
36
/**
36
 * Helper class that helps to get state code and user name info most of the code
37
 * Helper class that helps to get state code and user name info most of the code
37
 * 
38
 *
38
 */
39
 */
39
public class LinuxProcessHelper {
40
public class LinuxProcessHelper {
40
    private HashMap stateMap;
41
    private HashMap stateMap;
Lines 92-102 Link Here
92
        _uidsByUserName = new HashMap();
93
        _uidsByUserName = new HashMap();
93
94
94
        IShellService shellService = Activator.getShellService(host);
95
        IShellService shellService = Activator.getShellService(host);
95
        IHostShell hostShell = shellService.launchShell(
96
                "", null, new NullProgressMonitor()); //$NON-NLS-1$
97
        hostShell.writeToShell(getUserNameCommand());
98
        Process p = null;
96
        Process p = null;
99
        try {
97
        try {
98
            IHostShell hostShell = shellService.launchShell("", null, new NullProgressMonitor()); //$NON-NLS-1$
99
			hostShell.writeToShell(getUserNameCommand());
100
            p = new HostShellProcessAdapter(hostShell);
100
            p = new HostShellProcessAdapter(hostShell);
101
            // when p.waitFor() is called here, the hostShell.isActive() always
101
            // when p.waitFor() is called here, the hostShell.isActive() always
102
            // return true.
102
            // return true.
Lines 131-137 Link Here
131
        } catch (IOException e) {
131
        } catch (IOException e) {
132
            Activator.log(e);
132
            Activator.log(e);
133
        }
133
        }
134
        
134
135
        // Wait for remote process to exit.
135
        // Wait for remote process to exit.
136
        WaiterJob waiter = new WaiterJob(p);
136
        WaiterJob waiter = new WaiterJob(p);
137
        waiter.schedule();
137
        waiter.schedule();

Return to bug 226301