Пример #1
0
 /**
  * Parses the named script from the supplied PluginResources and returns the Class that can be
  * used to create instances to invoke methods on.
  *
  * @param resources The plugin resources.
  * @param script The script path relative to the scripts directory.
  * @return The resulting class.
  */
 public static Class parseClass(PluginResources resources, String script) throws Exception {
   String path = FileUtils.separatorsToUnix(FileUtils.concat(SCRIPT_PATH, script));
   InputStream stream = resources.getResourceAsStream(path);
   if (stream == null) {
     throw new IllegalArgumentException(Services.getMessage("script.not.found", path));
   }
   return parseClass(stream);
 }
Пример #2
0
  /**
   * Evaluates the specified script and returns the result.
   *
   * @param resources The plugin resources.
   * @param script The script path relative to the scripts directory.
   * @param values Any variable name / value pairs for the script.
   * @return The result of evaluating the supplied script.
   */
  public static Object evaluateScript(
      PluginResources resources, String script, Map<String, Object> values) throws Exception {
    Binding binding = new Binding(values);
    GroovyShell shell = new GroovyShell(binding);

    String path = FileUtils.separatorsToUnix(FileUtils.concat(SCRIPT_PATH, script));
    InputStream stream = resources.getResourceAsStream(path);
    if (stream == null) {
      throw new IllegalArgumentException(Services.getMessage("script.not.found", path));
    }
    return shell.evaluate(stream);
  }