public class Commandline
extends java.lang.Object
implements java.lang.Cloneable
<someelement>
The element
<acommandline executable="/executable/to/run">
<argument value="argument 1" />
<argument line="argument_1 argument_2 argument_3" />
<argument value="argument 4" />
</acommandline>
</someelement>
someelement
must provide a method
createAcommandline
which returns an instance of this class.
Modifier and Type | Class and Description |
---|---|
static class |
Commandline.Argument
Used for nested xml command line definitions.
|
class |
Commandline.Marker
Class to keep track of the position of an Argument.
|
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
DISCLAIMER |
Constructor and Description |
---|
Commandline()
Create an empty command line.
|
Commandline(java.lang.String toProcess)
Create a command line from a string.
|
Modifier and Type | Method and Description |
---|---|
void |
addArguments(java.lang.String[] line)
Append the arguments to the existing command.
|
void |
addArgumentsToList(java.util.ListIterator list)
Append all the arguments to the tail of a supplied list.
|
void |
addCommandToList(java.util.ListIterator list)
Add the entire command, including (optional) executable to a list.
|
void |
clear()
Clear out the whole command line.
|
void |
clearArgs()
Clear out the arguments but leave the executable in place for
another operation.
|
java.lang.Object |
clone()
Generate a deep clone of the contained object.
|
Commandline.Argument |
createArgument()
Create an argument object.
|
Commandline.Argument |
createArgument(boolean insertAtStart)
Create an argument object and add it to our list of args.
|
Commandline.Marker |
createMarker()
Return a marker.
|
java.lang.String |
describeArguments()
Return a String that describes the arguments suitable for
verbose output before a call to
Runtime.exec(String[]) |
static java.lang.String |
describeArguments(Commandline line)
Return a String that describes the arguments suitable for
verbose output before a call to
Runtime.exec(String[]) |
static java.lang.String |
describeArguments(java.lang.String[] args)
Return a String that describes the arguments suitable for
verbose output before a call to
Runtime.exec(String[]) |
protected static java.lang.String |
describeArguments(java.lang.String[] args,
int offset)
Return a String that describes the arguments suitable for
verbose output before a call to
Runtime.exec(String[]) |
java.lang.String |
describeCommand()
Return a String that describes the command and arguments suitable for
verbose output before a call to
Runtime.exec(String[]) |
static java.lang.String |
describeCommand(Commandline line)
Return a String that describes the command and arguments suitable for
verbose output before a call to
Runtime.exec(String[]) |
static java.lang.String |
describeCommand(java.lang.String[] args)
Return a String that describes the command and arguments suitable for
verbose output before a call to
Runtime.exec(String[]) |
java.lang.String[] |
getArguments()
Returns all arguments defined by
addLine ,
addValue or the argument object. |
java.lang.String[] |
getCommandline()
Return the executable and all defined arguments.
|
java.lang.String |
getExecutable()
Get the executable.
|
java.util.Iterator |
iterator()
Get an iterator to the arguments list.
|
static java.lang.String |
quoteArgument(java.lang.String argument)
Put quotes around the given String if necessary.
|
void |
setExecutable(java.lang.String executable)
Set the executable to run.
|
int |
size()
Size operator.
|
java.lang.String |
toString()
Return the command line as a string.
|
static java.lang.String |
toString(java.lang.String[] line)
Quote the parts of the given array in way that makes them
usable as command line arguments.
|
static java.lang.String[] |
translateCommandline(java.lang.String toProcess)
Crack a command line.
|
public Commandline(java.lang.String toProcess)
toProcess
- the line: the first element becomes the executable, the rest
the arguments.public Commandline()
public Commandline.Argument createArgument()
Each commandline object has at most one instance of the
argument class. This method calls
this.createArgument(false)
.
createArgument(boolean)
public Commandline.Argument createArgument(boolean insertAtStart)
Each commandline object has at most one instance of the argument class.
insertAtStart
- if true, the argument is inserted at the
beginning of the list of args, otherwise it is appended.public void setExecutable(java.lang.String executable)
executable
- the String executable name.public java.lang.String getExecutable()
public void addArguments(java.lang.String[] line)
line
- an array of arguments to append.public java.lang.String[] getCommandline()
public void addCommandToList(java.util.ListIterator list)
list
- the list to add to.public java.lang.String[] getArguments()
addLine
,
addValue
or the argument object.public void addArgumentsToList(java.util.ListIterator list)
list
- the list of arguments.public java.lang.String toString()
toString
in class java.lang.Object
public static java.lang.String quoteArgument(java.lang.String argument)
If the argument doesn't include spaces or quotes, return it as is. If it contains double quotes, use single quotes - else surround the argument by double quotes.
argument
- the argument to quote if necessary.BuildException
- if the argument contains both, single
and double quotes.public static java.lang.String toString(java.lang.String[] line)
line
- the list of arguments to quote.public static java.lang.String[] translateCommandline(java.lang.String toProcess)
toProcess
- the command line to process.public int size()
public java.lang.Object clone()
clone
in class java.lang.Object
public void clear()
public void clearArgs()
public Commandline.Marker createMarker()
This marker can be used to locate a position on the commandline--to insert something for example--when all parameters have been set.
public java.lang.String describeCommand()
Runtime.exec(String[]).
public java.lang.String describeArguments()
Runtime.exec(String[]).
public static java.lang.String describeCommand(Commandline line)
Runtime.exec(String[]).
line
- the Commandline to describe.public static java.lang.String describeArguments(Commandline line)
Runtime.exec(String[]).
line
- the Commandline whose arguments to describe.public static java.lang.String describeCommand(java.lang.String[] args)
Runtime.exec(String[]).
This method assumes that the first entry in the array is the
executable to run.
args
- the command line to describe as an array of stringspublic static java.lang.String describeArguments(java.lang.String[] args)
Runtime.exec(String[]).
args
- the command line to describe as an array of strings.protected static java.lang.String describeArguments(java.lang.String[] args, int offset)
Runtime.exec(String[]).
args
- the command line to describe as an array of strings.offset
- ignore entries before this index.public java.util.Iterator iterator()