Class Shell
java.lang.Object
org.codehaus.plexus.util.cli.shell.Shell
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
BourneShell,CmdShell,CommandShell
Class that abstracts the Shell functionality, with subclasses for shells that behave particularly, like
command.comcmd.exe
- Since:
- 1.2
- Author:
- Carlos Sanchez
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddShellArg(String arg) voidclone()protected Stringprotected chargetCommandLine(String executable, String[] arguments) Get the command line for the provided executable and arguments in this shellprotected char[]getEscapeChars(boolean includeSingleQuote, boolean includeDoubleQuote) protected charprotected StringgetOriginalCommandLine(String executable, String[] arguments) protected char[]getRawCommandLine(String executable, String[] arguments) String[]Get the command to execute the shellgetShellCommandLine(String[] arguments) Get the full command line to execute, including shell command, shell arguments, executable and executable argumentsprotected booleanprotected booleanbooleanbooleanprotected booleanprotected booleanprotected StringquoteOneItem(String inputString, boolean isExecutable) protected voidsetArgumentEscapePattern(String argumentEscapePattern) protected voidsetArgumentQuoteDelimiter(char argQuoteDelimiter) protected voidsetDoubleQuotedArgumentEscaped(boolean doubleQuotedArgumentEscaped) protected voidsetDoubleQuotedExecutableEscaped(boolean doubleQuotedExecutableEscaped) voidsetExecutable(String executable) protected voidsetExecutableQuoteDelimiter(char exeQuoteDelimiter) voidsetQuotedArgumentsEnabled(boolean quotedArgumentsEnabled) voidsetQuotedExecutableEnabled(boolean quotedExecutableEnabled) voidsetShellArgs(String[] shellArgs) Set the shell arguments when calling a command line (not the executable arguments) (eg.voidsetShellCommand(String shellCommand) Set the command to execute the shell (eg.protected voidsetSingleQuotedArgumentEscaped(boolean singleQuotedArgumentEscaped) protected voidsetSingleQuotedExecutableEscaped(boolean singleQuotedExecutableEscaped) voidsetUnconditionalQuoting(boolean unconditionallyQuote) Toggle unconditional quotingvoidsetWorkingDirectory(File workingDir) voidsetWorkingDirectory(String path)
-
Constructor Details
-
Shell
public Shell()
-
-
Method Details
-
setUnconditionalQuoting
public void setUnconditionalQuoting(boolean unconditionallyQuote) Toggle unconditional quoting- Parameters:
unconditionallyQuote- see name
-
setShellCommand
Set the command to execute the shell (eg. COMMAND.COM, /bin/bash,...)- Parameters:
shellCommand- see name
-
getShellCommand
Get the command to execute the shell- Returns:
- the command
-
setShellArgs
Set the shell arguments when calling a command line (not the executable arguments) (eg. /X /C for CMD.EXE)- Parameters:
shellArgs- see name
-
getShellArgs
- Returns:
- the shell arguments
-
getCommandLine
Get the command line for the provided executable and arguments in this shell- Parameters:
executable- executable that the shell has to callarguments- arguments for the executable, not the shell- Returns:
- List with one String object with executable and arguments quoted as needed
-
quoteOneItem
-
getRawCommandLine
-
getQuotingTriggerChars
protected char[] getQuotingTriggerChars() -
getExecutionPreamble
-
getEscapeChars
protected char[] getEscapeChars(boolean includeSingleQuote, boolean includeDoubleQuote) -
isDoubleQuotedArgumentEscaped
protected boolean isDoubleQuotedArgumentEscaped() -
isSingleQuotedArgumentEscaped
protected boolean isSingleQuotedArgumentEscaped() -
isDoubleQuotedExecutableEscaped
protected boolean isDoubleQuotedExecutableEscaped() -
isSingleQuotedExecutableEscaped
protected boolean isSingleQuotedExecutableEscaped() -
setArgumentQuoteDelimiter
protected void setArgumentQuoteDelimiter(char argQuoteDelimiter) -
getArgumentQuoteDelimiter
protected char getArgumentQuoteDelimiter() -
setExecutableQuoteDelimiter
protected void setExecutableQuoteDelimiter(char exeQuoteDelimiter) -
getExecutableQuoteDelimiter
protected char getExecutableQuoteDelimiter() -
setArgumentEscapePattern
-
getArgumentEscapePattern
-
getShellCommandLine
Get the full command line to execute, including shell command, shell arguments, executable and executable arguments- Parameters:
arguments- arguments for the executable, not the shell- Returns:
- List of String objects, whose array version is suitable to be used as argument of Runtime.getRuntime().exec()
-
getShellArgsList
-
addShellArg
-
setQuotedArgumentsEnabled
public void setQuotedArgumentsEnabled(boolean quotedArgumentsEnabled) -
isQuotedArgumentsEnabled
public boolean isQuotedArgumentsEnabled() -
setQuotedExecutableEnabled
public void setQuotedExecutableEnabled(boolean quotedExecutableEnabled) -
isQuotedExecutableEnabled
public boolean isQuotedExecutableEnabled() -
setExecutable
- Parameters:
executable- Sets the executable to run.
-
getExecutable
-
setWorkingDirectory
- Parameters:
path- Sets execution directory.
-
setWorkingDirectory
- Parameters:
workingDir- Sets execution directory.
-
getWorkingDirectory
-
getWorkingDirectoryAsString
-
clearArguments
public void clearArguments() -
clone
-
getOriginalExecutable
-
getOriginalCommandLine
-
setDoubleQuotedArgumentEscaped
protected void setDoubleQuotedArgumentEscaped(boolean doubleQuotedArgumentEscaped) -
setDoubleQuotedExecutableEscaped
protected void setDoubleQuotedExecutableEscaped(boolean doubleQuotedExecutableEscaped) -
setSingleQuotedArgumentEscaped
protected void setSingleQuotedArgumentEscaped(boolean singleQuotedArgumentEscaped) -
setSingleQuotedExecutableEscaped
protected void setSingleQuotedExecutableEscaped(boolean singleQuotedExecutableEscaped)
-