public abstract class AbstractShell extends AbstractShellStatusPublisher implements Shell
Shell
implementation.Modifier and Type | Field and Description |
---|---|
static String |
completionKeys |
protected Logger |
exceptionLogger |
protected ExitShellRequest |
exitShellRequest |
protected boolean |
inBlockComment |
protected Logger |
logger |
protected static String |
ROO_PROMPT |
static String |
shellPrompt |
shellStatus, shellStatusListeners
WINDOW_TITLE_SLOT
Constructor and Description |
---|
AbstractShell() |
Modifier and Type | Method and Description |
---|---|
void |
blockCommentBegin() |
void |
blockCommentFinish() |
CommandResult |
executeCommand(String line)
Runs the specified command.
|
boolean |
executeScriptLine(String line)
Execute the single line from a script.
|
void |
flash(Level level,
String message,
String slot)
Simple implementation of
flash(Level, String, String) that simply displays the message via the logger. |
protected abstract ExecutionStrategy |
getExecutionStrategy() |
ExitShellRequest |
getExitShellRequest() |
File |
getHome()
Obtains the home directory for the current shell instance.
|
protected abstract String |
getHomeAsString() |
protected abstract Parser |
getParser() |
String |
getShellPrompt() |
protected void |
handleExecutionResult(Object result)
Handles the result of execution of a command.
|
protected void |
logCommandIfRequired(String line,
boolean successful)
Allows a subclass to log the execution of a well-formed command.
|
protected void |
logCommandToOutput(String processedLine)
Allows a subclass to actually write the resulting logged command to some form of output.
|
void |
setPromptPath(String path)
Base implementation of the
Shell.setPromptPath(String) method, designed for simple shell
implementations. |
void |
setPromptPath(String path,
boolean overrideStyle)
Default implementation of
Shell#setPromptPath(String, boolean)) method to satisfy STS compatibility. |
String |
versionInfo() |
addShellStatusListener, getShellStatus, removeShellStatusListener, setShellStatus, setShellStatus
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isDevelopmentMode, promptLoop, setDevelopmentMode
addShellStatusListener, getShellStatus, removeShellStatusListener
protected static final String ROO_PROMPT
public static String completionKeys
public static String shellPrompt
protected final Logger logger
protected final Logger exceptionLogger
protected boolean inBlockComment
protected ExitShellRequest exitShellRequest
protected abstract String getHomeAsString()
protected abstract ExecutionStrategy getExecutionStrategy()
protected abstract Parser getParser()
public boolean executeScriptLine(String line)
This method can be overridden by sub-classes to pre-process script lines.
public CommandResult executeCommand(String line)
Shell
executeCommand
in interface Shell
line
- to execute (required)protected void logCommandIfRequired(String line, boolean successful)
Implementations should consider specially handling the "script" commands, and also
indicating whether a command was successful or not. Implementations that wish to behave
consistently with other AbstractShell
subclasses are encouraged to simply override
logCommandToOutput(String)
instead, and only override this method if you actually
need to fine-tune the output logic.
line
- the parsed line (any comments have been removed; never null)successful
- if the command was successful or notprotected void logCommandToOutput(String processedLine)
logCommandIfRequired(String, boolean)
.
Implementations should invoke getExitShellRequest()
to monitor any attempts to exit the shell and
release resources such as output log files.
processedLine
- the line that should be appended to some type of output (excluding the \n character)public void setPromptPath(String path)
Shell.setPromptPath(String)
method, designed for simple shell
implementations. Advanced implementations (eg those that support ANSI codes etc) will likely want
to override this method and set the shellPrompt
variable directly.setPromptPath
in interface Shell
path
- to set (can be null or empty; must NOT be formatted in any special way eg ANSI codes)public void setPromptPath(String path, boolean overrideStyle)
Shell#setPromptPath(String, boolean))
method to satisfy STS compatibility.setPromptPath
in interface Shell
path
- to set (can be null or empty)overrideStyle
- public ExitShellRequest getExitShellRequest()
getExitShellRequest
in interface Shell
@CliCommand(value="/*", help="Start of block comment") public void blockCommentBegin()
@CliCommand(value="*/", help="End of block comment") public void blockCommentFinish()
public String versionInfo()
public String getShellPrompt()
getShellPrompt
in interface ShellPromptAccessor
public File getHome()
Note: calls the getHomeAsString()
method to allow subclasses to provide the home directory location as
string using different environment-specific strategies.
If the path indicated by getHomeAsString()
exists and refers to a directory, that directory
is returned.
If the path indicated by getHomeAsString()
exists and refers to a file, an exception is thrown.
If the path indicated by getHomeAsString()
does not exist, it will be created as a directory.
If this fails, an exception will be thrown.
public void flash(Level level, String message, String slot)
flash(Level, String, String)
that simply displays the message via the logger. It is
strongly recommended shell implementations override this method with a more effective approach.protected void handleExecutionResult(Object result)
null
. If result is a
Iterable
object, it will be iterated through to print
the output of toString. For other type of objects, simply output
of toString is shown. Subclasses can alter this implementation
to handle the result differently.result
- not null
result of execution of a command.