com.rshtech.ant.util
Class SafeMain

java.lang.Object
  extended by com.rshtech.ant.util.SafeMain
All Implemented Interfaces:
org.apache.tools.ant.launch.AntMain

public class SafeMain
extends java.lang.Object
implements org.apache.tools.ant.launch.AntMain

A way to execute Ant build files from within a program without the process calling System.exit() (which makes it very useful in JUnit tests).

Version:
$Revision: 3134 $
Author:
$Author: kostya $

Field Summary
static java.lang.String DEFAULT_BUILD_FILENAME
          The default build file name.
 
Constructor Summary
  SafeMain()
          Constructor used when creating Main for later arg processing and startup
protected SafeMain(java.lang.String[] args)
          Deprecated.  
 
Method Summary
protected  void addBuildListeners(org.apache.tools.ant.Project project)
          Adds the listeners specified in the command line arguments, along with the default listener, to the specified project.
static java.lang.String getAntVersion()
          Returns the Ant version information, if available.
 org.apache.tools.ant.Project getProject()
           
static void main(java.lang.String[] args)
          Command line entry point (calls start(String, Properties, ClassLoader)).
static void start(int level, java.lang.String filename)
          Creates a new instance of this class using the arguments specified, gives it any extra user properties which have been specified, and then runs the build using the classloader provided.
static void start(int level, java.lang.String filename, java.lang.String target)
          Creates a new instance of this class using the arguments specified, gives it any extra user properties which have been specified, and then runs the build using the classloader provided.
static org.apache.tools.ant.Project start(java.lang.String[] args, java.util.Properties additionalUserProperties, java.lang.ClassLoader coreLoader)
          Creates a new instance of this class using the arguments specified, gives it any extra user properties which have been specified, and then runs the build using the classloader provided.
 void startAnt(java.lang.String[] args, java.util.Properties additionalUserProperties, java.lang.ClassLoader coreLoader)
          Start Ant
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUILD_FILENAME

public static final java.lang.String DEFAULT_BUILD_FILENAME
The default build file name.

See Also:
Constant Field Values
Constructor Detail

SafeMain

public SafeMain()
Constructor used when creating Main for later arg processing and startup


SafeMain

protected SafeMain(java.lang.String[] args)
            throws org.apache.tools.ant.BuildException
Deprecated. 

Sole constructor, which parses and deals with command line arguments.

Parameters:
args - Command line arguments. Must not be null.
Throws:
org.apache.tools.ant.BuildException - if the specified build file doesn't exist or is a directory.
Method Detail

getAntVersion

public static java.lang.String getAntVersion()
                                      throws org.apache.tools.ant.BuildException
Returns the Ant version information, if available. Once the information has been loaded once, it's cached and returned from the cache on future calls.

Returns:
the Ant version information as a String (always non-null)
Throws:
org.apache.tools.ant.BuildException - if the version information is unavailable

start

public static void start(int level,
                         java.lang.String filename)
Creates a new instance of this class using the arguments specified, gives it any extra user properties which have been specified, and then runs the build using the classloader provided.

Parameters:
args - Command line arguments. Must not be null.
additionalUserProperties - Any extra properties to use in this build. May be null, which is the equivalent to passing in an empty set of properties.
coreLoader - Classloader used for core classes. May be null in which case the system classloader is used.

start

public static void start(int level,
                         java.lang.String filename,
                         java.lang.String target)
Creates a new instance of this class using the arguments specified, gives it any extra user properties which have been specified, and then runs the build using the classloader provided.

Parameters:
args - Command line arguments. Must not be null.
additionalUserProperties - Any extra properties to use in this build. May be null, which is the equivalent to passing in an empty set of properties.
coreLoader - Classloader used for core classes. May be null in which case the system classloader is used.

start

public static org.apache.tools.ant.Project start(java.lang.String[] args,
                                                 java.util.Properties additionalUserProperties,
                                                 java.lang.ClassLoader coreLoader)
Creates a new instance of this class using the arguments specified, gives it any extra user properties which have been specified, and then runs the build using the classloader provided.

Parameters:
args - Command line arguments. Must not be null.
additionalUserProperties - Any extra properties to use in this build. May be null, which is the equivalent to passing in an empty set of properties.
coreLoader - Classloader used for core classes. May be null in which case the system classloader is used.

main

public static void main(java.lang.String[] args)
Command line entry point (calls start(String, Properties, ClassLoader)). This method kicks off the building of a project object and executes a build using either a given target or the default target.

Parameters:
args - Command line arguments. Must not be null.

startAnt

public void startAnt(java.lang.String[] args,
                     java.util.Properties additionalUserProperties,
                     java.lang.ClassLoader coreLoader)
Start Ant

Specified by:
startAnt in interface org.apache.tools.ant.launch.AntMain
Parameters:
args - command line args
additionalUserProperties - properties to set beyond those that may be specified on the args list
coreLoader - - not used
Since:
Ant 1.6

getProject

public org.apache.tools.ant.Project getProject()

addBuildListeners

protected void addBuildListeners(org.apache.tools.ant.Project project)
Adds the listeners specified in the command line arguments, along with the default listener, to the specified project.

Parameters:
project - The project to add listeners to. Must not be null.