org.apache.tools.ant.types
Class Commandline

java.lang.Object
  |
  +--org.apache.tools.ant.types.Commandline
All Implemented Interfaces:
java.lang.Cloneable

public class Commandline
extends java.lang.Object
implements java.lang.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.

Author:
thomas.haas@softwired-inc.com, Stefan Bodewig

Inner Class Summary
 class Commandline.Argument
          Used for nested xml command line definitions.
 class Commandline.Marker
          Class to keep track of the position of an Argument.
 
Constructor Summary
Commandline()
           
Commandline(java.lang.String to_process)
           
 
Method Summary
 void addArguments(java.lang.String[] line)
           
 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()
           
 Commandline.Argument createArgument()
          Creates an argument object.
 Commandline.Marker createMarker()
          Return a marker.
 java.lang.String[] getArguments()
          Returns all arguments defined by addLine, addValue or the argument object.
 java.lang.String[] getCommandline()
          Returns the executable and all defined arguments.
 java.lang.String getExecutable()
           
static java.lang.String quoteArgument(java.lang.String argument)
          Put quotes around the given String if necessary.
 void setExecutable(java.lang.String executable)
          Sets the executable to run.
 int size()
           
 java.lang.String toString()
           
static java.lang.String toString(java.lang.String[] line)
           
static java.lang.String[] translateCommandline(java.lang.String to_process)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Commandline

public Commandline(java.lang.String to_process)

Commandline

public Commandline()
Method Detail

createArgument

public Commandline.Argument createArgument()
Creates an argument object. Each commandline object has at most one instance of the argument class.
Returns:
the argument object.

setExecutable

public void setExecutable(java.lang.String executable)
Sets the executable to run.

getExecutable

public java.lang.String getExecutable()

addArguments

public void addArguments(java.lang.String[] line)

getCommandline

public java.lang.String[] getCommandline()
Returns the executable and all defined arguments.

getArguments

public java.lang.String[] getArguments()
Returns all arguments defined by addLine, addValue or the argument object.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

quoteArgument

public static java.lang.String quoteArgument(java.lang.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.

Throws:
BuildException - if the argument contains both, single and double quotes.

toString

public static java.lang.String toString(java.lang.String[] line)

translateCommandline

public static java.lang.String[] translateCommandline(java.lang.String to_process)

size

public int size()

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

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

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.



Copyright © 1999-2002 Apache Software Foundation. All Rights Reserved.