Class ScriptRunner
java.lang.Object
org.apache.maven.shared.scriptinterpreter.ScriptRunner
Runs pre-/post-build hook scripts.
- Version:
- $Id: ScriptRunner.java 1797598 2017-06-04 18:41:18Z hboutemy $
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe additional class path for the script interpreter, nevernull
.private String
The file encoding of the hook scripts ornull
to use platform encoding.The common set of global variables to pass into the script interpreter, nevernull
.private org.apache.maven.plugin.logging.Log
The mojo logger to print diagnostic to, nevernull
.private Map<String,
ScriptInterpreter> The supported script interpreters, indexed by the lower-case file extension of their associated script files, nevernull
. -
Constructor Summary
ConstructorsConstructorDescriptionScriptRunner
(org.apache.maven.plugin.logging.Log log) Creates a new script runner. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addScriptInterpreter
(String id, ScriptInterpreter scriptInterpreter) private void
executeRun
(String scriptDescription, File scriptFile, Map<String, ? extends Object> context, ExecutionLogger logger, String stage, boolean failOnException) private ScriptInterpreter
getInterpreter
(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 File
resolveScript
(File scriptFile) Gets the effective path to the specified 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 (after resolution).void
run
(String scriptDescription, File scriptFile, 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 interpreter.void
setScriptEncoding
(String encoding) Sets the file encoding of the hook scripts.
-
Field Details
-
log
private org.apache.maven.plugin.logging.Log logThe mojo logger to print diagnostic to, nevernull
. -
scriptInterpreters
The supported script interpreters, indexed by the lower-case file extension of their associated script files, nevernull
. -
globalVariables
The common set of global variables to pass into the script interpreter, nevernull
. -
classPath
The additional class path for the script interpreter, nevernull
. -
encoding
The file encoding of the hook scripts ornull
to use platform encoding.
-
-
Constructor Details
-
ScriptRunner
public ScriptRunner(org.apache.maven.plugin.logging.Log log) Creates a new script runner.- Parameters:
log
- The mojo logger to print diagnostic to, must not benull
.
-
-
Method Details
-
getLog
private org.apache.maven.plugin.logging.Log getLog()Gets the mojo logger.- Returns:
- The mojo logger, never
null
.
-
setGlobalVariable
Sets a global variable for the script interpreter.- Parameters:
name
- The name of the variable, must not benull
.value
- The value of the variable, may benull
.
-
setClassPath
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 benull
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
Sets the file encoding of the hook scripts.- Parameters:
encoding
- The file encoding of the hook scripts, may benull
or empty to use the platform's default encoding.
-
resolveScript
Gets the effective path to the specified script. For convenience, we allow to specify a script path as "verify" and have the plugin auto-append the file extension to search for "verify.bsh" and "verify.groovy".- Parameters:
scriptFile
- The script file to resolve, may benull
.- Returns:
- The effective path to the script file or
null
if the input wasnull
.
-
getInterpreter
Determines the script interpreter for the specified script file by looking at its file extension. In this context, file extensions are considered case-insensitive. For backward compatibility with plugin versions 1.2-, the BeanShell interpreter will be used for any unrecognized extension.- Parameters:
scriptFile
- The script file for which to determine an interpreter, must not benull
.- Returns:
- The script interpreter for the file, never
null
.