1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-13 20:15:22 +02:00

[226301][api][breaking] IShellService methods should throw SystemMessageException

This commit is contained in:
Martin Oberhuber 2008-04-09 21:42:16 +00:00
parent 9a28e0eb21
commit 9c8e811837
11 changed files with 176 additions and 145 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 PalmSource, Inc. and others.
* Copyright (c) 2006, 2008 PalmSource, 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
@ -9,6 +9,7 @@
* Ewa Matejska (PalmSource) - Adapted from LocalRunLaunchDelegate
* Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
* Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry
* Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
*******************************************************************************/
@ -279,17 +280,16 @@ public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate {
// This is necessary because runCommand does not actually run the command right now.
String env[] = new String[0];
IHostShell hostShell = shellService.launchShell("", env,new NullProgressMonitor()); //$NON-NLS-1$
hostShell.writeToShell(remote_command);
Process p = null;
try {
IHostShell hostShell = shellService.launchShell("", env, new NullProgressMonitor()); //$NON-NLS-1$
hostShell.writeToShell(remote_command);
p = new HostShellProcessAdapter(hostShell);
} catch (Exception e) {
if (p != null) {
p.destroy();
}
abort(Messages.RemoteRunLaunchDelegate_7, null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
abort(Messages.RemoteRunLaunchDelegate_7, e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
}
return p;

View file

@ -17,6 +17,7 @@
* David McKnight (IBM) - [196624] dstore miner IDs should be String constants rather than dynamic lookup
* David McKnight (IBM) - [216252] use SimpleSystemMessage instead of getMessage()
* Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable and add Javadoc
* Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
*******************************************************************************/
package org.eclipse.rse.internal.services.dstore.shells;
@ -32,6 +33,7 @@ import org.eclipse.dstore.core.model.IDataStoreProvider;
import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants;
import org.eclipse.rse.internal.services.dstore.ServiceResources;
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import org.eclipse.rse.services.dstore.AbstractDStoreService;
import org.eclipse.rse.services.dstore.util.DStoreStatusMonitor;
import org.eclipse.rse.services.shells.IHostShell;
@ -60,7 +62,7 @@ public class DStoreShellService extends AbstractDStoreService implements IShellS
}
public IHostShell launchShell(String initialWorkingDirectory, String[] environment, IProgressMonitor monitor)
public IHostShell launchShell(String initialWorkingDirectory, String[] environment, IProgressMonitor monitor) throws SystemMessageException
{
if (!isInitialized())
{
@ -69,7 +71,7 @@ public class DStoreShellService extends AbstractDStoreService implements IShellS
return launchShell(initialWorkingDirectory, null, environment, monitor);
}
public IHostShell launchShell(String initialWorkingDirectory, String encoding, String[] environment, IProgressMonitor monitor)
public IHostShell launchShell(String initialWorkingDirectory, String encoding, String[] environment, IProgressMonitor monitor) throws SystemMessageException
{
if (!isInitialized())
{
@ -79,7 +81,7 @@ public class DStoreShellService extends AbstractDStoreService implements IShellS
}
public IHostShell runCommand(String initialWorkingDirectory, String command, String[] environment,
IProgressMonitor monitor)
IProgressMonitor monitor) throws SystemMessageException
{
if (!isInitialized())
{
@ -89,7 +91,7 @@ public class DStoreShellService extends AbstractDStoreService implements IShellS
}
public IHostShell runCommand(String initialWorkingDirectory, String command, String encoding,
String[] environment, IProgressMonitor monitor)
String[] environment, IProgressMonitor monitor) throws SystemMessageException
{
if (!isInitialized())
{
@ -98,7 +100,7 @@ public class DStoreShellService extends AbstractDStoreService implements IShellS
return new DStoreHostShell(getStatusMonitor(getDataStore()), getDataStore(), initialWorkingDirectory, command, encoding, environment);
}
public String[] getHostEnvironment()
public String[] getHostEnvironment() throws SystemMessageException
{
if (_envVars == null || _envVars.length == 0)
{

View file

@ -13,6 +13,7 @@
* Contributors:
* Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
* Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable
* Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
********************************************************************************/
package org.eclipse.rse.internal.services.local.shells;
@ -26,6 +27,7 @@ import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.rse.internal.services.local.ILocalService;
import org.eclipse.rse.internal.services.local.LocalServiceResources;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import org.eclipse.rse.services.shells.AbstractShellService;
import org.eclipse.rse.services.shells.IHostShell;
@ -48,21 +50,21 @@ public class LocalShellService extends AbstractShellService implements ILocalSer
return LocalServiceResources.Local_Shell_Service_Description;
}
public IHostShell launchShell(String initialWorkingDirectory, String encoding, String[] environment, IProgressMonitor monitor)
public IHostShell launchShell(String initialWorkingDirectory, String encoding, String[] environment, IProgressMonitor monitor) throws SystemMessageException
{
LocalHostShell hostShell = new LocalHostShell(initialWorkingDirectory,SHELL_INVOCATION, encoding, environment);
hostShell.run(monitor);
return hostShell;
}
public IHostShell runCommand(String initialWorkingDirectory, String command, String encoding, String[] environment, IProgressMonitor monitor)
public IHostShell runCommand(String initialWorkingDirectory, String command, String encoding, String[] environment, IProgressMonitor monitor) throws SystemMessageException
{
LocalHostShell hostShell = new LocalHostShell(initialWorkingDirectory,command, encoding, environment);
hostShell.run(monitor);
return hostShell;
}
public String[] getHostEnvironment()
public String[] getHostEnvironment() throws SystemMessageException
{
if (_envVars == null)
{

View file

@ -15,6 +15,7 @@
* Martin Oberhuber (Wind River) - Adapted from LocalShellService.
* Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
* Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable
* Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
*******************************************************************************/
package org.eclipse.rse.internal.services.ssh.shell;
@ -24,6 +25,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.rse.internal.services.ssh.ISshService;
import org.eclipse.rse.internal.services.ssh.ISshSessionProvider;
import org.eclipse.rse.internal.services.ssh.SshServiceResources;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import org.eclipse.rse.services.shells.AbstractShellService;
import org.eclipse.rse.services.shells.IHostShell;
@ -41,23 +43,18 @@ public class SshShellService extends AbstractShellService implements ISshService
public IHostShell launchShell(String initialWorkingDirectory,
String encoding, String[] environment,
IProgressMonitor monitor) {
IProgressMonitor monitor) throws SystemMessageException {
SshHostShell hostShell = new SshHostShell(fSessionProvider, initialWorkingDirectory, SshHostShell.SHELL_INVOCATION, encoding, environment);
return hostShell;
}
public IHostShell runCommand(String initialWorkingDirectory,
String command, String encoding, String[] environment,
IProgressMonitor monitor) {
IProgressMonitor monitor) throws SystemMessageException {
SshHostShell hostShell = new SshHostShell(fSessionProvider, initialWorkingDirectory, command, encoding, environment);
return hostShell;
}
public String[] getHostEnvironment() {
//TODO getHostEnvironment is not yet implemented for ssh (needs running remote command and parsing)
return new String[0];
}
public String getName() {
return SshServiceResources.SshShellService_Name;
}

View file

@ -15,13 +15,15 @@
* Martin Oberhuber (Wind River) - Adapted from LocalShellService.
* Sheldon D'souza (Celunite) - Adapted from SshShellService.
* Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable
*******************************************************************************/
* Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
s *******************************************************************************/
package org.eclipse.rse.internal.services.telnet.shell;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.rse.internal.services.telnet.ITelnetService;
import org.eclipse.rse.internal.services.telnet.ITelnetSessionProvider;
import org.eclipse.rse.internal.services.telnet.TelnetServiceResources;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import org.eclipse.rse.services.shells.AbstractShellService;
import org.eclipse.rse.services.shells.IHostShell;
@ -33,20 +35,16 @@ public class TelnetShellService extends AbstractShellService implements ITelnetS
this.fTelnetSessionProvider = sessionProvider;
}
public String[] getHostEnvironment() {
return new String[0];
}
public IHostShell launchShell(String initialWorkingDirectory,
String encoding, String[] environment,
IProgressMonitor monitor) {
IProgressMonitor monitor) throws SystemMessageException {
TelnetHostShell hostShell = new TelnetHostShell(fTelnetSessionProvider, initialWorkingDirectory, TelnetHostShell.SHELL_INVOCATION, encoding, environment);
return hostShell;
}
public IHostShell runCommand(String initialWorkingDirectory,
String command, String encoding, String[] environment,
IProgressMonitor monitor) {
IProgressMonitor monitor) throws SystemMessageException {
TelnetHostShell hostShell = new TelnetHostShell(fTelnetSessionProvider, initialWorkingDirectory, TelnetHostShell.SHELL_INVOCATION, encoding, environment);
return hostShell;
}

View file

@ -18,7 +18,7 @@ import org.eclipse.core.runtime.PlatformObject;
* extend this class.
*
* @see IService
* @since org.eclipse.rse.core 3.0
* @since org.eclipse.rse.services 3.0
*/
public abstract class AbstractService extends PlatformObject implements IService {

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Martin Oberhuber (Wind River) - initial API and implementation
* Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
*******************************************************************************/
package org.eclipse.rse.services.shells;
@ -14,31 +15,41 @@ package org.eclipse.rse.services.shells;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.rse.services.AbstractService;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
/**
* Abstract base class for RSE Shell Service implementations.
*
* @since org.eclipse.rse.services 3.0
*/
public abstract class AbstractShellService extends AbstractService implements IShellService {
/* (non-Javadoc)
* @see org.eclipse.rse.services.shells.IShellService#getHostEnvironment()
private static final String[] EMPTY_ARRAY = new String[0];
/**
* Return an empty host environment. Extenders should override this method
* if they are able to return environment on the remote side. If they do not
* implement this feature, they must not override this method.
*
* @see IShellService#getHostEnvironment()
*/
public String[] getHostEnvironment() {
public String[] getHostEnvironment() throws SystemMessageException {
// not implemented by default
return null;
// TODO SSH https://bugs.eclipse.org/bugs/show_bug.cgi?id=162018
return EMPTY_ARRAY;
}
/* (non-Javadoc)
* @see org.eclipse.rse.services.shells.IShellService#launchShell(java.lang.String, java.lang.String[], org.eclipse.core.runtime.IProgressMonitor)
*/
public IHostShell launchShell(String initialWorkingDirectory, String[] environment, IProgressMonitor monitor) {
public IHostShell launchShell(String initialWorkingDirectory, String[] environment, IProgressMonitor monitor) throws SystemMessageException {
return launchShell(initialWorkingDirectory, null, environment, monitor);
}
/* (non-Javadoc)
* @see org.eclipse.rse.services.shells.IShellService#runCommand(java.lang.String, java.lang.String, java.lang.String[], org.eclipse.core.runtime.IProgressMonitor)
*/
public IHostShell runCommand(String initialWorkingDirectory, String command, String[] environment, IProgressMonitor monitor) {
public IHostShell runCommand(String initialWorkingDirectory, String command, String[] environment, IProgressMonitor monitor) throws SystemMessageException {
return runCommand(initialWorkingDirectory, command, null, environment, monitor);
}

View file

@ -13,6 +13,7 @@
* Contributors:
* Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
* Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable and add Javadoc
* Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
********************************************************************************/
package org.eclipse.rse.services.shells;
@ -20,6 +21,7 @@ package org.eclipse.rse.services.shells;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.rse.services.IService;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
/**
* IShellService is an abstraction for running shells and shell commands.
@ -36,16 +38,19 @@ public interface IShellService extends IService
*
* This is a convenience method, passing <code>null</code> as encoding
* into {@link #launchShell(String, String, String[], IProgressMonitor)}.
*
* @throws SystemMessageException in case an error occurred or the user
* chose to cancel the operation via the progress monitor.
*/
public IHostShell launchShell(String initialWorkingDirectory, String[] environment, IProgressMonitor monitor);
public IHostShell launchShell(String initialWorkingDirectory, String[] environment, IProgressMonitor monitor) throws SystemMessageException;
/**
* Launch a new shell in the specified directory.
*
* @param initialWorkingDirectory initial working directory or
* <code>null</code> if not relevant. The remote shell will
* launch in a directory of its own choice in that case
* (typically a user's home directory).
* @param initialWorkingDirectory initial working directory or empty String
* ("") if not relevant. The remote shell will launch in a
* directory of its own choice in that case (typically a user's
* home directory).
* @param encoding Stream encoding to use, or <code>null</code> to fall
* back to a default encoding. The Shell Service will make
* efforts to determine a proper default encoding on the remote
@ -57,11 +62,13 @@ public interface IShellService extends IService
* set.
* @param monitor Progress Monitor for monitoring and cancellation
* @return the shell object. Note that the shell may not actually be usable
* in case an error occurred or the operation was canceled. In this
* case, {@link IHostShell#isActive()} returns <code>false</code>
* on the created Shell object.
* in case the remote side allows opening a channel but immediately
* closes it again. In this case, {@link IHostShell#isActive()}
* returns <code>false</code> on the created Shell object.
* @throws SystemMessageException in case an error occurred or the user
* chose to cancel the operation via the progress monitor.
*/
public IHostShell launchShell(String initialWorkingDirectory, String encoding, String[] environment, IProgressMonitor monitor);
public IHostShell launchShell(String initialWorkingDirectory, String encoding, String[] environment, IProgressMonitor monitor) throws SystemMessageException;
/**
*
@ -70,8 +77,11 @@ public interface IShellService extends IService
* This is a convenience method, passing <code>null</code> as encoding
* into
* {@link #runCommand(String, String, String, String[], IProgressMonitor)}.
*
* @throws SystemMessageException in case an error occurred or the user
* chose to cancel the operation via the progress monitor.
*/
public IHostShell runCommand(String initialWorkingDirectory, String command, String[] environment, IProgressMonitor monitor);
public IHostShell runCommand(String initialWorkingDirectory, String command, String[] environment, IProgressMonitor monitor) throws SystemMessageException;
/**
* Run a single command in it's own shell.
@ -85,10 +95,10 @@ public interface IShellService extends IService
* connection automatically. Clients need to call {@link IHostShell#exit()}
* in case the shell remains active after the initial command is completed.
*
* @param initialWorkingDirectory initial working directory or
* <code>null</code> if not relevant. The remote shell will
* launch in a directory of its own choice in that case
* (typically a user's home directory).
* @param initialWorkingDirectory initial working directory or empty String
* ("") if not relevant. The remote command will launch in a
* directory of its own choice in that case (typically a user's
* home directory).
* @param encoding Stream encoding to use, or <code>null</code> to fall
* back to a default encoding. The Shell Service will make
* efforts to determine a proper default encoding on the remote
@ -100,12 +110,14 @@ public interface IShellService extends IService
* set.
* @param monitor Progress Monitor for monitoring and cancellation
* @return the shell object for getting output and error streams. Note that
* the shell may not actually be usable in case an error occurred or
* the operation was canceled. In this case,
* {@link IHostShell#isActive()} returns <code>false</code> on the
* created Shell object.
* the shell may not actually be usable in case an error occurred on
* the remote side, such as the command not being executable. In
* this case, {@link IHostShell#isActive()} returns
* <code>false</code> on the created Shell object.
* @throws SystemMessageException in case an error occurred or the user
* chose to cancel the operation via the progress monitor.
*/
public IHostShell runCommand(String initialWorkingDirectory, String command, String encoding, String[] environment, IProgressMonitor monitor);
public IHostShell runCommand(String initialWorkingDirectory, String command, String encoding, String[] environment, IProgressMonitor monitor) throws SystemMessageException;
/**
* Return an array of environment variables that describe the environment on
@ -114,9 +126,11 @@ public interface IShellService extends IService
* environment variable, everything after the equals sign is its contents.
*
* @return Array of environment variable Strings of the form "var=text" if
* supported by a shell service implementation. May return
* <code>null</code> in case environment variable retrieval is not
* supported by a shell service implementation. Should return an
* empty array in case environment variable retrieval is not
* supported on a particular shell service implementation.
* @throws SystemMessageException in case an error occurred or the user
* chose to cancel the operation via the progress monitor.
*/
public String[] getHostEnvironment();
public String[] getHostEnvironment() throws SystemMessageException;
}

View file

@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2005, 2007 IBM Corporation and others. All rights reserved.
* Copyright (c) 2005, 2008 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 http://www.eclipse.org/legal/epl-v10.html
@ -15,6 +15,7 @@
* Martin Oberhuber (Wind River) - [refactor] "shell" instead of "ssh" everywhere
* Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
* David McKnight (IBM) - [175308] Need to use a job to wait for shell to exit
* Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
*******************************************************************************/
package org.eclipse.rse.internal.subsystems.processes.shell.linux;
@ -92,11 +93,10 @@ public class LinuxProcessHelper {
_uidsByUserName = new HashMap();
IShellService shellService = Activator.getShellService(host);
IHostShell hostShell = shellService.launchShell(
"", null, new NullProgressMonitor()); //$NON-NLS-1$
hostShell.writeToShell(getUserNameCommand());
Process p = null;
try {
IHostShell hostShell = shellService.launchShell("", null, new NullProgressMonitor()); //$NON-NLS-1$
hostShell.writeToShell(getUserNameCommand());
p = new HostShellProcessAdapter(hostShell);
// when p.waitFor() is called here, the hostShell.isActive() always
// return true.

View file

@ -11,6 +11,7 @@
* Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
* David McKnight (IBM) - [175308] Need to use a job to wait for shell to exit
* Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable and add Javadoc
* Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
*******************************************************************************/
package org.eclipse.rse.internal.subsystems.processes.shell.linux;
@ -212,15 +213,14 @@ public class LinuxShellProcessService extends AbstractProcessService {
*/
protected String[] internalGetSignalTypes() {
IShellService shellService = Activator.getShellService(host);
IHostShell hostShell = shellService.launchShell(
"", null, new NullProgressMonitor()); //$NON-NLS-1$
hostShell.writeToShell(getSignalTypesCommand());
Process p = null;
try {
IHostShell hostShell = shellService.launchShell("", null, new NullProgressMonitor()); //$NON-NLS-1$
hostShell.writeToShell(getSignalTypesCommand());
p = new HostShellProcessAdapter(hostShell);
// p.waitFor();
} catch (Exception e) {
e.printStackTrace();
Activator.log(e);
if (p != null) {
p.destroy();
}

View file

@ -18,6 +18,7 @@
* David Dykstal (IBM) - [197036] refactored switch configuration
* David Dykstal (IBM) - [217556] remove service subsystem types
* David McKnight (IBM) - [220524] internalSwitchServiceSubSystemConfiguration -> internalSwitchSubSystemConfiguration
* Martin Oberhuber (Wind River) - [226301][api] IShellService should throw SystemMessageException on error
********************************************************************************/
package org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem;
@ -38,6 +39,7 @@ import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem;
import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell;
import org.eclipse.rse.subsystems.shells.core.subsystems.RemoteCmdSubSystem;
import org.eclipse.rse.ui.SystemBasePlugin;
public final class ShellServiceSubSystem extends RemoteCmdSubSystem implements IShellServiceSubSystem
{
@ -193,7 +195,12 @@ public final class ShellServiceSubSystem extends RemoteCmdSubSystem implements I
public String[] getHostEnvironment()
{
try {
return getShellService().getHostEnvironment();
} catch (SystemMessageException e) {
SystemBasePlugin.logError(e.getSystemMessage().getLevelOneText(), e);
}
return new String[0];
}
public List getHostEnvironmentVariables()