Top Description Inners Fields Constructors Methods
org.apache.tools.ant.types

public Class Commandline

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Imports
java.io.File, java.util.ArrayList, .Iterator, .LinkedList, .List, .ListIterator, .StringTokenizer, java.util.stream.Stream, org.apache.tools.ant.BuildException, .ProjectComponent, org.apache.tools.ant.taskdefs.condition.Os

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 and Inner Type Summary

Modifier and TypeClass and Description
public static class
Commandline.Argument

Used for nested xml command line definitions.

public class
Commandline.Marker

Class to keep track of the position of an Argument.

Field Summary

Modifier and TypeField and Description
private List<Commandline.Argument>
arguments

The arguments of the command

protected static final String
private String
executable

the program to execute

private static final boolean
IS_WIN_9X

win9x uses a (shudder) bat file (antRun.bat) for executing commands

Constructor Summary

AccessConstructor and Description
public
Commandline(String
the line: the first element becomes the executable, the rest the arguments.
toProcess
)

Create a command line from a string.

public
Commandline()

Create an empty command line.

Method Summary

Modifier and TypeMethod and Description
public void
addArguments(String[]
an array of arguments to append.
line
)

Append the arguments to the existing command.

public void
addArgumentsToList(ListIterator<String>
the list of arguments.
list
)

Append all the arguments to the tail of a supplied list.

public void
addCommandToList(ListIterator<String>
the list to add to.
list
)

Add the entire command, including (optional) executable to a list.

public void
clear()

Clear out the whole command line.

public void
clearArgs()

Clear out the arguments but leave the executable in place for another operation.

public Object

Returns:

a clone of the contained object
clone
()

Overrides java.lang.Object.clone.

Generate a deep clone of the contained object.
public Commandline.Argument

Returns:

the argument object.
createArgument
()

Create an argument object.

public Commandline.Argument

Returns:

an argument to be configured
createArgument
(boolean
if true, the argument is inserted at the beginning of the list of args, otherwise it is appended.
insertAtStart
)

Create an argument object and add it to our list of args.

public Commandline.Marker

Returns:

a marker
createMarker
()

Return a marker.

public String

Returns:

a string that describes the arguments.
describeArguments
()

Return a String that describes the arguments suitable for verbose output before a call to Runtime.exec(String[]).

public static String

Returns:

a string that describes the arguments.
describeArguments
(Commandline
the Commandline whose arguments to describe.
line
)

Return a String that describes the arguments suitable for verbose output before a call to Runtime.exec(String[]).

public static String

Returns:

a string that describes the arguments.
describeArguments
(String[]
the command line to describe as an array of strings.
args
)

Return a String that describes the arguments suitable for verbose output before a call to Runtime.exec(String[]).

protected static String

Returns:

a string that describes the arguments
describeArguments
(String[]
the command line to describe as an array of strings.
args
,
int
ignore entries before this index.
offset
)

Return a String that describes the arguments suitable for verbose output before a call to Runtime.exec(String[]).

public String

Returns:

a string that describes the command and arguments.
describeCommand
()

Return a String that describes the command and arguments suitable for verbose output before a call to Runtime.exec(String[]).

public static String

Returns:

a string that describes the command and arguments.
describeCommand
(Commandline
the Commandline to describe.
line
)

Return a String that describes the command and arguments suitable for verbose output before a call to Runtime.exec(String[]).

public static String

Returns:

a string that describes the command and arguments.
describeCommand
(String[]
the command line to describe as an array of strings
args
)

Return a String that describes the command and arguments suitable for verbose output before a call to Runtime.exec(String[]).

public String[]

Returns:

the arguments as an array of strings.
getArguments
()

Returns all arguments defined by addLine, addValue or the argument object.

public String[]

Returns:

the commandline as an array of strings.
getCommandline
()

Return the executable and all defined arguments.

public String

Returns:

the program to run--null if not yet set.
getExecutable
()

Get the executable.

public Iterator<Commandline.Argument>

Returns:

an Iterator.
iterator
()

Get an iterator to the arguments list.

public static String

Returns:

the quoted argument.
quoteArgument
(String
the argument to quote if necessary.
argument
)

