public class ScriptRunner
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.List<java.lang.String> |
classPath
The additional class path for the script interpreter, never
null . |
private java.lang.String |
encoding
The file encoding of the hook scripts or
null to use platform encoding. |
private java.util.Map<java.lang.String,java.lang.Object> |
globalVariables
The common set of global variables to pass into the script interpreter, never
null . |
private org.apache.maven.plugin.logging.Log |
log
The mojo logger to print diagnostic to, never
null . |
private java.util.Map<java.lang.String,ScriptInterpreter> |
scriptInterpreters
The supported script interpreters, indexed by the lower-case file extension of their associated script files,
never
null . |
Constructor and Description |
---|
ScriptRunner(org.apache.maven.plugin.logging.Log log)
Creates a new script runner.
|
Modifier and Type | Method and Description |
---|---|
void |
addScriptInterpreter(java.lang.String id,
ScriptInterpreter scriptInterpreter) |
private void |
executeRun(java.lang.String scriptDescription,
java.io.File scriptFile,
java.util.Map<java.lang.String,? extends java.lang.Object> context,
ExecutionLogger logger,
java.lang.String stage,
boolean failOnException) |
private ScriptInterpreter |
getInterpreter(java.io.File scriptFile)
Determines the script interpreter for the specified script file by looking at its file extension.
|
private org.apache.maven.plugin.logging.Log |
getLog()
Gets the mojo logger.
|
private java.io.File |
resolveScript(java.io.File scriptFile)
Gets the effective path to the specified script.
|
void |
run(java.lang.String scriptDescription,
java.io.File scriptFile,
java.util.Map<java.lang.String,? extends java.lang.Object> context,
ExecutionLogger logger,
java.lang.String stage,
boolean failOnException)
Runs the specified hook script.
|
void |
run(java.lang.String scriptDescription,
java.io.File basedir,
java.lang.String relativeScriptPath,
java.util.Map<java.lang.String,? extends java.lang.Object> context,
ExecutionLogger logger,
java.lang.String stage,
boolean failOnException)
Runs the specified hook script.
|
void |
setClassPath(java.util.List<java.lang.String> classPath)
Sets the additional class path for the hook scripts.
|
void |
setGlobalVariable(java.lang.String name,
java.lang.Object value)
Sets a global variable for the script interpeter.
|
void |
setScriptEncoding(java.lang.String encoding)
Sets the file encoding of the hook scripts.
|
private org.apache.maven.plugin.logging.Log log
null
.private java.util.Map<java.lang.String,ScriptInterpreter> scriptInterpreters
null
.private java.util.Map<java.lang.String,java.lang.Object> globalVariables
null
.private java.util.List<java.lang.String> classPath
null
.private java.lang.String encoding
null
to use platform encoding.public ScriptRunner(org.apache.maven.plugin.logging.Log log)
log
- The mojo logger to print diagnostic to, must not be null
.public void addScriptInterpreter(java.lang.String id, ScriptInterpreter scriptInterpreter)
private org.apache.maven.plugin.logging.Log getLog()
null
.public void setGlobalVariable(java.lang.String name, java.lang.Object value)
name
- The name of the variable, must not be null
.value
- The value of the variable, may be null
.public void setClassPath(java.util.List<java.lang.String> classPath)
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.public void setScriptEncoding(java.lang.String encoding)
encoding
- The file encoding of the hook scripts, may be null
or empty to use the platform's
default encoding.public void run(java.lang.String scriptDescription, java.io.File basedir, java.lang.String relativeScriptPath, java.util.Map<java.lang.String,? extends java.lang.Object> context, ExecutionLogger logger, java.lang.String stage, boolean failOnException) throws java.io.IOException, RunFailureException
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.java.io.IOException
- If an I/O error occurred while reading the script file.RunFailureException
- If the script did not return true
of threw an exception.public void run(java.lang.String scriptDescription, java.io.File scriptFile, java.util.Map<java.lang.String,? extends java.lang.Object> context, ExecutionLogger logger, java.lang.String stage, boolean failOnException) throws java.io.IOException, RunFailureException
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.java.io.IOException
- If an I/O error occurred while reading the script file.RunFailureException
- If the script did not return true
of threw an exception.private void executeRun(java.lang.String scriptDescription, java.io.File scriptFile, java.util.Map<java.lang.String,? extends java.lang.Object> context, ExecutionLogger logger, java.lang.String stage, boolean failOnException) throws java.io.IOException, RunFailureException
java.io.IOException
RunFailureException
private java.io.File resolveScript(java.io.File scriptFile)
scriptFile
- The script file to resolve, may be null
.null
if the input was null
.private ScriptInterpreter getInterpreter(java.io.File scriptFile)
scriptFile
- The script file for which to determine an interpreter, must not be null
.null
.