org.schmant.app.jython
Class JythonExecutor

java.lang.Object
  extended by org.schmant.app.jython.JythonExecutor
All Implemented Interfaces:
ClosureRunner, ScriptExecutor, FlatteningListDecorator, TaskPackageEnableCallback

public final class JythonExecutor
extends Object
implements ScriptExecutor, FlatteningListDecorator, TaskPackageEnableCallback, ClosureRunner

This script executor runs Jython build scripts.

Since:
1.1
Author:
Karl Gustafsson
See Also:
JythonExecutorFactory

Constructor Summary
JythonExecutor()
           
 
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?
 void postEnable(TaskPackage tp, Report r)
          This method is called just after the task package has enabled itself.
 void preEnable(TaskPackage tp, Report r)
          This method is called just before the task package enables itself.
 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 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.
<T> int
tryAdd(FlatteningList<T> list, int index, Object o, ObjectTransformer<T> transformer)
          If o is an object that this decorator handles, add it to the list.
<T> int
tryAdd(FlatteningList<T> list, int index, T o)
          If o is an object that this decorator handles, add it to the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JythonExecutor

public JythonExecutor()
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 SchmantException,
                                 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:
SchmantException - On errors.
IOException

runWithDefaultWrapperScript

public Object runWithDefaultWrapperScript()
                                   throws SchmantException,
                                          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:
SchmantException - On errors.
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.

tryAdd

public <T> int tryAdd(FlatteningList<T> list,
                      int index,
                      T o)
Description copied from interface: FlatteningListDecorator
If o is an object that this decorator handles, add it to the list.

Specified by:
tryAdd in interface FlatteningListDecorator
Type Parameters:
T - The type of objects in the list.
Parameters:
list - The list to add the object to.
index - The index for the new object in the list. If this argument is -1, add the object to the end of the list.
o - The object to add.
Returns:
The total number of objects added to the list. If this decorator does not handle the supplied object, this method should return -1.

tryAdd

public <T> int tryAdd(FlatteningList<T> list,
                      int index,
                      Object o,
                      ObjectTransformer<T> transformer)
Description copied from interface: FlatteningListDecorator
If o is an object that this decorator handles, add it to the list.

Specified by:
tryAdd in interface FlatteningListDecorator
Type Parameters:
T - The type of objects in the list.
Parameters:
list - The list to add the object to.
index - The index for the new object in the list. If this argument is -1, add the object to the end of the list.
o - The object to add.
transformer - The transformer used to transform the object into the list's type before it is added.
Returns:
The total number of objects added to the list. If this decorator does not handle the supplied object, this method should return -1.

postEnable

public void postEnable(TaskPackage tp,
                       Report r)
Description copied from interface: TaskPackageEnableCallback
This method is called just after the task package has enabled itself.

Specified by:
postEnable in interface TaskPackageEnableCallback
Parameters:
tp - The task package.
r - The current report.

preEnable

public void preEnable(TaskPackage tp,
                      Report r)
Description copied from interface: TaskPackageEnableCallback
This method is called just before the task package enables itself.

Specified by:
preEnable in interface TaskPackageEnableCallback
Parameters:
tp - The task package.
r - The current report.

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.