Put quotes around the given String if necessary.

public void
setExecutable(String
the String executable name.
executable
)

Set the executable to run.

public void
setExecutable(String
the String executable name.
executable
,
boolean
if true all file separators in the string are converted to the platform specific value.
translateFileSeparator
)

Set the executable to run.

public int

Returns:

number of elements in the command, including the executable.
size
()

Size operator.

public String

Returns:

the command line.
toString
()

Overrides java.lang.Object.toString.

Return the command line as a string.
public static String

Returns:

empty string for null or no command, else every argument split by spaces and quoted by quoting rules.
toString
(String[]
the list of arguments to quote.
line
)

Quote the parts of the given array in way that makes them usable as command line arguments.

public static String[]

Returns:

the command line broken into strings. An empty or null toProcess parameter results in a zero sized array.
translateCommandline
(String
the command line to process.
toProcess
)

Crack a command line.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

argumentsback to summary
private List<Commandline.Argument> arguments

The arguments of the command

DISCLAIMERback to summary
protected static final String DISCLAIMER
executableback to summary
private String executable

the program to execute

IS_WIN_9Xback to summary
private static final boolean IS_WIN_9X

win9x uses a (shudder) bat file (antRun.bat) for executing commands

Constructor Detail

Commandlineback to summary
public Commandline(String toProcess)

Create a command line from a string.

Parameters
toProcess:String

the line: the first element becomes the executable, the rest the arguments.

Commandlineback to summary
public Commandline()

Create an empty command line.

Method Detail

addArgumentsback to summary
public void addArguments(String[] line)

Append the arguments to the existing command.

Parameters
line:String[]

an array of arguments to append.

addArgumentsToListback to summary
public void addArgumentsToList(ListIterator<String> list)

Append all the arguments to the tail of a supplied list.

Parameters
list:ListIterator<String>

the list of arguments.

Since
Ant 1.6
addCommandToListback to summary
public void addCommandToList(ListIterator<String> list)

Add the entire command, including (optional) executable to a list.

Parameters
list:ListIterator<String>

the list to add to.

Since
Ant 1.6
clearback to summary
public void clear()

Clear out the whole command line.

clearArgsback to summary
public void clearArgs()

Clear out the arguments but leave the executable in place for another operation.

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Generate a deep clone of the contained object.

Returns:Object

a clone of the contained object

Annotations
@Override
createArgumentback to summary
public Commandline.Argument createArgument()

Create an argument object.

Each commandline object has at most one instance of the argument class. This method calls this.createArgument(false).

Returns:Commandline.Argument

the argument object.

See Also
createArgument(boolean)
createArgumentback to summary
public Commandline.Argument createArgument(boolean insertAtStart)

Create 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:boolean

if true, the argument is inserted at the beginning of the list of args, otherwise it is appended.

Returns:Commandline.Argument

an argument to be configured

createMarkerback to summary
public Commandline.Marker 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.

Returns:Commandline.Marker

a marker

describeArgumentsback to summary
public String describeArguments()

Return a String that describes the arguments suitable for verbose output before a call to Runtime.exec(String[]).

Returns:String

a string that describes the arguments.

Since
Ant 1.5
describeArgumentsback to summary
public static String describeArguments(Commandline line)

Return a String that describes the arguments suitable for verbose output before a call to Runtime.exec(String[]).

Parameters
line:Commandline

the Commandline whose arguments to describe.

Returns:String

a string that describes the arguments.

Since
Ant 1.5
describeArgumentsback to summary
public static String describeArguments(String[] args)

Return a String that describes the arguments suitable for verbose output before a call to Runtime.exec(String[]).

Parameters
args:String[]

the command line to describe as an array of strings.

Returns:String

a string that describes the arguments.

Since
Ant 1.5
describeArgumentsback to summary
protected static String describeArguments(String[] args, int offset)

Return a String that describes the arguments suitable for verbose output before a call to Runtime.exec(String[]).

Parameters
args:String[]

the command line to describe as an array of strings.

offset:int

ignore entries before this index.

Returns:String

a string that describes the arguments

Since
Ant 1.5
describeCommandback to summary
public String describeCommand()

