org.codehaus.mojo.macker
Class CommandLineBuilder

java.lang.Object
  extended by org.codehaus.mojo.macker.CommandLineBuilder

public class CommandLineBuilder
extends Object

Helper class for storing long command lines inside a 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. Options are saved in UTF-8 encoding.

Author:
Grzegorz Lukasik (Cobertura)

Constructor Summary
CommandLineBuilder(String name)
          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.
 void saveArgs()
          Saves options and made file available to use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandLineBuilder

public CommandLineBuilder(String name)
                   throws IOException
Creates a new instance of the builder. Instances of this class should not be reused to create many command lines.

Throws:
IOException - if problems with creating temporary file for storing command line occur
Method Detail

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.

Parameters:
arg - command line argument to save
Throws:
IOException - if problems with temporary file occur

addArg

public void addArg(String arg1,
                   String arg2)
            throws IOException
Adds two command line arguments. Convienience function, calls addArg(String) two times.

Parameters:
arg1 - first command line argument to save
arg2 - second command line argument to save
Throws:
IOException - if problems with temporary file occur

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.

Throws:
IOException - if problems with temporary file occur

getCommandLineFile

public String getCommandLineFile()
                          throws IOException
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.

Returns:
absolute path to the file with arguments
Throws:
IOException

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.



Copyright © 2007-2010 CodeHaus. All Rights Reserved.