public abstract class BaseCommand
extends java.lang.Object
implements org.apache.sshd.server.Command
Modifier and Type | Class and Description |
---|---|
static interface |
BaseCommand.CommandRunnable
Runnable function which can throw an exception.
|
static class |
BaseCommand.Failure
Thrown from
BaseCommand.CommandRunnable.run() with client message and code. |
static interface |
BaseCommand.ProjectCommandRunnable
Runnable function which can retrieve a project name related to the task
|
static class |
BaseCommand.UnloggedFailure
Thrown from
BaseCommand.CommandRunnable.run() with client message and code. |
Modifier and Type | Field and Description |
---|---|
static java.nio.charset.Charset |
ENC |
protected java.io.OutputStream |
err |
protected java.io.InputStream |
in |
protected java.io.OutputStream |
out |
static int |
STATUS_NOT_ADMIN |
Constructor and Description |
---|
BaseCommand() |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
protected BaseCommand.UnloggedFailure |
die(java.lang.String msg) |
protected BaseCommand.UnloggedFailure |
die(java.lang.Throwable why) |
java.lang.String[] |
getArguments() |
protected java.lang.String |
getName() |
protected java.lang.String |
getPluginName() |
protected java.lang.String |
getTaskDescription() |
protected java.lang.String[] |
getTrimmedArguments()
Trim the argument if it is spanning multiple lines.
|
protected com.google.gerrit.util.cli.CmdLineParser |
newCmdLineParser(java.lang.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()
Parses the command line argument, injecting parsed values into fields.
|
protected void |
parseCommandLine(java.lang.Object options)
Parses the command line argument, injecting parsed values into fields.
|
protected void |
provideStateTo(org.apache.sshd.server.Command cmd)
Pass all state into the command, then run its start method.
|
void |
setArguments(java.lang.String[] argv) |
void |
setErrorStream(java.io.OutputStream err) |
void |
setExitCallback(org.apache.sshd.server.ExitCallback callback) |
void |
setInputStream(java.io.InputStream in) |
void |
setOutputStream(java.io.OutputStream out) |
protected void |
startThread(BaseCommand.CommandRunnable thunk)
Spawn a function into its own thread.
|
protected void |
startThread(java.lang.Runnable thunk)
Spawn a function into its own thread.
|
protected static java.io.PrintWriter |
toPrintWriter(java.io.OutputStream o)
Wrap the supplied output stream in a UTF-8 encoded PrintWriter.
|
protected java.lang.String |
usage() |
protected void |
writeError(java.lang.String type,
java.lang.String msg) |
public static final java.nio.charset.Charset ENC
public static final int STATUS_NOT_ADMIN
protected java.io.InputStream in
protected java.io.OutputStream out
protected java.io.OutputStream err
public void setInputStream(java.io.InputStream in)
setInputStream
in interface org.apache.sshd.server.Command
public void setOutputStream(java.io.OutputStream out)
setOutputStream
in interface org.apache.sshd.server.Command
public void setErrorStream(java.io.OutputStream err)
setErrorStream
in interface org.apache.sshd.server.Command
public void setExitCallback(org.apache.sshd.server.ExitCallback callback)
setExitCallback
in interface org.apache.sshd.server.Command
protected java.lang.String getPluginName()
protected java.lang.String getName()
public java.lang.String[] getArguments()
public void setArguments(java.lang.String[] argv)
protected java.lang.String[] getTrimmedArguments()
public void destroy()
destroy
in interface org.apache.sshd.server.CommandLifecycle
protected void provideStateTo(org.apache.sshd.server.Command cmd)
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.
cmd
- the command that will receive the current state.protected void parseCommandLine() throws BaseCommand.UnloggedFailure
This method must be explicitly invoked to cause a parse.
BaseCommand.UnloggedFailure
- if the command line arguments were invalid.Option
,
Argument
protected void parseCommandLine(java.lang.Object options) throws BaseCommand.UnloggedFailure
This method must be explicitly invoked to cause a parse.
options
- object whose fields declare Option and Argument annotations to describe the
parameters of the command. Usually this
.BaseCommand.UnloggedFailure
- if the command line arguments were invalid.Option
,
Argument
protected java.lang.String usage()
protected com.google.gerrit.util.cli.CmdLineParser newCmdLineParser(java.lang.Object options)
protected void startThread(java.lang.Runnable thunk)
Typically this should be invoked within CommandLifecycle.start(Environment)
, such as:
startThread(new Runnable() { public void run() { runImp(); } });
thunk
- the runnable to execute on the thread, performing the command's logic.protected void startThread(BaseCommand.CommandRunnable thunk)
Typically this should be invoked within CommandLifecycle.start(Environment)
, such as:
startThread(new CommandRunnable() { public void run() throws Exception { runImp(); } });
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.
thunk
- the runnable to execute on the thread, performing the command's logic.protected void onExit(int rc)
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.
rc
- exit code for the remote client.protected static java.io.PrintWriter toPrintWriter(java.io.OutputStream o)
protected BaseCommand.UnloggedFailure die(java.lang.String msg)
protected BaseCommand.UnloggedFailure die(java.lang.Throwable why)
protected void writeError(java.lang.String type, java.lang.String msg)
protected java.lang.String getTaskDescription()