Class ScriptRunner

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

public class ScriptRunner extends Object
Runs pre-/post-build hook scripts.
  • Field Details

    • LOG

      private static final org.slf4j.Logger LOG
    • scriptInterpreters

      private Map<String,ScriptInterpreter> scriptInterpreters
      The supported script interpreters, indexed by the lower-case file extension of their associated script files, never null.
    • globalVariables

      private Map<String,Object> globalVariables
      The common set of global variables to pass into the script interpreter, never null.
    • classPath

      private List<String> classPath
      The additional class path for the script interpreter, never null.
    • encoding

      private String encoding
      The file encoding of the hook scripts or null to use platform encoding.
  • Constructor Details

    • ScriptRunner

      public ScriptRunner()
      Creates a new script runner with BSH and Groovy interpreters.
  • Method Details

    • addScriptInterpreter

      public void addScriptInterpreter(String id, ScriptInterpreter scriptInterpreter)
      Add new script Interpreter
      Parameters:
      id - The Id of interpreter
      scriptInterpreter - the Script Interpreter implementation
    • setGlobalVariable

      public void setGlobalVariable(String name, Object value)
      Sets a global variable for the script interpreter.
      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,?> context, ExecutionLogger logger) throws IOException, ScriptException
      Runs the specified hook script (after resolution).
      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 and may not have extensions (resolution will search).
      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.
      Throws:
      IOException - If an I/O error occurred while reading the script file.
      ScriptException - If the script did not return true of threw an exception.
    • run

      public void run(String scriptDescription, File scriptFile, Map<String,?> context, ExecutionLogger logger) throws IOException, ScriptException
      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.
      Throws:
      IOException - If an I/O error occurred while reading the script file.
      ScriptException - If the script did not return true of threw an exception.
    • executeRun

      private void executeRun(String scriptDescription, File scriptFile, Map<String,?> context, ExecutionLogger logger) throws IOException, ScriptException
      Throws:
      IOException
      ScriptException
    • resolveScript

      private File resolveScript(File scriptFile)
      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 be null.
      Returns:
      The effective path to the script file or null if the input was null.
    • getInterpreter

      private ScriptInterpreter getInterpreter(File scriptFile)
      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 be null.
      Returns:
      The script interpreter for the file, never null.