org.apache.maven.shared.scriptinterpreter
Class ScriptRunner

java.lang.Object
  extended by org.apache.maven.shared.scriptinterpreter.ScriptRunner

public class ScriptRunner
extends Object

Runs pre-/post-build hook scripts.

Version:
$Id: ScriptRunner.java 1361825 2012-07-15 22:21:49Z hboutemy $
Author:
Benjamin Bentmann

Constructor Summary
ScriptRunner(Log log)
          Creates a new script runner.
 
Method Summary
 void addScriptInterpreter(String id, ScriptInterpreter scriptInterpreter)
           
 void run(String scriptDescription, File scriptFile, Map<String,? extends Object> context, ExecutionLogger logger, String stage, boolean failOnException)
          Runs the specified hook script.
 void run(String scriptDescription, File basedir, String relativeScriptPath, Map<String,? extends Object> context, ExecutionLogger logger, String stage, boolean failOnException)
          Runs the specified hook script.
 void setClassPath(List<String> classPath)
          Sets the additional class path for the hook scripts.
 void setGlobalVariable(String name, Object value)
          Sets a global variable for the script interpeter.
 void setScriptEncoding(String encoding)
          Sets the file encoding of the hook scripts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptRunner

public ScriptRunner(Log log)
Creates a new script runner.

Parameters:
log - The mojo logger to print diagnostic to, must not be null.
Method Detail

addScriptInterpreter

public void addScriptInterpreter(String id,
                                 ScriptInterpreter scriptInterpreter)

setGlobalVariable

public void setGlobalVariable(String name,
                              Object value)
Sets a global variable for the script interpeter.

Parameters:
name - The name of the variable, must not be null.
value - The value of the variable, may be null.

setClassPath

public void setClassPath(List<String> classPath)
Sets the additional class path for the hook scripts. Note that the provided list is copied, so any later changes will not affect the scripts.

Parameters:
classPath - The additional class path for the script interpreter, may be null or empty if only the plugin realm should be used for the script evaluation. If specified, this class path will precede the artifacts from the plugin class path.

setScriptEncoding

public void setScriptEncoding(String encoding)
Sets the file encoding of the hook scripts.

Parameters:
encoding - The file encoding of the hook scripts, may be null or empty to use the platform's default encoding.

run

public void run(String scriptDescription,
                File basedir,
                String relativeScriptPath,
                Map<String,? extends Object> context,
                ExecutionLogger logger,
                String stage,
                boolean failOnException)
         throws IOException,
                RunFailureException
Runs the specified hook script.

Parameters:
scriptDescription - The description of the script to use for logging, must not be null.
basedir - The base directory of the project, must not be null.
relativeScriptPath - The path to the script relative to the project base directory, may be null to skip the script execution.
context - The key-value storage used to share information between hook scripts, may be null.
logger - The logger to redirect the script output to, may be null to use stdout/stderr.
stage - The stage of the build job the script is invoked in, must not be null. This is for logging purpose only.
failOnException - If true and the script throws an exception, then a RunFailureException will be thrown, otherwise a RunErrorException will be thrown on script exception.
Throws:
IOException - If an I/O error occurred while reading the script file.
RunFailureException - If the script did not return true of threw an exception.

run

public void run(String scriptDescription,
                File scriptFile,
                Map<String,? extends Object> context,
                ExecutionLogger logger,
                String stage,
                boolean failOnException)
         throws IOException,
                RunFailureException
Runs the specified hook script.

Parameters:
scriptDescription - The description of the script to use for logging, must not be null.
scriptFile - The path to the script, may be null to skip the script execution.
context - The key-value storage used to share information between hook scripts, may be null.
logger - The logger to redirect the script output to, may be null to use stdout/stderr.
stage - The stage of the build job the script is invoked in, must not be null. This is for logging purpose only.
failOnException - If true and the script throws an exception, then a RunFailureException will be thrown, otherwise a RunErrorException will be thrown on script exception.
Throws:
IOException - If an I/O error occurred while reading the script file.
RunFailureException - If the script did not return true of threw an exception.


Copyright © 2002-2012 The Apache Software Foundation. All Rights Reserved.