org.schmant.app.groovy
Class GroovyExecutor

java.lang.Object
  extended by org.schmant.app.groovy.GroovyExecutor
All Implemented Interfaces:
ClosureRunner, ScriptExecutor

public final class GroovyExecutor
extends Object
implements ScriptExecutor, ClosureRunner

Script executor for Groovy build scripts.

Since:
1.1
Author:
Karl Gustafsson

Constructor Summary
GroovyExecutor()
           
 
Method Summary
 void init(NamedReadableFile scriptFile, LauncherSettings ls, Report r)
          Initialize the script executor.
 boolean isClosure(Object o)
          Is the object a closure that can be run?
 Object runClosure(Object closure, Object... arguments)
          Run the closure and return the result.
 void runDefaultPreparationScript(Report r)
          Run the default environment preparation script.
 void runPreparationScript(File script, Report r)
          Run the preparation script in the file.
 Object runScript(Object scriptFile)
           
 Object runWithDefaultWrapperScript()
          Run the script using the default wrapper script, if any.
 void setBindings(Bindings bnd, int scope)
          Set the variables stored in the bindings in the specified scope.
 void setGlobalVariable(String name, Object value)
          Set the value of a global variable in the script.
 void tearDown()
          Tear down the script executor when Schmant terminates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GroovyExecutor

public GroovyExecutor()
Method Detail

init

public void init(NamedReadableFile scriptFile,
                 LauncherSettings ls,
                 Report r)
          throws IOException
Description copied from interface: ScriptExecutor
Initialize the script executor. This method is responsible for registering the script executor with different Schmant extension points such as FlatteningList.registerDecorator(org.schmant.support.util.FlatteningListDecorator), TaskExecutorThreadFactory.registerThreadContextInitializer(org.schmant.run.ThreadContextInitializer) and ClosureSupport.registerClosureRunner(org.schmant.lang.ClosureRunner).

Specified by:
init in interface ScriptExecutor
Parameters:
scriptFile - The script file that is run.
ls - The command line settings.
r - The report.
Throws:
IOException
See Also:
ScriptExecutor.tearDown()

tearDown

public void tearDown()
Description copied from interface: ScriptExecutor
Tear down the script executor when Schmant terminates. This method should deregister the script executor from the extension points that ScriptExecutor.init(NamedReadableFile, LauncherSettings, Report) registered with.

Specified by:
tearDown in interface ScriptExecutor

runDefaultPreparationScript

public void runDefaultPreparationScript(Report r)
                                 throws IOException
Description copied from interface: ScriptExecutor
Run the default environment preparation script. This should register global functions that the build script may use.

Specified by:
runDefaultPreparationScript in interface ScriptExecutor
Parameters:
r - A report to log to.
Throws:
IOException

runPreparationScript

public void runPreparationScript(File script,
                                 Report r)
                          throws IOException
Description copied from interface: ScriptExecutor
Run the preparation script in the file.

Specified by:
runPreparationScript in interface ScriptExecutor
Parameters:
script - The script file.
r - A report to log to.
Throws:
IOException

runWithDefaultWrapperScript

public Object runWithDefaultWrapperScript()
                                   throws IOException
Description copied from interface: ScriptExecutor
Run the script using the default wrapper script, if any.

Specified by:
runWithDefaultWrapperScript in interface ScriptExecutor
Returns:
The value returned from the script.
Throws:
IOException

runScript

public Object runScript(Object scriptFile)
                 throws IOException
Throws:
IOException

setBindings

public void setBindings(Bindings bnd,
                        int scope)
Description copied from interface: ScriptExecutor
Set the variables stored in the bindings in the specified scope. For now the scope is always global.

Specified by:
setBindings in interface ScriptExecutor
Parameters:
bnd - The bindings containing a map of variables to set.
scope - The scope to set the variables in. See ScriptContext. For now this parameter can be ignored and all variables set to the global scope.

setGlobalVariable

public void setGlobalVariable(String name,
                              Object value)
Description copied from interface: ScriptExecutor
Set the value of a global variable in the script.

Specified by:
setGlobalVariable in interface ScriptExecutor
Parameters:
name - The name of the variable.
value - The variable value.

isClosure

public boolean isClosure(Object o)
Description copied from interface: ClosureRunner
Is the object a closure that can be run?

Specified by:
isClosure in interface ClosureRunner
Parameters:
o - The object.
Returns:
true if the object is a closure.

runClosure

public Object runClosure(Object closure,
                         Object... arguments)
                  throws SchmantException
Description copied from interface: ClosureRunner
Run the closure and return the result.

Specified by:
runClosure in interface ClosureRunner
Parameters:
closure - The closure to run.
arguments - Arguments to the closure.
Returns:
The result from running the closure. This should be the expected value and not some kind of script language wrapper object, such as PyObject.
Throws:
SchmantException - On errors.