Package org.apache.tools.ant.types
Class Commandline
java.lang.Object
org.apache.tools.ant.types.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 SummaryNested ClassesModifier and TypeClassDescriptionstatic classUsed for nested xml command line definitions.classClass to keep track of the position of an Argument.
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionCreate an empty command line.Commandline(String toProcess) Create a command line from a string.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddArguments(String[] line) Append the arguments to the existing command.voidaddArgumentsToList(ListIterator<String> list) Append all the arguments to the tail of a supplied list.voidaddCommandToList(ListIterator<String> list) Add the entire command, including (optional) executable to a list.voidclear()Clear out the whole command line.voidClear out the arguments but leave the executable in place for another operation.clone()Generate a deep clone of the contained object.Create an argument object.createArgument(boolean insertAtStart) Create an argument object and add it to our list of args.Return a marker.Return a String that describes the arguments suitable for verbose output before a call toRuntime.exec(String[]).static StringdescribeArguments(String[] args) Return a String that describes the arguments suitable for verbose output before a call toRuntime.exec(String[]).protected static StringdescribeArguments(String[] args, int offset) Return a String that describes the arguments suitable for verbose output before a call toRuntime.exec(String[]).static StringdescribeArguments(Commandline line) Return a String that describes the arguments suitable for verbose output before a call toRuntime.exec(String[]).Return a String that describes the command and arguments suitable for verbose output before a call toRuntime.exec(String[]).static StringdescribeCommand(String[] args) Return a String that describes the command and arguments suitable for verbose output before a call toRuntime.exec(String[]).static StringdescribeCommand(Commandline line) Return a String that describes the command and arguments suitable for verbose output before a call toRuntime.exec(String[]).String[]Returns all arguments defined byaddLine,addValueor the argument object.String[]Return the executable and all defined arguments.Get the executable.iterator()Get an iterator to the arguments list.static StringquoteArgument(String argument) Put quotes around the given String if necessary.voidsetExecutable(String executable) Set the executable to run.voidsetExecutable(String executable, boolean translateFileSeparator) Set the executable to run.intsize()Size operator.toString()Return the command line as a string.static StringQuote the parts of the given array in way that makes them usable as command line arguments.static String[]translateCommandline(String toProcess) Crack a command line.
- 
Field Details- 
DISCLAIMER
 
- 
- 
Constructor Details- 
CommandlineCreate a command line from a string.- Parameters:
- toProcess- the line: the first element becomes the executable, the rest the arguments.
 
- 
Commandlinepublic Commandline()Create an empty command line.
 
- 
- 
Method Details- 
createArgumentCreate 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:
 
- 
createArgumentCreate an argument object and add 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.
- Returns:
- an argument to be configured
 
- 
setExecutableSet the executable to run. All file separators in the string are converted to the platform specific value.- Parameters:
- executable- the String executable name.
 
- 
setExecutableSet the executable to run.- Parameters:
- executable- the String executable name.
- translateFileSeparator- if- trueall file separators in the string are converted to the platform specific value.
- Since:
- Ant 1.9.7
 
- 
getExecutableGet the executable.- Returns:
- the program to run--null if not yet set.
 
- 
addArgumentsAppend the arguments to the existing command.- Parameters:
- line- an array of arguments to append.
 
- 
getCommandlineReturn the executable and all defined arguments.- Returns:
- the commandline as an array of strings.
 
- 
addCommandToListAdd the entire command, including (optional) executable to a list.- Parameters:
- list- the list to add to.
- Since:
- Ant 1.6
 
- 
getArgumentsReturns all arguments defined byaddLine,addValueor the argument object.- Returns:
- the arguments as an array of strings.
 
- 
addArgumentsToListAppend all the arguments to the tail of a supplied list.- Parameters:
- list- the list of arguments.
- Since:
- Ant 1.6
 
- 
toStringReturn the command line as a string.
- 
quoteArgumentPut quotes around the given String if necessary.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. - Parameters:
- argument- the argument to quote if necessary.
- Returns:
- the quoted argument.
- Throws:
- BuildException- if the argument contains both, single and double quotes.
 
- 
toStringQuote the parts of the given array in way that makes them usable as command line arguments.- Parameters:
- line- the list of arguments to quote.
- Returns:
- empty string for null or no command, else every argument split by spaces and quoted by quoting rules.
 
- 
translateCommandlineCrack a command line.- Parameters:
- toProcess- the command line to process.
- Returns:
- the command line broken into strings. An empty or null toProcess parameter results in a zero sized array.
 
- 
sizepublic int size()Size operator. This actually creates the command line, so it is not a zero cost operation.- Returns:
- number of elements in the command, including the executable.
 
- 
cloneGenerate a deep clone of the contained object.
- 
clearpublic void clear()Clear out the whole command line.
- 
clearArgspublic void clearArgs()Clear out the arguments but leave the executable in place for another operation.
- 
createMarkerReturn 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. - Returns:
- a marker
 
- 
describeCommandReturn a String that describes the command and arguments suitable for verbose output before a call toRuntime.exec(String[]).- Returns:
- a string that describes the command and arguments.
- Since:
- Ant 1.5
 
- 
describeArgumentsReturn a String that describes the arguments suitable for verbose output before a call toRuntime.exec(String[]).- Returns:
- a string that describes the arguments.
- Since:
- Ant 1.5
 
- 
describeCommandReturn a String that describes the command and arguments suitable for verbose output before a call toRuntime.exec(String[]).- Parameters:
- line- the Commandline to describe.
- Returns:
- a string that describes the command and arguments.
- Since:
- Ant 1.5
 
- 
describeArgumentsReturn a String that describes the arguments suitable for verbose output before a call toRuntime.exec(String[]).- Parameters:
- line- the Commandline whose arguments to describe.
- Returns:
- a string that describes the arguments.
- Since:
- Ant 1.5
 
- 
describeCommandReturn a String that describes the command and arguments suitable for verbose output before a call toRuntime.exec(String[]).This method assumes that the first entry in the array is the executable to run. - Parameters:
- args- the command line to describe as an array of strings
- Returns:
- a string that describes the command and arguments.
- Since:
- Ant 1.5
 
- 
describeArgumentsReturn a String that describes the arguments suitable for verbose output before a call toRuntime.exec(String[]).- Parameters:
- args- the command line to describe as an array of strings.
- Returns:
- a string that describes the arguments.
- Since:
- Ant 1.5
 
- 
describeArgumentsReturn a String that describes the arguments suitable for verbose output before a call toRuntime.exec(String[]).- Parameters:
- args- the command line to describe as an array of strings.
- offset- ignore entries before this index.
- Returns:
- a string that describes the arguments
- Since:
- Ant 1.5
 
- 
iteratorGet an iterator to the arguments list.- Returns:
- an Iterator.
- Since:
- Ant 1.7
 
 
-