Class Shell
- java.lang.Object
-
- org.codehaus.plexus.util.cli.shell.Shell
-
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
BourneShell,CmdShell,CommandShell
public class Shell extends Object implements Cloneable
Class that abstracts the Shell functionality, with subclases for shells that behave particularly, like
command.comcmd.exe
- Since:
- 1.2
- Version:
- $Id$
- Author:
- Carlos Sanchez
-
-
Field Summary
Fields Modifier and Type Field Description private charargQuoteDelimiterprivate StringargumentEscapePatternprivate static char[]DEFAULT_QUOTING_TRIGGER_CHARSprivate booleandoubleQuotedArgumentEscapedprivate booleandoubleQuotedExecutableEscapedprivate Stringexecutableprivate charexeQuoteDelimiterprivate booleanquotedArgumentsEnabledprivate booleanquotedExecutableEnabledprivate List<String>shellArgsprivate StringshellCommandprivate booleansingleQuotedArgumentEscapedprivate booleansingleQuotedExecutableEscapedprivate booleanunconditionallyQuoteprivate StringworkingDir
-
Constructor Summary
Constructors Constructor Description Shell()
-
Method Summary
Modifier and Type Method Description voidaddShellArg(String arg)voidclearArguments()Objectclone()protected StringgetArgumentEscapePattern()protected chargetArgumentQuoteDelimiter()List<String>getCommandLine(String executable, String[] arguments)Get the command line for the provided executable and arguments in this shellprotected char[]getEscapeChars(boolean includeSingleQuote, boolean includeDoubleQuote)StringgetExecutable()protected chargetExecutableQuoteDelimiter()protected StringgetExecutionPreamble()List<String>getOriginalCommandLine(String executable, String[] arguments)StringgetOriginalExecutable()protected char[]getQuotingTriggerChars()protected List<String>getRawCommandLine(String executable, String[] arguments)String[]getShellArgs()Get the shell argumentsList<String>getShellArgsList()StringgetShellCommand()Get the command to execute the shellList<String>getShellCommandLine(String[] arguments)Get the full command line to execute, including shell command, shell arguments, executable and executable argumentsFilegetWorkingDirectory()StringgetWorkingDirectoryAsString()protected booleanisDoubleQuotedArgumentEscaped()protected booleanisDoubleQuotedExecutableEscaped()booleanisQuotedArgumentsEnabled()booleanisQuotedExecutableEnabled()protected booleanisSingleQuotedArgumentEscaped()protected booleanisSingleQuotedExecutableEscaped()protected StringquoteOneItem(String inputString, boolean isExecutable)protected voidsetArgumentEscapePattern(String argumentEscapePattern)protected voidsetArgumentQuoteDelimiter(char argQuoteDelimiter)protected voidsetDoubleQuotedArgumentEscaped(boolean doubleQuotedArgumentEscaped)protected voidsetDoubleQuotedExecutableEscaped(boolean doubleQuotedExecutableEscaped)voidsetExecutable(String executable)Sets the executable to run.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)Sets execution directory.voidsetWorkingDirectory(String path)Sets execution directory.
-
-
-
Field Detail
-
DEFAULT_QUOTING_TRIGGER_CHARS
private static final char[] DEFAULT_QUOTING_TRIGGER_CHARS
-
shellCommand
private String shellCommand
-
quotedArgumentsEnabled
private boolean quotedArgumentsEnabled
-
unconditionallyQuote
private boolean unconditionallyQuote
-
executable
private String executable
-
workingDir
private String workingDir
-
quotedExecutableEnabled
private boolean quotedExecutableEnabled
-
doubleQuotedArgumentEscaped
private boolean doubleQuotedArgumentEscaped
-
singleQuotedArgumentEscaped
private boolean singleQuotedArgumentEscaped
-
doubleQuotedExecutableEscaped
private boolean doubleQuotedExecutableEscaped
-
singleQuotedExecutableEscaped
private boolean singleQuotedExecutableEscaped
-
argQuoteDelimiter
private char argQuoteDelimiter
-
exeQuoteDelimiter
private char exeQuoteDelimiter
-
argumentEscapePattern
private String argumentEscapePattern
-
-
Method Detail
-
setUnconditionalQuoting
public void setUnconditionalQuoting(boolean unconditionallyQuote)
Toggle unconditional quoting- Parameters:
unconditionallyQuote-
-
setShellCommand
public void setShellCommand(String shellCommand)
Set the command to execute the shell (eg. COMMAND.COM, /bin/bash,...)- Parameters:
shellCommand-
-
getShellCommand
public String getShellCommand()
Get the command to execute the shell- Returns:
- the command to be executed.
-
setShellArgs
public void setShellArgs(String[] shellArgs)
Set the shell arguments when calling a command line (not the executable arguments) (eg. /X /C for CMD.EXE)- Parameters:
shellArgs-
-
getShellArgs
public String[] getShellArgs()
Get the shell arguments- Returns:
- the arguments of the shell.
-
getCommandLine
public List<String> getCommandLine(String executable, String[] arguments)
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
-
getQuotingTriggerChars
protected char[] getQuotingTriggerChars()
-
getExecutionPreamble
protected String 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
protected void setArgumentEscapePattern(String argumentEscapePattern)
-
getArgumentEscapePattern
protected String getArgumentEscapePattern()
-
getShellCommandLine
public List<String> getShellCommandLine(String[] arguments)
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()
-
addShellArg
public void addShellArg(String arg)
-
setQuotedArgumentsEnabled
public void setQuotedArgumentsEnabled(boolean quotedArgumentsEnabled)
-
isQuotedArgumentsEnabled
public boolean isQuotedArgumentsEnabled()
-
setQuotedExecutableEnabled
public void setQuotedExecutableEnabled(boolean quotedExecutableEnabled)
-
isQuotedExecutableEnabled
public boolean isQuotedExecutableEnabled()
-
setExecutable
public void setExecutable(String executable)
Sets the executable to run.
-
getExecutable
public String getExecutable()
-
setWorkingDirectory
public void setWorkingDirectory(String path)
Sets execution directory.
-
setWorkingDirectory
public void setWorkingDirectory(File workingDir)
Sets execution directory.
-
getWorkingDirectory
public File getWorkingDirectory()
-
getWorkingDirectoryAsString
public String getWorkingDirectoryAsString()
-
clearArguments
public void clearArguments()
-
getOriginalExecutable
public String getOriginalExecutable()
-
getOriginalCommandLine
public List<String> getOriginalCommandLine(String executable, String[] arguments)
-
setDoubleQuotedArgumentEscaped
protected void setDoubleQuotedArgumentEscaped(boolean doubleQuotedArgumentEscaped)
-
setDoubleQuotedExecutableEscaped
protected void setDoubleQuotedExecutableEscaped(boolean doubleQuotedExecutableEscaped)
-
setSingleQuotedArgumentEscaped
protected void setSingleQuotedArgumentEscaped(boolean singleQuotedArgumentEscaped)
-
setSingleQuotedExecutableEscaped
protected void setSingleQuotedExecutableEscaped(boolean singleQuotedExecutableEscaped)
-
-