Gant 1.9.6

gant
[Groovy] Class Gant

java.lang.Object
  gant.Gant

final class Gant
extends java.lang.Object

This class provides infrastructure and an executable command for using Groovy + AntBuilder as a build tool in a way similar to Rake and SCons. However, where Rake and SCons are dependency programming systems based on Ruby and Python respectively, Gant is simply a way of scripting Ant tasks; the Ant tasks do all the dependency management.

A Gant build specification file (default name build.gant) is assumed to contain one or more targets. Dependencies between targets are handled as function calls within functions, or by use of the depends function. Execution of Ant tasks is by calling methods on the object referred to by `ant', which is predefined as a GantBuilder instance.

On execution of the gant command, the Gant build specification is read and executed in the context of a predefined binding. An object referred to by `ant' is part of the binding so methods can use this object to get access to the Ant tasks without having to create an object explicitly. A method called `target' is part of the predefined binding. A target has two parameters, a single item map and a closure. The single item map has the target name as the key and the documentation about the target as the value. This documentation is used by the `gant -T' / `gant --targets' / `gant -p' command to present a list of all the documented targets.

NB In the following example some extra spaces have had to be introduced because some of the patterns look like comment ends:-(

A trivial example build specification is:

      target ( stuff : 'A target to do some stuff.' ) {
        clean ( )
        otherStuff ( )
      }
      target ( otherStuff : 'A target to do some other stuff' ) {
        depends ( clean )
      }
      target ( clean : 'Clean the directory and subdirectories' ) {
        delete ( dir : 'build' , quiet : 'true' )
        delete ( quiet : 'true' ) { fileset ( dir : '.' , includes : '** /*~,** /*.bak'  , defaultexcludes : 'false' ) }
      }
      setDefaultTarget ( stuff )
 

or, using some a ready made targets class:

      includeTargets << gant.targets.Clean
      cleanPattern << [ '** / *~' , '** / *.bak' ]
      cleanDirectory << 'build'
      target ( stuff : 'A target to do some stuff.' ) {
        clean ( )
        otherStuff ( )
      }
      target ( otherStuff : 'A target to do some other stuff' ) {
        depends ( clean )
      }
      setDefaultTarget ( stuff )
  

Note that there is an space between the two asterisks and the solidus in the fileset line that should notbe there, we have to have it in the source because asterisk followed by solidus is end of comment in Groovy

Authors:
Russel Winder
Graeme Rocher
Peter Ledbrook


Property Summary
java.lang.String buildClassName

The name of the class actually used for compiling the script.

java.io.File cacheDirectory

The location where the compiled scripts are cached.

boolean dryRun

Determines whether Gant performs a dry-run or does it for real.

java.util.List gantLib

A list of strings containing the locations of Gant modules.

java.lang.Object script

The script that will be run when {

link:
#processTargets ( ) } is called.

boolean useCache

Determines whether the scripts are cached or not.

 
Constructor Summary
Gant()

Default constructor -- creates a new instance of GantBinding for the script binding, and the default class loader.

Gant(GantBinding b)

Constructor that uses the passed GantBinding for the script binding, and the default class loader.

Gant(GantBinding b, java.lang.ClassLoader cl)

Constructor that uses the passed GantBinding for the script binding, and the passed ClassLoader as the class loader.

Gant(java.lang.Object p)

Constructor intended for use in code to be called from the Groovy Ant Task.

 
Method Summary
void addBuildListener(org.apache.tools.ant.BuildListener buildListener)

Add a BuildListener instance to this Gant instance.

java.lang.Integer executeTargets(java.lang.String function = 'dispatch', java.util.List targets = [])

Executes a pre-prepared set of targets.

Gant loadScript(java.lang.String text)

Treat the given text as a Gant script and load it.

Gant loadScript(java.io.InputStream scriptSource)

Load a Gant script from the given input stream, using the default Groovy encoding to convert the bytes to characters.

Gant loadScript(java.io.File scriptFile)

Load a Gant script from the given file, using the default Groovy encoding to convert the bytes to characters.

Gant loadScript(java.net.URL scriptUrl)

Load a Gant script from the given URL, using the default Groovy encoding to convert the bytes to characters.

Gant loadScriptClass(java.lang.String className)

Load a pre-compiled Gant script using the configured class loader.

static void main(String[] args)

The entry point for command line invocation.

groovy.lang.GroovyObject prepareTargets()

Prepares Gant for execution returning the Gant script that will be used for the execution

java.lang.Integer processArgs(String[] args)

Process the command line options and then call the function to process the targets.

java.lang.Integer processTargets()

java.lang.Integer processTargets(java.lang.String s)

java.lang.Integer processTargets(java.util.List l)

protected java.lang.Integer processTargets(java.lang.String function, java.util.List targets)

Process the targets, but first execute the build script so all the targets and other code are available.

void removeBuildListener(org.apache.tools.ant.BuildListener buildListener)

Remove a BuildListener instance from this Gant instance

void setAllPerTargetPostHooks(groovy.lang.Closure hook)

Sets all the target post hooks

void setAllPerTargetPreHooks(groovy.lang.Closure hook)

Sets all the pre hooks

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Property Detail

buildClassName

java.lang.String buildClassName
The name of the class actually used for compiling the script.


cacheDirectory

java.io.File cacheDirectory
The location where the compiled scripts are cached. Defaults to "$USER_HOME/.gant/cache".


dryRun

boolean dryRun
Determines whether Gant performs a dry-run or does it for real.


gantLib

java.util.List gantLib
A list of strings containing the locations of Gant modules.


script

java.lang.Object script
The script that will be run when {
link:
#processTargets ( ) } is called. It is initialised when a script is loaded. Note that it has a dynamic type because the script may be loaded from a different class loader than the one used to load the Gant class. If we declared it as Script, there would likely be ClassCastExceptions.


useCache

boolean useCache
Determines whether the scripts are cached or not. Defaults to false.


 
Constructor Detail

Gant

Gant()
Default constructor -- creates a new instance of GantBinding for the script binding, and the default class loader.


Gant

Gant(GantBinding b)
Constructor that uses the passed GantBinding for the script binding, and the default class loader.
Parameters:
b - the GantBinding to use.


Gant

Gant(GantBinding b, java.lang.ClassLoader cl)
Constructor that uses the passed GantBinding for the script binding, and the passed ClassLoader as the class loader.
Parameters:
b - the GantBinding to use.
cl - the ClassLoader to use.


Gant

Gant(java.lang.Object p)
Constructor intended for use in code to be called from the Groovy Ant Task.
Parameters:
p - the org.apache.tools.ant.Project to use.


 
Method Detail

addBuildListener

void addBuildListener(org.apache.tools.ant.BuildListener buildListener)
Add a BuildListener instance to this Gant instance.


executeTargets

java.lang.Integer executeTargets(java.lang.String function = 'dispatch', java.util.List targets = [])

Executes a pre-prepared set of targets. This method is typically used in conjunction with #prepareTargets()

     gant.prepareTargets()
     gant.executeTargets()
 

The #processTargets() method combines the above two methods

Parameters:
function
targets
Returns:


loadScript

Gant loadScript(java.lang.String text)
Treat the given text as a Gant script and load it.
params:
text The text of the Gant script to load.
Returns:
The Gant instance (to allow chaining).


loadScript

Gant loadScript(java.io.InputStream scriptSource)
Load a Gant script from the given input stream, using the default Groovy encoding to convert the bytes to characters.
params:
scriptSource The stream containing the Gant script source, i.e. the Groovy code, not the compiled class.
Returns:
The Gant instance (to allow chaining).


loadScript

Gant loadScript(java.io.File scriptFile)
Load a Gant script from the given file, using the default Groovy encoding to convert the bytes to characters.
params:
scriptFile The file containing the Gant script source, i.e. the Groovy code, not the compiled class.
Returns:
The Gant instance (to allow chaining).


loadScript

Gant loadScript(java.net.URL scriptUrl)
Load a Gant script from the given URL, using the default Groovy encoding to convert the bytes to characters.
params:
scriptUrl The URL where the the Gant script source is located.
Returns:
The Gant instance (to allow chaining).


loadScriptClass

Gant loadScriptClass(java.lang.String className)
Load a pre-compiled Gant script using the configured class loader.
params:
className The fully qualified name of the class to load.
Returns:
The Gant instance (to allow chaining).


main

static void main(String[] args)
The entry point for command line invocation.


prepareTargets

groovy.lang.GroovyObject prepareTargets()
Prepares Gant for execution returning the Gant script that will be used for the execution
Returns:
The Gant script to be used


processArgs

java.lang.Integer processArgs(String[] args)
Process the command line options and then call the function to process the targets.


processTargets

java.lang.Integer processTargets()


processTargets

java.lang.Integer processTargets(java.lang.String s)


processTargets

java.lang.Integer processTargets(java.util.List l)


processTargets

protected java.lang.Integer processTargets(java.lang.String function, java.util.List targets)
Process the targets, but first execute the build script so all the targets and other code are available.


removeBuildListener

void removeBuildListener(org.apache.tools.ant.BuildListener buildListener)
Remove a BuildListener instance from this Gant instance


setAllPerTargetPostHooks

void setAllPerTargetPostHooks(groovy.lang.Closure hook)
Sets all the target post hooks


setAllPerTargetPreHooks

void setAllPerTargetPreHooks(groovy.lang.Closure hook)
Sets all the pre hooks


 

Copyright © 2006–9 The Codehaus. All Rights Reserved.