public class CommandBuilder extends Object implements Serializable, Cloneable
Most of the methods are for adding arguments. To simplify this, we
have all kinds of overloaded add(String) methods. These methods
are null safe, in that if null is passed as an argument they get ignored.
Configuring other parts of the process invocation isn't complete, except
pwd(File). When you find a need to add more, please add them.
Once enough details are configured, use system() or popen()
to run them. Alternatively, use build() to get a configured
ProcessBuilder and then handle the output yourself.
| Constructor and Description |
|---|
CommandBuilder() |
CommandBuilder(Collection<String> args) |
CommandBuilder(String... args) |
| Modifier and Type | Method and Description |
|---|---|
CommandBuilder |
add(CommandBuilder cmds) |
CommandBuilder |
add(File f) |
CommandBuilder |
add(Object... args) |
CommandBuilder |
add(Object a) |
CommandBuilder |
add(Object a,
boolean mask) |
CommandBuilder |
add(String... args) |
CommandBuilder |
add(String a) |
CommandBuilder |
addAll(Collection<String> args) |
CommandBuilder |
addKeyValuePair(String prefix,
String key,
String value) |
CommandBuilder |
addKeyValuePairs(String prefix,
Map<String,String> props)
Adds key value pairs as "-Dkey=value -Dkey=value ..."
-D portion is configurable as the 'prefix' parameter.
|
CommandBuilder |
addKeyValuePairs(String prefix,
Map<String,String> props,
Set<String> propsToMask)
Adds key value pairs as "-Dkey=value -Dkey=value ..." with masking.
|
CommandBuilder |
addQuoted(String a)
Adds an argument by quoting it.
|
CommandBuilder |
addQuoted(String a,
boolean mask) |
ProcessBuilder |
build() |
void |
clear()
Re-initializes the arguments list.
|
CommandBuilder |
clone() |
boolean |
equals(Object o) |
int |
hashCode() |
ProcessInputStream |
popen()
Executes a process and read its output.
|
CommandBuilder |
prepend(String... args) |
CommandBuilder |
pwd(File dir) |
int |
system()
Executes a process and waits for that to complete.
|
String[] |
toCommandArray() |
List<String> |
toList() |
String |
toString()
Debug/error message friendly output.
|
String |
toStringWithQuote()
Just adds quotes around args containing spaces, but no other special characters,
so this method should generally be used only for informational/logging purposes.
|
CommandBuilder |
toWindowsCommand()
Calls toWindowsCommand(false)
|
CommandBuilder |
toWindowsCommand(boolean escapeVars)
Wrap command in a CMD.EXE call so we can return the exit code (ERRORLEVEL).
|
public CommandBuilder()
public CommandBuilder(Collection<String> args)
public CommandBuilder(String... args)
public ProcessBuilder build()
public int system()
throws IOException,
InterruptedException
IOExceptionInterruptedExceptionpublic ProcessInputStream popen() throws IOException
IOExceptionpublic CommandBuilder pwd(File dir)
public CommandBuilder add(Object a)
public CommandBuilder add(Object a, boolean mask)
public CommandBuilder add(File f)
public CommandBuilder add(String a)
public CommandBuilder prepend(String... args)
public CommandBuilder addQuoted(String a)
public CommandBuilder addQuoted(String a, boolean mask)
public CommandBuilder add(Object... args)
public CommandBuilder add(String... args)
public CommandBuilder add(CommandBuilder cmds)
public CommandBuilder addAll(Collection<String> args)
public CommandBuilder addKeyValuePair(String prefix, String key, String value)
public CommandBuilder addKeyValuePairs(String prefix, Map<String,String> props)
public CommandBuilder addKeyValuePairs(String prefix, Map<String,String> props, Set<String> propsToMask)
prefix - Configures the -D portion of the example. Defaults to -D if null.props - The map of key/value pairs to addpropsToMask - Set containing key names to mark as masked in the argument list. Key
names that do not exist in the set will be added unmasked.public String[] toCommandArray()
public CommandBuilder clone()
public void clear()
public String toStringWithQuote()
public CommandBuilder toWindowsCommand(boolean escapeVars)
escapeVars - True to escape %VAR% references; false to leave these alone
so they may be expanded when the command is runpublic CommandBuilder toWindowsCommand()
toWindowsCommand(boolean)public String toString()
Copyright © 2004-2014. All Rights Reserved.