org.apache.maven.shared.utils.cli
Class Commandline

java.lang.Object
  extended by org.apache.maven.shared.utils.cli.Commandline
All Implemented Interfaces:
Cloneable

public class Commandline
extends Object
implements Cloneable

Commandline objects help handling command lines specifying processes to execute.

The class can be used to define a command line as nested elements or as a helper to define a command line by an application.

<someelement>
  <acommandline executable="/executable/to/run">
    <argument value="argument 1" />
    <argument line="argument_1 argument_2 argument_3" />
    <argument value="argument 4" />
  </acommandline>
</someelement>

The element someelement must provide a method createAcommandline which returns an instance of this class.

Author:
thomas.haas@softwired-inc.com, Stefan Bodewig

Nested Class Summary
static class Commandline.Argument
           
 
Constructor Summary
Commandline()
          Create a new command line object.
Commandline(Shell shell)
          Create a new command line object.
Commandline(String toProcess)
          Create a new command line object.
 
Method Summary
 void addArguments(String... line)
           
 void addEnvironment(String name, String value)
          Add an environment variable
 void addSystemEnvironment()
          Add system environment variables
 void clearArgs()
          Clear out the arguments but leave the executable in place for another operation.
 Object clone()
           
 Arg createArg()
          Creates an argument object.
 Arg createArg(boolean insertAtStart)
          Creates an argument object and adds it to our list of args.
 Process execute()
          Executes the command.
 String[] getArguments()
          Returns all arguments defined by addLine, addValue or the argument object.
 String[] getArguments(boolean mask)
          Returns all arguments defined by addLine, addValue or the argument object.
 String[] getCommandline()
          Returns the executable and all defined arguments.
 String[] getEnvironmentVariables()
          Return the list of environment variables
 String getExecutable()
           
 Shell getShell()
          Get the shell to be used in this command line.
 File getWorkingDirectory()
           
 void setExecutable(String executable)
          Sets the executable to run.
 void setWorkingDirectory(File workingDirectory)
          Sets execution directory.
 void setWorkingDirectory(String path)
          Sets execution directory.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Commandline

public Commandline(Shell shell)
Create a new command line object. Shell is autodetected from operating system


Commandline

public Commandline(String toProcess)
Create a new command line object. Shell is autodetected from operating system

Parameters:
toProcess - The command to process

Commandline

public Commandline()
Create a new command line object. Shell is autodetected from operating system

Method Detail

createArg

public Arg createArg()
Creates an argument object.

Each commandline object has at most one instance of the argument class. This method calls this.createArgument(false).

Returns:
the argument object.

createArg

public Arg createArg(boolean insertAtStart)
Creates an argument object and adds it to our list of args.

Each commandline object has at most one instance of the argument class.

Parameters:
insertAtStart - if true, the argument is inserted at the beginning of the list of args, otherwise it is appended.

setExecutable

public void setExecutable(String executable)
Sets the executable to run.


getExecutable

public String getExecutable()

addArguments

public void addArguments(String... line)

addEnvironment

public void addEnvironment(String name,
                           String value)
Add an environment variable


addSystemEnvironment

public void addSystemEnvironment()
Add system environment variables


getEnvironmentVariables

public String[] getEnvironmentVariables()
Return the list of environment variables


getCommandline

public String[] getCommandline()
Returns the executable and all defined arguments.


getArguments

public String[] getArguments()
Returns all arguments defined by addLine, addValue or the argument object.


getArguments

public String[] getArguments(boolean mask)
Returns all arguments defined by addLine, addValue or the argument object.

Parameters:
mask - flag to mask any arguments (having his mask field to true).

toString

public String toString()
Overrides:
toString in class Object

clone

public Object clone()
Overrides:
clone in class Object

setWorkingDirectory

public void setWorkingDirectory(String path)
Sets execution directory.


setWorkingDirectory

public void setWorkingDirectory(File workingDirectory)
Sets execution directory.


getWorkingDirectory

public File getWorkingDirectory()

clearArgs

public void clearArgs()
Clear out the arguments but leave the executable in place for another operation.


execute

public Process execute()
                throws CommandLineException
Executes the command.

Throws:
CommandLineException

getShell

public Shell getShell()
Get the shell to be used in this command line.



Copyright © 2002–2015 The Apache Software Foundation. All rights reserved.