Return a String that describes the command and arguments suitable for verbose output before a call to Runtime.exec(String[]).

Returns:String

a string that describes the command and arguments.

Since
Ant 1.5
describeCommandback to summary
public static String describeCommand(Commandline line)

Return a String that describes the command and arguments suitable for verbose output before a call to Runtime.exec(String[]).

Parameters
line:Commandline

the Commandline to describe.

Returns:String

a string that describes the command and arguments.

Since
Ant 1.5
describeCommandback to summary
public static String describeCommand(String[] args)

Return a String that describes the command and arguments suitable for verbose output before a call to Runtime.exec(String[]).

This method assumes that the first entry in the array is the executable to run.

Parameters
args:String[]

the command line to describe as an array of strings

Returns:String

a string that describes the command and arguments.

Since
Ant 1.5
getArgumentsback to summary
public String[] getArguments()

Returns all arguments defined by addLine, addValue or the argument object.

Returns:String[]

the arguments as an array of strings.

getCommandlineback to summary
public String[] getCommandline()

Return the executable and all defined arguments.

Returns:String[]

the commandline as an array of strings.

getExecutableback to summary
public String getExecutable()

Get the executable.

Returns:String

the program to run--null if not yet set.

iteratorback to summary
public Iterator<Commandline.Argument> iterator()

Get an iterator to the arguments list.

Returns:Iterator<Commandline.Argument>

an Iterator.

Since
Ant 1.7
quoteArgumentback to summary
public static String quoteArgument(String argument)

Put 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:String

the argument to quote if necessary.

Returns:String

the quoted argument.

Exceptions
BuildException:
if the argument contains both, single and double quotes.
setExecutableback to summary
public void setExecutable(String executable)

Set the executable to run. All file separators in the string are converted to the platform specific value.

Parameters
executable:String

the String executable name.

setExecutableback to summary
public void setExecutable(String executable, boolean translateFileSeparator)

Set the executable to run.

Parameters
executable:String

the String executable name.

translateFileSeparator:boolean

if true all file separators in the string are converted to the platform specific value.

Since
Ant 1.9.7
sizeback to summary
public int size()

Size operator. This actually creates the command line, so it is not a zero cost operation.

Returns:int

number of elements in the command, including the executable.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return the command line as a string.

Returns:String

the command line.

Annotations
@Override
toStringback to summary
public static String toString(String[] line)

Quote the parts of the given array in way that makes them usable as command line arguments.

Parameters
line:String[]

the list of arguments to quote.

Returns:String

empty string for null or no command, else every argument split by spaces and quoted by quoting rules.

translateCommandlineback to summary
public static String[] translateCommandline(String toProcess)

Crack a command line.

Parameters
toProcess:String

the command line to process.

Returns:String[]

the command line broken into strings. An empty or null toProcess parameter results in a zero sized array.

org.apache.tools.ant.types back to summary

public Class Commandline.Argument

extends ProjectComponent
Class Inheritance
Known Direct Subclasses
org.apache.tools.ant.util.facade.ImplementationSpecificArgument

Used for nested xml command line definitions.

Field Summary

Modifier and TypeField and Description
private String[]
private String
private String
Inherited from org.apache.tools.ant.ProjectComponent:
descriptionlocationproject

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
copyFrom(Commandline.Argument
the argument to copy setting from
other
)

Copies settings from a different argument.

public String[]

Returns:

an array of strings.
getParts
()

Return the constituent parts of this Argument.

public void
setFile(File
a single commandline argument.
value
)

Set a single commandline argument to the absolute filename of the given file.

public void
setLine(String
line to split into several commandline arguments.
line
)

Set the line to split into several commandline arguments.

public void
setPath(Path
a single commandline argument.
value
)

Set a single commandline argument and treats it like a PATH--ensuring the right separator for the local platform is used.

public void
setPathref(Reference
a single commandline argument.
value
)

Set a single commandline argument from a reference to a path--ensuring the right separator for the local platform is used.

public void
setPrefix(String
fixed prefix string.
prefix
)

Set the prefix to be placed in front of every part of the argument.

public void
setSuffix(String
fixed suffix string.
suffix
)

