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

[cleanup] Improve Javadoc of RemoteCommandShellOperation

This commit is contained in:
Martin Oberhuber 2008-12-04 16:40:29 +00:00
parent 448c966004
commit 6acf667c72
2 changed files with 67 additions and 67 deletions

View file

@ -53,7 +53,7 @@ plugin@org.eclipse.rse.subsystems.processes.core=v20080529,:pserver:anonymous:no
plugin@org.eclipse.rse.subsystems.processes.dstore=v20080604,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.rse/plugins/org.eclipse.rse.subsystems.processes.dstore plugin@org.eclipse.rse.subsystems.processes.dstore=v20080604,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.rse/plugins/org.eclipse.rse.subsystems.processes.dstore
plugin@org.eclipse.rse.subsystems.processes.local=v20080604,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.rse/plugins/org.eclipse.rse.subsystems.processes.local plugin@org.eclipse.rse.subsystems.processes.local=v20080604,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.rse/plugins/org.eclipse.rse.subsystems.processes.local
plugin@org.eclipse.rse.subsystems.processes.shell.linux=v20080714,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux plugin@org.eclipse.rse.subsystems.processes.shell.linux=v20080714,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.rse/plugins/org.eclipse.rse.subsystems.processes.shell.linux
plugin@org.eclipse.rse.subsystems.shells.core=v200811251700,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.rse/plugins/org.eclipse.rse.subsystems.shells.core plugin@org.eclipse.rse.subsystems.shells.core=v200812041630,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.rse/plugins/org.eclipse.rse.subsystems.shells.core
plugin@org.eclipse.rse.subsystems.shells.dstore=v20080604,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.rse/plugins/org.eclipse.rse.subsystems.shells.dstore plugin@org.eclipse.rse.subsystems.shells.dstore=v20080604,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.rse/plugins/org.eclipse.rse.subsystems.shells.dstore
plugin@org.eclipse.rse.subsystems.shells.local=v20080604,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.rse/plugins/org.eclipse.rse.subsystems.shells.local plugin@org.eclipse.rse.subsystems.shells.local=v20080604,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.rse/plugins/org.eclipse.rse.subsystems.shells.local
plugin@org.eclipse.rse.subsystems.shells.ssh=v20080604,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.rse/plugins/org.eclipse.rse.subsystems.shells.ssh plugin@org.eclipse.rse.subsystems.shells.ssh=v20080604,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.rse/plugins/org.eclipse.rse.subsystems.shells.ssh

View file

