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 subclasses for shells that behave particularly, like
  • command.com
  • cmd.exe
Since:
1.2
Author:
Carlos Sanchez
  • Constructor Details

    • Shell

      public Shell()
  • Method Details

    • setUnconditionalQuoting

      public void setUnconditionalQuoting(boolean unconditionallyQuote)
      Toggle unconditional quoting
      Parameters:
      unconditionallyQuote - see name
    • setShellCommand

      public void setShellCommand(String shellCommand)
      Set the command to execute the shell (eg. COMMAND.COM, /bin/bash,...)
      Parameters:
      shellCommand - see name
    • getShellCommand

      public String getShellCommand()
      Get the command to execute the shell
      Returns:
      the command
    • 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 - see name
    • getShellArgs

      public String[] getShellArgs()
      Returns:
      the shell arguments
    • 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 call
      arguments - arguments for the executable, not the shell
      Returns:
      List with one String object with executable and arguments quoted as needed
    • quoteOneItem

      protected String quoteOneItem(String inputString, boolean isExecutable)
    • getRawCommandLine

      protected List<String> getRawCommandLine(String executable, String[] arguments)
    • 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()
    • getShellArgsList

      public List<String> getShellArgsList()
    • 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)
      Parameters:
      executable - Sets the executable to run.
    • getExecutable

      public String getExecutable()
    • setWorkingDirectory

      public void setWorkingDirectory(String path)
      Parameters:
      path - Sets execution directory.
    • setWorkingDirectory

      public void setWorkingDirectory(File workingDir)
      Parameters:
      workingDir - Sets execution directory.
    • getWorkingDirectory

      public File getWorkingDirectory()
    • getWorkingDirectoryAsString

      public String getWorkingDirectoryAsString()
    • clearArguments

      public void clearArguments()
    • clone

      public Object clone()
      Overrides:
      clone in class Object
    • 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)