net.sourceforge.cobertura.util
Class CommandLineBuilder
java.lang.Object
net.sourceforge.cobertura.util.CommandLineBuilder
Helper class for storing long command lines inside temporary file.
Typical usage:
builder = new CommandLineBuilder();
builder.addArg("--someoption");
builder.addArg("optionValue");
...
builder.saveArgs();
doSomething(builder.getCommandLineFile());
builder.dispose();
It will save options in
builder.getCommandLineFile()
. Options
will be stored one in a line. To retrieve options from file helper method can
be used (see documentation):
String[] args = CommandLineBuilder.preprocessCommandLineArguments(args);
NOTICE: No protection against line separators in arguments, should be OK for
Cobertura needs.
NOTICE: This class depends on local machine settings (line separator, default
encoding). If arguments are saved on different machine than they are loaded,
results are unspecified. No problem in Cobertura.
void | addArg(String arg) - Adds command line argument.
|
void | addArg(String arg1, String arg2) - Adds two command line arguments.
|
void | dispose() - Explicity frees all resources associated with this instance.
|
String | getCommandLineFile() - Gets absolute path to the file with saved arguments.
|
static String[] | preprocessCommandLineArguments(String[] args) - Loads arguments from file if
--commandsfile option is used.
|
void | saveArgs() - Saves options and made file available to use.
|
LINESEP
private static final String LINESEP
logger
private static final Logger logger
CommandLineBuilder
public CommandLineBuilder()
throws IOException
Creates a new instance of the builder. Instances of this class should not
be reused to create many command lines.
addArg
public void addArg(String arg)
throws IOException
Adds command line argument. Each argument can be thought as a single cell
in array passed to main method. This method should not be used after
arguments were saved.
arg
- command line argument to save
addArg
public void addArg(String arg1,
String arg2)
throws IOException
Adds two command line arguments. Convienience function, calls
addArg(String)
two times.
arg1
- first command line argument to savearg2
- second command line argument to save
dispose
public void dispose()
Explicity frees all resources associated with this instance. Result of
any other method call after disposing an instance of this class is
unspecified.
getCommandLineFile
public String getCommandLineFile()
Gets absolute path to the file with saved arguments. Notice, that however
this method can be used as soon as an instance of this class is created,
arguments should be read from the file after a call to
saveArgs()
method.
- absolute path to the file with arguments
preprocessCommandLineArguments
public static String[] preprocessCommandLineArguments(String[] args)
throws IOException
Loads arguments from file if --commandsfile
option is used. Checks
if passed array contains --commandsfile
String, and if
so arguments from file specified in the very next array cell are read. If
there are more then one --commandsfile
the result is unspecified.
- The list of arguments read from commandsfile, or
args
if commandsfile option was not specified
or the file cannot be read.
saveArgs
public void saveArgs()
throws IOException
Saves options and made file available to use. Use method
getCommandLineFile()
to get the file the arguments are saved in.