net.sourceforge.cobertura.util
public class CommandLineBuilder extends Object
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.
| Field Summary | |
|---|---|
| File | commandLineFile |
| FileWriter | commandLineWriter |
| static Logger | logger |
| static String | LINESEP |
| Constructor Summary | |
|---|---|
| CommandLineBuilder()
Creates a new instance of the builder. | |
| Method Summary | |
|---|---|
| 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. |
Throws: IOException if problems with creating temporary file for storing command line occur
Parameters: arg command line argument to save
Throws: IOException
if problems with temporary file occur NullPointerException
if arg is null
Parameters: arg1 first command line argument to save arg2 second command line argument to save
Throws: IOException
if problems with temporary file occur NullPointerException
if any arg is null
Returns: absolute path to the file with arguments
--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.
Returns: The list of arguments read from commandsfile, or
args if commandsfile option was not specified
or the file cannot be read.
Throws: NullPointerException if args is null, or any argument is null IllegalArgumentException if --commandsfile is specified as last option IOException if I/O related error with temporary command line file occur
Throws: IOException if problems with temporary file occur