Methods Summary |
---|
public void | addArguments(java.lang.String[] line)Append the arguments to the existing command.
for (int i = 0; i < line.length; i++) {
createArgument().setValue(line[i]);
}
|
public void | addArgumentsToList(java.util.ListIterator list)Append all the arguments to the tail of a supplied list.
for (int i = 0; i < arguments.size(); i++) {
Argument arg = (Argument) arguments.elementAt(i);
String[] s = arg.getParts();
if (s != null) {
for (int j = 0; j < s.length; j++) {
list.add(s[j]);
}
}
}
|
public void | addCommandToList(java.util.ListIterator list)Add the entire command, including (optional) executable to a list.
if (executable != null) {
list.add(executable);
}
addArgumentsToList(list);
|
public void | clear()Clear out the whole command line.
executable = null;
arguments.removeAllElements();
|
public void | clearArgs()Clear out the arguments but leave the executable in place for
another operation.
arguments.removeAllElements();
|
public java.lang.Object | clone()Generate a deep clone of the contained object.
try {
Commandline c = (Commandline) super.clone();
c.arguments = (Vector) arguments.clone();
return c;
} catch (CloneNotSupportedException e) {
throw new BuildException(e);
}
|
public org.apache.tools.ant.types.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) .
return this.createArgument(false);
|
public org.apache.tools.ant.types.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.
Argument argument = new Argument();
if (insertAtStart) {
arguments.insertElementAt(argument, 0);
} else {
arguments.addElement(argument);
}
return argument;
|
public org.apache.tools.ant.types.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.
return new Marker(arguments.size());
|
public java.lang.String | describeArguments()Return a String that describes the arguments suitable for
verbose output before a call to Runtime.exec(String[]).
return describeArguments(this);
|
public static java.lang.String | describeArguments(org.apache.tools.ant.types.Commandline line)Return a String that describes the arguments suitable for
verbose output before a call to Runtime.exec(String[]).
return describeArguments(line.getArguments());
|
public 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[]).
return describeArguments(args, 0);
|
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[]).
if (args == null || args.length <= offset) {
return "";
}
StringBuffer buf = new StringBuffer("argument");
if (args.length > offset) {
buf.append("s");
}
buf.append(":").append(StringUtils.LINE_SEP);
for (int i = offset; i < args.length; i++) {
buf.append("\'").append(args[i]).append("\'")
.append(StringUtils.LINE_SEP);
}
buf.append(DISCLAIMER);
return buf.toString();
|
public java.lang.String | describeCommand()Return a String that describes the command and arguments suitable for
verbose output before a call to Runtime.exec(String[]).
return describeCommand(this);
|
public static java.lang.String | describeCommand(org.apache.tools.ant.types.Commandline line)Return a String that describes the command and arguments suitable for
verbose output before a call to Runtime.exec(String[]).
return describeCommand(line.getCommandline());
|
public 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[]).
This method assumes that the first entry in the array is the
executable to run.
if (args == null || args.length == 0) {
return "";
}
StringBuffer buf = new StringBuffer("Executing \'");
buf.append(args[0]);
buf.append("\'");
if (args.length > 1) {
buf.append(" with ");
buf.append(describeArguments(args, 1));
} else {
buf.append(DISCLAIMER);
}
return buf.toString();
|
public java.lang.String[] | getArguments()Returns all arguments defined by addLine ,
addValue or the argument object.
List result = new ArrayList(arguments.size() * 2);
addArgumentsToList(result.listIterator());
String [] res = new String[result.size()];
return (String[]) result.toArray(res);
|
public java.lang.String[] | getCommandline()Return the executable and all defined arguments.
List commands = new LinkedList();
ListIterator list = commands.listIterator();
addCommandToList(list);
final String[] result = new String[commands.size()];
return (String[]) commands.toArray(result);
|
public java.lang.String | getExecutable()Get the executable.
return executable;
|
public java.util.Iterator | iterator()Get an iterator to the arguments list.
return arguments.iterator();
|
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.
if (argument.indexOf("\"") > -1) {
if (argument.indexOf("\'") > -1) {
throw new BuildException("Can\'t handle single and double"
+ " quotes in same argument");
} else {
return '\'" + argument + '\'";
}
} else if (argument.indexOf("\'") > -1
|| argument.indexOf(" ") > -1
// WIN9x uses a bat file for executing commands
|| (IS_WIN_9X && argument.indexOf(';") != -1)) {
return '\"" + argument + '\"";
} else {
return argument;
}
|
public void | setExecutable(java.lang.String executable)Set the executable to run. All file separators in the string
are converted to the platform specific value.
if (executable == null || executable.length() == 0) {
return;
}
this.executable = executable.replace('/", File.separatorChar)
.replace('\\", File.separatorChar);
|
public int | size()Size operator. This actually creates the command line, so it is not
a zero cost operation.
return getCommandline().length;
|
public java.lang.String | toString()Return the command line as a string.
return toString(getCommandline());
|
public 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.
// empty path return empty string
if (line == null || line.length == 0) {
return "";
}
// path containing one or more elements
final StringBuffer result = new StringBuffer();
for (int i = 0; i < line.length; i++) {
if (i > 0) {
result.append(' ");
}
result.append(quoteArgument(line[i]));
}
return result.toString();
|
public static java.lang.String[] | translateCommandline(java.lang.String toProcess)Crack a command line.
if (toProcess == null || toProcess.length() == 0) {
//no command? no string
return new String[0];
}
// parse with a simple finite state machine
final int normal = 0;
final int inQuote = 1;
final int inDoubleQuote = 2;
int state = normal;
StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true);
Vector v = new Vector();
StringBuffer current = new StringBuffer();
boolean lastTokenHasBeenQuoted = false;
while (tok.hasMoreTokens()) {
String nextTok = tok.nextToken();
switch (state) {
case inQuote:
if ("\'".equals(nextTok)) {
lastTokenHasBeenQuoted = true;
state = normal;
} else {
current.append(nextTok);
}
break;
case inDoubleQuote:
if ("\"".equals(nextTok)) {
lastTokenHasBeenQuoted = true;
state = normal;
} else {
current.append(nextTok);
}
break;
default:
if ("\'".equals(nextTok)) {
state = inQuote;
} else if ("\"".equals(nextTok)) {
state = inDoubleQuote;
} else if (" ".equals(nextTok)) {
if (lastTokenHasBeenQuoted || current.length() != 0) {
v.addElement(current.toString());
current = new StringBuffer();
}
} else {
current.append(nextTok);
}
lastTokenHasBeenQuoted = false;
break;
}
}
if (lastTokenHasBeenQuoted || current.length() != 0) {
v.addElement(current.toString());
}
if (state == inQuote || state == inDoubleQuote) {
throw new BuildException("unbalanced quotes in " + toProcess);
}
String[] args = new String[v.size()];
v.copyInto(args);
return args;
|