@ -1,15 +1,15 @@
/******************************************************************************** /********************************************************************************
* Copyright (c) 2006, 2007 IBM Corporation and others. All rights reserved. * Copyright (c) 2006, 2008 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the terms * 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 * of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html * available at http://www.eclipse.org/legal/epl-v10.html
* *
* Initial Contributors: * Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer * The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir, * component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
* *
* Contributors: * Contributors:
* Martin Oberhuber (Wind River) - [168975] Move RSE Events API to Core * Martin Oberhuber (Wind River) - [168975] Move RSE Events API to Core
* Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
@ -35,17 +35,15 @@ import org.eclipse.rse.ui.SystemBasePlugin;
import org.eclipse.rse.ui.model.ISystemShellProvider; import org.eclipse.rse.ui.model.ISystemShellProvider;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
/**
* Base class for command shell wrappers that use echo markers to parse command finish.
/* * This abstract class can be extended to provide a command shell wrapper. When
* This abstract class can be extended to provide a command shell wrapper. * running a shell, commands can be piped to the shell via the sendCommand()
* When running a shell, commands can be piped to the shell via the * method. Echo commands are used to determine when each command is complete.
* sendCommand() method. Echo commands are used to determine when each command * Whenever a command completes, the handleCommandFinished() method is called.
* is complete. Whenever a command completes, the handleCommandFinished() method
* is called.
* *
*/ */
public abstract class RemoteCommandShellOperation public abstract class RemoteCommandShellOperation
implements ISystemResourceChangeListener, ISystemShellProvider implements ISystemResourceChangeListener, ISystemShellProvider
{ {
@ -58,32 +56,32 @@ public abstract class RemoteCommandShellOperation
_alias = alias; _alias = alias;
_command = command; _command = command;
} }
public String getAlias() public String getAlias()
{ {
return _alias; return _alias;
} }
public String getCommand() public String getCommand()
{ {
return _command; return _command;
} }
} }
protected IRemoteCmdSubSystem _cmdSubSystem; protected IRemoteCmdSubSystem _cmdSubSystem;
protected IRemoteFile _pwd; protected IRemoteFile _pwd;
protected Shell _shell; protected Shell _shell;
protected IRemoteCommandShell _remoteCmdShell; protected IRemoteCommandShell _remoteCmdShell;
private Stack _commandStack; private Stack _commandStack;
private int _outputOffset = 0; private int _outputOffset = 0;
private String _cmdSeparator = ";"; //$NON-NLS-1$ private String _cmdSeparator = ";"; //$NON-NLS-1$
private Random _random; private Random _random;
/* /**
* Constructor * Constructor
*/ */
public RemoteCommandShellOperation(Shell shell, IRemoteCmdSubSystem cmdSubSystem, IRemoteFile pwd) public RemoteCommandShellOperation(Shell shell, IRemoteCmdSubSystem cmdSubSystem, IRemoteFile pwd)
@ -95,13 +93,13 @@ public abstract class RemoteCommandShellOperation
_commandStack = new Stack(); _commandStack = new Stack();
_cmdSeparator = _cmdSubSystem.getParentRemoteCmdSubSystemConfiguration().getCommandSeparator(); _cmdSeparator = _cmdSubSystem.getParentRemoteCmdSubSystemConfiguration().getCommandSeparator();
} }
public void setWorkingDirectory(IRemoteFile pwd) public void setWorkingDirectory(IRemoteFile pwd)
{ {
_pwd = pwd; _pwd = pwd;
} }
/* /**
* Launches a new remote shell * Launches a new remote shell
*/ */
public IRemoteCommandShell run() public IRemoteCommandShell run()
@ -109,20 +107,20 @@ public abstract class RemoteCommandShellOperation
try try
{ {
RSECorePlugin.getTheSystemRegistry().addSystemResourceChangeListener(this); RSECorePlugin.getTheSystemRegistry().addSystemResourceChangeListener(this);
_remoteCmdShell = _cmdSubSystem.runShell(_pwd, new NullProgressMonitor()); _remoteCmdShell = _cmdSubSystem.runShell(_pwd, new NullProgressMonitor());
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
return _remoteCmdShell; return _remoteCmdShell;
} }
public IRemoteCommandShell getRemoteCommandShell() public IRemoteCommandShell getRemoteCommandShell()
{ {
return _remoteCmdShell; return _remoteCmdShell;
} }
public void associateProject(IProject project) public void associateProject(IProject project)
{ {
if (_remoteCmdShell != null) if (_remoteCmdShell != null)
@ -130,8 +128,8 @@ public abstract class RemoteCommandShellOperation
_remoteCmdShell.associateProject(project); _remoteCmdShell.associateProject(project);
} }
} }
/* /**
* Called when a shell is complete. * Called when a shell is complete.
*/ */
public void finish() public void finish()
@ -144,22 +142,22 @@ public abstract class RemoteCommandShellOperation
_cmdSubSystem.cancelShell(_remoteCmdShell, new NullProgressMonitor()); _cmdSubSystem.cancelShell(_remoteCmdShell, new NullProgressMonitor());
} }
catch (Exception e) catch (Exception e)
{ {
} }
} }
} }
private String getEchoCmd(CommandAlias alias) private String getEchoCmd(CommandAlias alias)
{ {
return "echo " + getEchoResult(alias); //$NON-NLS-1$ return "echo " + getEchoResult(alias); //$NON-NLS-1$
} }
private String getEchoResult(CommandAlias alias) private String getEchoResult(CommandAlias alias)
{ {
return "BEGIN-END-TAG:" + alias.getAlias() + " done"; //$NON-NLS-1$ //$NON-NLS-2$ return "BEGIN-END-TAG:" + alias.getAlias() + " done"; //$NON-NLS-1$ //$NON-NLS-2$
} }
public String getCurrentCommand() public String getCurrentCommand()
{ {
if (_commandStack != null && _commandStack.size() > 0) if (_commandStack != null && _commandStack.size() > 0)
@ -169,7 +167,7 @@ public abstract class RemoteCommandShellOperation
} }
return null; return null;
} }
/** /**
* Send a command to the running command shell. * Send a command to the running command shell.
* @param cmd the command to run in the shell * @param cmd the command to run in the shell
@ -184,18 +182,18 @@ public abstract class RemoteCommandShellOperation
CommandAlias alias = new CommandAlias(newId, cmd); CommandAlias alias = new CommandAlias(newId, cmd);
_commandStack.push(alias); _commandStack.push(alias);
String echoCmd = getEchoCmd(alias); String echoCmd = getEchoCmd(alias);
// echo command appended after ; so that // echo command appended after ; so that
// it isn't treated like stdin for the intial command // it isn't treated like stdin for the intial command
_cmdSubSystem.sendCommandToShell(cmd + _cmdSeparator + echoCmd, _remoteCmdShell, new NullProgressMonitor()); _cmdSubSystem.sendCommandToShell(cmd + _cmdSeparator + echoCmd, _remoteCmdShell, new NullProgressMonitor());
} }
catch (Exception e) catch (Exception e)
{ {
} }
} }
} }
/** /**
* Send input to the running command shell. The input is treated as input to * Send input to the running command shell. The input is treated as input to
* a running program - rather than a new command. As such, no echos are used * a running program - rather than a new command. As such, no echos are used
@ -209,15 +207,15 @@ public abstract class RemoteCommandShellOperation
try try
{ {
_cmdSubSystem.sendCommandToShell(input, _remoteCmdShell, new NullProgressMonitor()); _cmdSubSystem.sendCommandToShell(input, _remoteCmdShell, new NullProgressMonitor());
} }
catch (Exception e) catch (Exception e)
{ {
} }
} }
} }
public Shell getShell() public Shell getShell()
{ {
if (_shell.isDisposed()) if (_shell.isDisposed())
@ -226,9 +224,9 @@ public abstract class RemoteCommandShellOperation
} }
return _shell; return _shell;
} }
/** /**
* Indicates whether the command shell is active or not * Indicates whether the command shell is active or not
* @return true if the command shell is running * @return true if the command shell is running
@ -237,11 +235,11 @@ public abstract class RemoteCommandShellOperation
{ {
if (_remoteCmdShell != null) if (_remoteCmdShell != null)
{ {
return _remoteCmdShell.isActive() && _cmdSubSystem.isConnected(); return _remoteCmdShell.isActive() && _cmdSubSystem.isConnected();
} }
return false; return false;
} }
/* /*
* Check for remote changes * Check for remote changes
*/ */
@ -270,7 +268,7 @@ public abstract class RemoteCommandShellOperation
} }
/** /**
* Called whenever output is retrieved from the host * Called (on the main Thread) whenever output is retrieved from the host
*/ */
public void outputUpdated() public void outputUpdated()
{ {
@ -278,16 +276,16 @@ public abstract class RemoteCommandShellOperation
synchronized(_commandStack) synchronized(_commandStack)
{ {
if (!_commandStack.empty()) if (!_commandStack.empty())
{ {
Object[] outputs = _remoteCmdShell.listOutput(); Object[] outputs = _remoteCmdShell.listOutput();
synchronized(outputs) synchronized(outputs)
{ {
for (int i = _outputOffset; i < outputs.length && !_commandStack.empty(); i++) for (int i = _outputOffset; i < outputs.length && !_commandStack.empty(); i++)
{ {
boolean handledOutput = false; boolean handledOutput = false;
CommandAlias firstCommand = (CommandAlias)_commandStack.firstElement(); CommandAlias firstCommand = (CommandAlias)_commandStack.firstElement();
Object output = outputs[_outputOffset]; Object output = outputs[_outputOffset];
if (output instanceof IRemoteOutput) if (output instanceof IRemoteOutput)
{ {
@ -296,7 +294,7 @@ public abstract class RemoteCommandShellOperation
if (commandMatches(text, firstCommand)) if (commandMatches(text, firstCommand))
{ {
_commandStack.remove(0); _commandStack.remove(0);
handleCommandFinished(firstCommand.getCommand()); handleCommandFinished(firstCommand.getCommand());
handledOutput = true; handledOutput = true;
} }
} }
@ -307,14 +305,14 @@ public abstract class RemoteCommandShellOperation
_outputOffset++; _outputOffset++;
} }
} }
} }
} }
} }
protected boolean commandMatches(String outputEcho, CommandAlias firstCommand) protected boolean commandMatches(String outputEcho, CommandAlias firstCommand)
{ {
String expected = getEchoResult(firstCommand); String expected = getEchoResult(firstCommand);
if (outputEcho.equals(expected)) if (outputEcho.equals(expected))
{ {
return true; return true;
@ -330,29 +328,31 @@ public abstract class RemoteCommandShellOperation
} }
} }
} }
return false; return false;
} }
/* /**
* Called when the shell is complete * Called (on the main Thread) when the shell is complete
*/ */
public void handleShellFinished() public void handleShellFinished()
{ {
finish(); finish();
} }
/* /**
* Called when the specified command is complete * Called (on the main Thread) when the specified command is complete
*
* @param cmd the completed command * @param cmd the completed command
*/ */
public abstract void handleCommandFinished(String cmd); public abstract void handleCommandFinished(String cmd);
/* /**
* Called whenever output has changed * Called (on the main Thread) whenever output has changed
*
* @param command the current command * @param command the current command
* @param output the new output object * @param output the new output object
*/ */
public abstract void handleOutputChanged(String command, Object output); public abstract void handleOutputChanged(String command, Object output);
} }