org.codehaus.plexus.util.cli.shell
Class Shell

java.lang.Object
  extended by 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

Since:
1.2
Version:
$Id: Shell.java 8010 2009-01-07 12:59:50Z vsiveton $
Author:
Carlos Sanchez

Constructor Summary
Shell()
           
 
Method Summary
 void addShellArg(String arg)
           
 void clearArguments()
           
 Object clone()
           
protected  char getArgumentQuoteDelimiter()
           
 List getCommandLine(String executable, String[] arguments)
          Get the command line for the provided executable and arguments in this shell
protected  char[] getEscapeChars(boolean includeSingleQuote, boolean includeDoubleQuote)
           
 String getExecutable()
           
protected  char getExecutableQuoteDelimiter()
           
protected  String getExecutionPreamble()
           
 List getOriginalCommandLine(String executable, String[] arguments)
           
 String getOriginalExecutable()
           
protected  char[] getQuotingTriggerChars()
           
protected  List getRawCommandLine(String executable, String[] arguments)
           
 String[] getShellArgs()
          Get the shell arguments
 List getShellArgsList()
           
 String getShellCommand()
          Get the command to execute the shell
 List getShellCommandLine(String[] arguments)
          Get the full command line to execute, including shell command, shell arguments, executable and executable arguments
 File getWorkingDirectory()
           
 String getWorkingDirectoryAsString()
           
protected  boolean isDoubleQuotedArgumentEscaped()
           
protected  boolean isDoubleQuotedExecutableEscaped()
           
 boolean isQuotedArgumentsEnabled()
           
 boolean isQuotedExecutableEnabled()
           
protected  boolean isSingleQuotedArgumentEscaped()
           
protected  boolean isSingleQuotedExecutableEscaped()
           
protected  void setArgumentQuoteDelimiter(char argQuoteDelimiter)
           
protected  void setDoubleQuotedArgumentEscaped(boolean doubleQuotedArgumentEscaped)
           
protected  void setDoubleQuotedExecutableEscaped(boolean doubleQuotedExecutableEscaped)
           
 void setExecutable(String executable)
          Sets the executable to run.
protected  void setExecutableQuoteDelimiter(char exeQuoteDelimiter)
           
 void setQuotedArgumentsEnabled(boolean quotedArgumentsEnabled)
           
 void setQuotedExecutableEnabled(boolean quotedExecutableEnabled)
           
 void setShellArgs(String[] shellArgs)
          Set the shell arguments when calling a command line (not the executable arguments) (eg.
 void setShellCommand(String shellCommand)
          Set the command to execute the shell (eg.
protected  void setSingleQuotedArgumentEscaped(boolean singleQuotedArgumentEscaped)
           
protected  void setSingleQuotedExecutableEscaped(boolean singleQuotedExecutableEscaped)
           
 void setWorkingDirectory(File workingDir)
          Sets execution directory.
 void setWorkingDirectory(String path)
          Sets execution directory.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Shell

public Shell()
Method Detail

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:

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:

getCommandLine

public List 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

getRawCommandLine

protected List 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()

getShellCommandLine

public List 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 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)
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()

clone

public Object clone()
Overrides:
clone in class Object

getOriginalExecutable

public String getOriginalExecutable()

getOriginalCommandLine

public List 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)


Copyright © 2001-2009 Codehaus. All Rights Reserved.