Package com.google.gerrit.sshd
Class BaseCommand
java.lang.Object
com.google.gerrit.sshd.BaseCommand
- All Implemented Interfaces:
org.apache.sshd.server.command.Command
,org.apache.sshd.server.command.CommandDirectErrorStreamAware
,org.apache.sshd.server.command.CommandDirectInputStreamAware
,org.apache.sshd.server.command.CommandDirectOutputStreamAware
,org.apache.sshd.server.command.CommandDirectStreamsAware
,org.apache.sshd.server.command.CommandLifecycle
- Direct Known Subclasses:
AbstractGitCommand
,AliasCommand
,SshCommand
,StreamEvents
,SuExec
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Runnable function which can throw an exception.static class
Thrown fromBaseCommand.CommandRunnable.run()
with client message and code.static interface
Runnable function which can retrieve a project name related to the taskstatic class
Thrown fromBaseCommand.CommandRunnable.run()
with client message and code. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected RequestCleanup
protected DynamicMap<DynamicOptions.DynamicBean>
static final Charset
protected OutputStream
protected org.apache.sshd.server.ExitCallback
protected InputStream
protected com.google.inject.Injector
protected OutputStream
static final int
protected CurrentUser
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy
(org.apache.sshd.server.channel.ChannelSession channel) protected BaseCommand.UnloggedFailure
protected BaseCommand.UnloggedFailure
protected BaseCommand.UnloggedFailure
protected void
String[]
protected String
getName()
protected String
protected String
protected String[]
Trim the argument if it is spanning multiple lines.protected com.google.gerrit.util.cli.CmdLineParser
newCmdLineParser
(Object options) Construct a new parser for this command's received command line.protected void
onExit
(int rc) Terminate this command and return a result code to the remote client.protected void
parseCommandLine
(DynamicOptions pluginOptions) Parses the command line argument, injecting parsed values into fields.protected void
parseCommandLine
(Object options, DynamicOptions pluginOptions) Parses the command line argument, injecting parsed values into fields.protected void
provideStateTo
(org.apache.sshd.server.command.Command cmd) Pass all state into the command, then run its start method.void
setArguments
(String[] argv) void
void
setExitCallback
(org.apache.sshd.server.ExitCallback callback) void
void
protected void
startThread
(BaseCommand.CommandRunnable thunk, AccessPath accessPath) Spawn a function into its own thread.protected static PrintWriter
Wrap the supplied output stream in a UTF-8 encoded PrintWriter.protected String
usage()
protected void
writeError
(String type, String msg) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.sshd.server.command.CommandLifecycle
start
-
Field Details
-
ENC
-
STATUS_NOT_ADMIN
public static final int STATUS_NOT_ADMIN- See Also:
-
in
-
out
-
err
-
exit
protected org.apache.sshd.server.ExitCallback exit -
user
-
cleanup
-
injector
@Inject protected com.google.inject.Injector injector -
dynamicBeans
-
-
Constructor Details
-
BaseCommand
public BaseCommand()
-
-
Method Details
-
setInputStream
- Specified by:
setInputStream
in interfaceorg.apache.sshd.server.command.CommandDirectInputStreamAware
-
setOutputStream
- Specified by:
setOutputStream
in interfaceorg.apache.sshd.server.command.CommandDirectOutputStreamAware
-
setErrorStream
- Specified by:
setErrorStream
in interfaceorg.apache.sshd.server.command.CommandDirectErrorStreamAware
-
setExitCallback
public void setExitCallback(org.apache.sshd.server.ExitCallback callback) - Specified by:
setExitCallback
in interfaceorg.apache.sshd.server.command.Command
-
getPluginName
-
getName
-
getArguments
-
setArguments
-
getTrimmedArguments
Trim the argument if it is spanning multiple lines.- Returns:
- the arguments where all the multiple-line fields are trimmed.
-
destroy
public void destroy(org.apache.sshd.server.channel.ChannelSession channel) - Specified by:
destroy
in interfaceorg.apache.sshd.server.command.CommandLifecycle
-
provideStateTo
protected void provideStateTo(org.apache.sshd.server.command.Command cmd) Pass all state into the command, then run its start method.This method copies all critical state, like the input and output streams, into the supplied command. The caller must still invoke
cmd.start()
if wants to pass control to the command.- Parameters:
cmd
- the command that will receive the current state.
-
parseCommandLine
Parses the command line argument, injecting parsed values into fields.This method must be explicitly invoked to cause a parse.
- Parameters:
pluginOptions
- which helps to define and parse options provided from plugins- Throws:
BaseCommand.UnloggedFailure
- if the command line arguments were invalid.- See Also:
-
Option
Argument
-
parseCommandLine
protected void parseCommandLine(Object options, DynamicOptions pluginOptions) throws BaseCommand.UnloggedFailure Parses the command line argument, injecting parsed values into fields.This method must be explicitly invoked to cause a parse.
- Parameters:
options
- object whose fields declare Option and Argument annotations to describe the parameters of the command. Usuallythis
.pluginOptions
- which helps to define and parse options provided from plugins- Throws:
BaseCommand.UnloggedFailure
- if the command line arguments were invalid.- See Also:
-
Option
Argument
-
usage
-
newCmdLineParser
Construct a new parser for this command's received command line. -
startThread
Spawn a function into its own thread.Typically this should be invoked within
CommandLifecycle.start(ChannelSession, Environment)
, such as:startThread(new CommandRunnable() { public void run() throws Exception { runImp(); } }, accessPath);
If the function throws an exception, it is translated to a simple message for the client, a non-zero exit code, and the stack trace is logged.
- Parameters:
thunk
- the runnable to execute on the thread, performing the command's logic.accessPath
- the path used by the end user for running the SSH command
-
onExit
protected void onExit(int rc) Terminate this command and return a result code to the remote client.Commands should invoke this at most once. Once invoked, the command may lose access to request based resources as any callbacks previously registered with
RequestCleanup
will fire.- Parameters:
rc
- exit code for the remote client.
-
toPrintWriter
Wrap the supplied output stream in a UTF-8 encoded PrintWriter. -
die
-
die
-
die
-
writeError
-
enableGracefulStop
protected void enableGracefulStop() -
getTaskDescription
-