コード例 #1
0
ファイル: ScriptCommand.java プロジェクト: arvindcr2/jsoar
  private synchronized ScriptEngineState getEngineByName(String name, boolean reset)
      throws SoarException {
    ScriptEngineState state = engines.get(name);
    if (state != null && reset) {
      state.dispose();
      engines.remove(name);
      state = null;
    }

    if (state == null) {
      final ScriptEngine engine = getEngineManager().getEngineByName(name);
      if (engine == null) {
        throw new SoarException("Unsupported script engine '" + name + "'");
      }

      final ScriptEngineFactory f = engine.getFactory();
      logger.info(
          String.format(
              "Loaded '%s' script engine for %s: %s version %s, %s version %s",
              name,
              context,
              f.getEngineName(),
              f.getEngineVersion(),
              f.getLanguageName(),
              f.getLanguageVersion()));

      engines.put(name, state = new ScriptEngineState(context, name, engine));
    }
    return state;
  }
コード例 #2
0
  private L2ScriptEngineManager() {
    ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
    List<ScriptEngineFactory> factories = scriptEngineManager.getEngineFactories();
    if (Config.SCRIPT_CACHE) {
      _cache = loadCompiledScriptCache();
    } else {
      _cache = null;
    }
    _log.info("Initializing Script Engine Manager");

    for (ScriptEngineFactory factory : factories) {
      try {
        ScriptEngine engine = factory.getScriptEngine();
        boolean reg = false;
        for (String name : factory.getNames()) {
          ScriptEngine existentEngine = _nameEngines.get(name);

          if (existentEngine != null) {
            double engineVer = Double.parseDouble(factory.getEngineVersion());
            double existentEngVer =
                Double.parseDouble(existentEngine.getFactory().getEngineVersion());

            if (engineVer <= existentEngVer) {
              continue;
            }
          }

          reg = true;
          _nameEngines.put(name, engine);
        }

        if (reg) {
          _log.info(
              "Script Engine: "
                  + factory.getEngineName()
                  + " "
                  + factory.getEngineVersion()
                  + " - Language: "
                  + factory.getLanguageName()
                  + " - Language Version: "
                  + factory.getLanguageVersion());
        }

        for (String ext : factory.getExtensions()) {
          if (!ext.equals("java") || factory.getLanguageName().equals("java")) {
            _extEngines.put(ext, engine);
          }
        }
      } catch (Exception e) {
        _log.warn("Failed initializing factory. ");
        e.printStackTrace();
      }
    }

    preConfigure();
  }
コード例 #3
0
  public String getHelpText() {
    StringBuilder helpText =
        new StringBuilder(
            "Custom message content generated from a script using JSR 223. "
                + "Custom scripts should be placed in "
                + "$JENKINS_HOME/"
                + EMAIL_TEMPLATES_DIRECTORY
                + ". When using custom scripts, "
                + "the script filename WITH .py/.rb/etc	should be used for "
                + "the \""
                + SCRIPT_NAME_ARG
                + "\" argument.\n"
                + "templates and other items may be loaded using the\n"
                + "host.readFile(String fileName) function\n"
                + "the function will look in the resources for\n"
                + "the email-ext plugin first, and then in the $JENKINS_HOME/"
                + EMAIL_TEMPLATES_DIRECTORY
                + "\n"
                + "directory. No other directories will be searched.\n"
                + "<ul>\n"
                + "<li><i>"
                + SCRIPT_NAME_ARG
                + "</i> - the script name.<br>\n"
                + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Defaults to \""
                + DEFAULT_SCRIPT_NAME
                + "\".</li>\n"
                + "<li><i>"
                + SCRIPT_TEMPLATE_ARG
                + "</i> - the template filename.<br>\n"
                + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Defaults to \""
                + DEFAULT_TEMPLATE_NAME
                + "\"</li>\n"
                + "<li><i>"
                + SCRIPT_INIT_ARG
                + "</i> - true to run the language's init script.<br>\n"
                + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Defaults to "
                + DEFAULT_INIT_VALUE
                + "</li>\n"
                + "<li>Available Script Engines\n"
                + "<ul>\n");

    for (ScriptEngineFactory fact : scriptEngineManager.getEngineFactories()) {
      String extensions = join(fact.getExtensions(), ",");
      helpText.append(
          "<li><i>"
              + fact.getLanguageName()
              + "</i> - "
              + fact.getLanguageVersion()
              + " ("
              + extensions
              + ")</li>\n");
    }
    helpText.append("</ul></ul>\n");
    return helpText.toString();
  }
コード例 #4
0
  public void printInfo() {
    ScriptEngineManager mgr = new ScriptEngineManager();
    List<ScriptEngineFactory> factories = mgr.getEngineFactories();

    for (ScriptEngineFactory factory : factories) {
      System.out.println("ScriptEngineFactory Info");
      String engName = factory.getEngineName();
      String engVersion = factory.getEngineVersion();
      String langName = factory.getLanguageName();
      String langVersion = factory.getLanguageVersion();
      System.out.printf("\tScript Engine: %s (%s)\n", engName, engVersion);
      List<String> engNames = factory.getNames();
      for (String name : engNames) {
        System.out.printf("\tEngine Alias: %s\n", name);
      }
      System.out.printf("\tLanguage: %s (%s)\n", langName, langVersion);
    }
  }
コード例 #5
0
ファイル: ScriptingWindow.java プロジェクト: ryancar/OmegaT
  private StringBuilder listScriptEngine() {
    StringBuilder sb = new StringBuilder(OStrings.getString("SCW_LIST_ENGINES") + "\n");
    for (ScriptEngineFactory engine : manager.getEngineFactories()) {
      sb.append(" - ");
      sb.append(engine.getEngineName());
      sb.append(" ");
      sb.append(engine.getLanguageName());
      sb.append(" v.");
      sb.append(engine.getLanguageVersion());
      sb.append(" (").append(OStrings.getString("SCW_EXTENSIONS")).append(" ");
      boolean hasMore = false;
      for (String ext : engine.getExtensions()) {
        if (hasMore) {
          sb.append(", ");
        }
        sb.append(ext);
        hasMore = true;
      }
      sb.append(")");
      sb.append("\n");
    }

    return sb;
  }
コード例 #6
0
  /**
   * Unbinds a ScriptEngineFactory.
   *
   * @param factory the script engine factory to unbind
   */
  protected void unbindScriptEngineFactory(ScriptEngineFactory factory) {
    String language = factory.getLanguageName();
    String languageVersion = factory.getLanguageVersion();

    removeScriptEngineFactory(new ScriptLanguageDescription(language, languageVersion), factory);
  }
コード例 #7
0
 @Override
 public String getLanguageVersion() {
   return factory.getLanguageVersion();
 }