Esempio n. 1
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();
  }
Esempio n. 2
0
  private List<String> getAvailableScriptExtensions() {
    ArrayList<String> extensions = new ArrayList<String>();
    for (ScriptEngineFactory engine : manager.getEngineFactories()) {
      for (String ext : engine.getExtensions()) {
        extensions.add(ext);
      }
    }

    return extensions;
  }
  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();
  }
Esempio n. 4
0
  public ObjectPanel(ClientModel model) {
    super(model);

    model.addObjectListener(this);

    // get all installed script engines
    scriptExtensions = new HashSet<String>();
    ScriptEngineManager mgr = new ScriptEngineManager();
    for (ScriptEngineFactory sef : mgr.getEngineFactories()) {
      scriptExtensions.addAll(sef.getExtensions());
    }

    createGUI();
  }
Esempio n. 5
0
 /** The Script Engine used to evaluate the script. */
 protected ScriptEngine createScriptEngine() {
   for (ScriptEngineFactory factory : new ScriptEngineManager().getEngineFactories()) {
     for (String name : factory.getNames()) {
       if (name.equalsIgnoreCase(scriptEngineLookup)) {
         return factory.getScriptEngine();
       }
     }
     for (String ext : factory.getExtensions()) {
       String scriptEngineLookupLowercase = scriptEngineLookup.toLowerCase();
       if (scriptEngineLookupLowercase.endsWith(ext.toLowerCase())) {
         return factory.getScriptEngine();
       }
     }
   }
   return null;
 }
Esempio n. 6
0
  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;
  }
 @Override
 public List<String> getExtensions() {
   return factory.getExtensions();
 }