Class 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 classclassClass to keep track of the position of an Argument. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringDeprecated.protected static final StringDeprecated.UseOsclass instead.private longprivate Shellprotected static final StringDeprecated.UseOsclass instead.private FileDeprecated.UsesetWorkingDirectory(File)orsetWorkingDirectory(String)instead. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new command line object.Commandline(String toProcess) Create a new command line object, given a command following POSIX sh quoting rulesCommandline(String toProcess, Shell shell) Create a new command line object.Commandline(Shell shell) Create a new command line object. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an argument object to our list of args.voidAdds an argument object to our list of args.voidaddArguments(String[] line) voidaddEnvironment(String name, String value) Add an environment variablevoidAdd system environment variablesvoidclear()Clear out the whole command line.voidClear out the arguments but leave the executable in place for another operation.clone()Creates an argument object.createArg(boolean insertAtStart) Creates an argument object and adds it to our list of args.Deprecated.UsecreateArg()insteadcreateArgument(boolean insertAtStart) Deprecated.UsecreateArg(boolean)insteadReturn a marker.execute()Executes the command.String[]Returns all arguments defined byaddLine,addValueor the argument object.String[]Returns the executable and all defined arguments.
For Windows Family,getShellCommandline()is returnedString[]Return the list of environment variablesReturn an executable name, quoted for shell use.longgetPid()String[]Returns the executable and all defined arguments.getShell()Get the shell to be used in this command line.String[]Returns the shell, executable and all defined arguments.static StringquoteArgument(String argument) Deprecated.UseCommandLineUtils.quote(String)instead.private voidSets the shell or command-line interpreter for the detected operating system, and the shell arguments.voidsetExecutable(String executable) Sets the executable to run.voidsetPid(long pid) voidAllows to set the shell to be used in this command line.voidsetWorkingDirectory(File workingDirectory) Sets execution directory.voidsetWorkingDirectory(String path) Sets execution directory.intsize()toString()static StringDeprecated.UseCommandLineUtils.toString(String[])instead.static String[]translateCommandline(String toProcess) Deprecated.UseCommandLineUtils.translateCommandline(String)instead.private voidDeprecated.Remove once backward compat with plexus-utils <= 1.4 is no longer a consideration
-
Field Details
-
OS_NAME
Deprecated.UseOsclass instead.- See Also:
-
WINDOWS
Deprecated.UseOsclass instead.- See Also:
-
arguments
-
envVars
-
pid
private long pid -
shell
-
executable
Deprecated.UsesetExecutable(String)instead. -
workingDir
Deprecated.UsesetWorkingDirectory(File)orsetWorkingDirectory(String)instead.
-
-
Constructor Details
-
Commandline
Create a new command line object. Shell is autodetected from operating system Shell usage is only desirable when generating code for remote execution.- Parameters:
toProcess-
-
Commandline
Create a new command line object. Shell is autodetected from operating system Shell usage is only desirable when generating code for remote execution. -
Commandline
Create a new command line object, given a command following POSIX sh quoting rules- Parameters:
toProcess-
-
Commandline
public Commandline()Create a new command line object.
-
-
Method Details
-
getPid
public long getPid() -
setPid
public void setPid(long pid) -
setDefaultShell
private void setDefaultShell()Sets the shell or command-line interpreter for the detected operating system, and the shell arguments.
-
createArgument
Deprecated.UsecreateArg()insteadCreates an argument object.
Each commandline object has at most one instance of the argument class. This method calls
this.createArgument(false).- Returns:
- the argument object.
- See Also:
-
createArgument
Deprecated.UsecreateArg(boolean)insteadCreates an argument object and adds it to our list of args.
Each commandline object has at most one instance of the argument class.
- Parameters:
insertAtStart- if true, the argument is inserted at the beginning of the list of args, otherwise it is appended.
-
createArg
Creates an argument object.
Each commandline object has at most one instance of the argument class. This method calls
this.createArgument(false).- Returns:
- the argument object.
- See Also:
-
createArg
Creates an argument object and adds it to our list of args.
Each commandline object has at most one instance of the argument class.
- Parameters:
insertAtStart- if true, the argument is inserted at the beginning of the list of args, otherwise it is appended.
-
addArg
Adds an argument object to our list of args.- See Also:
-
addArg
Adds an argument object to our list of args.- Parameters:
insertAtStart- if true, the argument is inserted at the beginning of the list of args, otherwise it is appended.
-
setExecutable
Sets the executable to run. -
getLiteralExecutable
- Returns:
- Executable to be run, as a literal string (no shell quoting/munging)
-
getExecutable
Return an executable name, quoted for shell use. Shell usage is only desirable when generating code for remote execution.- Returns:
- Executable to be run, quoted for shell interpretation
-
addArguments
-
addEnvironment
Add an environment variable -
addSystemEnvironment
Add system environment variables- Throws:
Exception
-
getEnvironmentVariables
Return the list of environment variables- Throws:
CommandLineException
-
getCommandline
Returns the executable and all defined arguments.
For Windows Family,getShellCommandline()is returned -
getRawCommandline
Returns the executable and all defined arguments. -
getShellCommandline
Returns the shell, executable and all defined arguments. Shell usage is only desirable when generating code for remote execution. -
getArguments
Returns all arguments defined byaddLine,addValueor the argument object. -
toString
-
size
public int size() -
clone
-
clear
public void clear()Clear out the whole command line. -
clearArgs
public void clearArgs()Clear out the arguments but leave the executable in place for another operation. -
createMarker
Return a marker.
This marker can be used to locate a position on the commandline - to insert something for example - when all parameters have been set.
-
setWorkingDirectory
Sets execution directory. -
setWorkingDirectory
Sets execution directory. -
getWorkingDirectory
-
execute
Executes the command.- Throws:
CommandLineException
-
verifyShellState
private void verifyShellState()Deprecated.Remove once backward compat with plexus-utils <= 1.4 is no longer a consideration -
getSystemEnvVars
- Throws:
Exception
-
setShell
Allows to set the shell to be used in this command line. Shell usage is only desirable when generating code for remote execution.- Parameters:
shell-- Since:
- 1.2
-
getShell
Get the shell to be used in this command line. Shell usage is only desirable when generating code for remote execution.- Since:
- 1.2
-
translateCommandline
Deprecated.UseCommandLineUtils.translateCommandline(String)instead.- Throws:
Exception
-
quoteArgument
Deprecated.UseCommandLineUtils.quote(String)instead.- Throws:
CommandLineException
-
toString
Deprecated.UseCommandLineUtils.toString(String[])instead.
-
setExecutable(String)instead.