Class Commandline
java.lang.Object
org.apache.maven.shared.utils.cli.Commandline
- All Implemented Interfaces:
Cloneable
Commandline objects help handling command lines specifying processes to execute.
The class can be used to define a command line as nested elements or as a helper to define a command line by an application.
<someelement>
<acommandline executable="/executable/to/run">
<argument value="argument 1" />
<argument line="argument_1 argument_2 argument_3" />
<argument value="argument 4" />
</acommandline>
</someelement>
The element someelement
must provide a method
createAcommandline
which returns an instance of this class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A single command line argument -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new command line object.Commandline
(String toProcess) Create a new command line object.Commandline
(Shell shell) Create a new command line object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addArguments
(String... line) void
addEnvironment
(String name, String value) Add an environment variable.void
Add system environment variables.void
Clear out the arguments but leave the executable in place for another operation.clone()
Creates an empty argument object and inserts it at the end of the argument list.createArg
(boolean insertAtStart) Creates an argument object and adds it to the list of args.execute()
Execute the command.String[]
Returns all arguments defined byaddLine
,addValue
or the argument object.String[]
getArguments
(boolean mask) Returns all arguments defined byaddLine
,addValue
, or the argument object.String[]
Returns the executable and all defined arguments.String[]
Return the list of environment variables.getShell()
Get the shell to be used in this command line.private String[]
private String[]
getShellCommandline
(boolean mask) private void
Sets the shell or command-line interpreter for the detected operating system, and the shell arguments.void
setExecutable
(String executable) Sets the executable to run.(package private) void
Set the shell to be used for this command line.void
setWorkingDirectory
(File workingDirectory) Sets working directory.void
setWorkingDirectory
(String path) Sets working directory.toString()
-
Field Details
-
arguments
-
envVars
-
shell
-
-
Constructor Details
-
Commandline
Create a new command line object. Shell is autodetected from operating system.- Parameters:
toProcess
- the command to process- Throws:
CommandLineException
- in case of unbalanced quotes.
-
Commandline
public Commandline()Create a new command line object. Shell is autodetected from operating system.
-
Method Details
-
setDefaultShell
private void setDefaultShell()Sets the shell or command-line interpreter for the detected operating system, and the shell arguments.
-
createArg
Creates an empty argument object and inserts it at the end of the argument list.- Returns:
- the argument object
-
createArg
Creates an argument object and adds it to the list of args.- Parameters:
insertAtStart
- if true, the argument is inserted at the beginning of the list of args. Otherwise it is appended.- Returns:
- the argument
-
setExecutable
Sets the executable to run.- Parameters:
executable
- the executable
-
getExecutable
- Returns:
- the executable
-
addArguments
- Parameters:
line
- the arguments
-
addEnvironment
Add an environment variable.- Parameters:
name
- the name of the environment variablevalue
- the appropriate value
-
addSystemEnvironment
public void addSystemEnvironment()Add system environment variables. -
getEnvironmentVariables
Return the list of environment variables.- Returns:
- an array of all environment variables
-
getCommandline
Returns the executable and all defined arguments.- Returns:
- an array of all arguments including the executable
-
getShellCommandline
- Returns:
- the shell, executable and all defined arguments without masking any arguments
-
getShellCommandline
- Parameters:
mask
- flag to mask any arguments (having hismask
field totrue
)- Returns:
- the shell, executable and all defined arguments with masking some arguments if
mask
parameter is on
-
getArguments
Returns all arguments defined byaddLine
,addValue
or the argument object.- Returns:
- an array of arguments.
-
getArguments
Returns all arguments defined byaddLine
,addValue
, or the argument object.- Parameters:
mask
- flag to mask any arguments (having hismask
field totrue
)- Returns:
- an array of arguments
-
toString
-
clone
-
setWorkingDirectory
Sets working directory.- Parameters:
path
- the working directory
-
setWorkingDirectory
Sets working directory.- Parameters:
workingDirectory
- the working directory
-
getWorkingDirectory
- Returns:
- the working directory
-
clearArgs
public void clearArgs()Clear out the arguments but leave the executable in place for another operation. -
execute
Execute the command.- Returns:
- the process
- Throws:
CommandLineException
- in case of errors
-
getShell
Get the shell to be used in this command line.- Returns:
- the shell
-