Set the suffix to be placed at the end of every part of the argument.

public void
setValue(String
a single commandline argument.
value
)

Set a single commandline argument.

Inherited from org.apache.tools.ant.ProjectComponent:
clonegetDescriptiongetLocationgetProjectloglogsetDescriptionsetLocationsetProject

Field Detail

partsback to summary
private String[] parts
prefixback to summary
private String prefix
suffixback to summary
private String suffix

Constructor Detail

Argumentback to summary
public Argument()

Method Detail

copyFromback to summary
public void copyFrom(Commandline.Argument other)

Copies settings from a different argument.

Parameters
other:Commandline.Argument

the argument to copy setting from

Since
Ant 1.10.6
getPartsback to summary
public String[] getParts()

Return the constituent parts of this Argument.

Returns:String[]

an array of strings.

setFileback to summary
public void setFile(File value)

Set a single commandline argument to the absolute filename of the given file.

Parameters
value:File

a single commandline argument.

setLineback to summary
public void setLine(String line)

Set the line to split into several commandline arguments.

Parameters
line:String

line to split into several commandline arguments.

setPathback to summary
public void setPath(Path value)

Set a single commandline argument and treats it like a PATH--ensuring the right separator for the local platform is used.

Parameters
value:Path

a single commandline argument.

setPathrefback to summary
public void setPathref(Reference value)

Set a single commandline argument from a reference to a path--ensuring the right separator for the local platform is used.

Parameters
value:Reference

a single commandline argument.

setPrefixback to summary
public void setPrefix(String prefix)

Set the prefix to be placed in front of every part of the argument.

Parameters
prefix:String

fixed prefix string.

Since
Ant 1.8.0
setSuffixback to summary
public void setSuffix(String suffix)

Set the suffix to be placed at the end of every part of the argument.

Parameters
suffix:String

fixed suffix string.

Since
Ant 1.8.0
setValueback to summary
public void setValue(String value)

Set a single commandline argument.

Parameters
value:String

a single commandline argument.

org.apache.tools.ant.types back to summary

public Class Commandline.Marker

extends Object
Class Inheritance

Class to keep track of the position of an Argument.

This class is there to support the srcfile and targetfile elements of <apply>.

Field Summary

Modifier and TypeField and Description
private int
private String
private int
private String

Constructor Summary

AccessConstructor and Description
pack-priv
Marker(int
the position to mark.
position
)

Construct a marker for the specified position.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the position of this marker.
getPosition
()

Return the number of arguments that preceded this marker.

public String

Returns:

String
getPrefix
()

Get the prefix to be placed in front of the inserted argument.

public String

Returns:

String
getSuffix
()

Get the suffix to be placed at the end of the inserted argument.

public void
setPrefix(String
fixed prefix string.
prefix
)

Set the prefix to be placed in front of the inserted argument.

public void
setSuffix(String
fixed suffix string.
suffix
)

Set the suffix to be placed at the end of the inserted argument.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

positionback to summary
private int position
prefixback to summary
private String prefix
realPosback to summary
private int realPos
suffixback to summary
private String suffix

Constructor Detail

Markerback to summary
pack-priv Marker(int position)

Construct a marker for the specified position.

Parameters
position:int

the position to mark.

Method Detail

getPositionback to summary
public int getPosition()

Return the number of arguments that preceded this marker.

The name of the executable -- if set -- is counted as the first argument.

Returns:int

the position of this marker.

getPrefixback to summary
public String getPrefix()

Get the prefix to be placed in front of the inserted argument.

Returns:String

String

Since
Ant 1.8.0
getSuffixback to summary
public String getSuffix()

Get the suffix to be placed at the end of the inserted argument.

Returns:String

String

Since
Ant 1.8.0
setPrefixback to summary
public void setPrefix(String prefix)

Set the prefix to be placed in front of the inserted argument.

Parameters
prefix:String

fixed prefix string.

Since
Ant 1.8.0
setSuffixback to summary
public void setSuffix(String suffix)

Set the suffix to be placed at the end of the inserted argument.

Parameters
suffix:String

fixed suffix string.

Since
Ant 1.8.0