use of javax.script.ScriptEngineFactory in project intellij-community by JetBrains.
the class JavaFxInjectPageLanguageIntention method getAvailableLanguages.
public static Set<String> getAvailableLanguages(Project project) {
final List<ScriptEngineFactory> engineFactories = new ScriptEngineManager(composeUserClassLoader(project)).getEngineFactories();
if (engineFactories != null) {
final Set<String> availableNames = new TreeSet<>();
for (ScriptEngineFactory factory : engineFactories) {
final String engineName = (String) factory.getParameter(ScriptEngine.NAME);
availableNames.add(engineName);
}
return availableNames;
}
return null;
}
use of javax.script.ScriptEngineFactory in project lucene-solr by apache.
the class StatelessScriptUpdateProcessorFactory method getSupportedEngines.
/**
* For error messages - returns null if there are any exceptions of any
* kind building the string (or of the list is empty for some unknown reason).
* @param ext - if true, list of extensions, otherwise a list of engine names
*/
private static String getSupportedEngines(ScriptEngineManager mgr, boolean ext) {
String result = null;
try {
List<ScriptEngineFactory> factories = mgr.getEngineFactories();
if (null == factories)
return result;
Set<String> engines = new LinkedHashSet<>(factories.size());
for (ScriptEngineFactory f : factories) {
if (ext) {
engines.addAll(f.getExtensions());
} else {
engines.addAll(f.getNames());
}
}
result = StringUtils.join(engines, ", ");
} catch (RuntimeException e) {
/* :NOOP: */
}
return result;
}
use of javax.script.ScriptEngineFactory in project tomee by apache.
the class OpenEJBScripter method engine.
private static ScriptEngine engine(final String language) {
ScriptEngine engine = ENGINES.get().get(language);
if (engine == null) {
final ScriptEngineFactory factory = ENGINE_FACTORIES.get(language);
engine = factory.getScriptEngine();
ENGINES.get().put(language, engine);
}
return engine;
}
use of javax.script.ScriptEngineFactory in project sling by apache.
the class ScriptConsolePlugin method getScriptConfig0.
private String getScriptConfig0() throws IOException {
StringWriter sw = new StringWriter();
JSONWriter jw = new JSONWriter(sw);
jw.array();
for (ScriptEngineFactory sef : scriptEngineManager.getEngineFactories()) {
jw.object();
if (sef.getExtensions().isEmpty()) {
continue;
}
jw.key("langName").value(sef.getLanguageName());
jw.key("langCode").value(sef.getExtensions().get(0));
//Language mode as per CodeMirror names
String mode = determineMode(sef.getExtensions());
if (mode != null) {
jw.key("mode").value(mode);
}
jw.endObject();
}
jw.endArray();
return sw.toString();
}
use of javax.script.ScriptEngineFactory in project jqa-core-framework by buschmais.
the class AnalyzerVisitor method executeScript.
/**
* Execute an analysis script
*
* @param <T>
* The result type.
* @param scriptExecutable
* The script.
* @param ruleParameters
* @param severity
* The severity. @return The result.
* @throws RuleExecutorException
* If script execution fails.
*/
private <T extends ExecutableRule> Result<T> executeScript(T executable, ScriptExecutable scriptExecutable, Map<String, Object> ruleParameters, Severity severity) throws RuleExecutorException {
String language = scriptExecutable.getLanguage();
ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(language);
if (scriptEngine == null) {
List<String> availableLanguages = new ArrayList<>();
for (ScriptEngineFactory factory : scriptEngineManager.getEngineFactories()) {
availableLanguages.addAll(factory.getNames());
}
throw new RuleExecutorException("Cannot resolve scripting engine for '" + language + "', available languages are " + availableLanguages);
}
// Set default variables
scriptEngine.put(ScriptVariable.STORE.getVariableName(), store);
scriptEngine.put(ScriptVariable.RULE.getVariableName(), executable);
scriptEngine.put(ScriptVariable.SEVERITY.getVariableName(), severity);
// Set rule parameters
for (Map.Entry<String, Object> entry : ruleParameters.entrySet()) {
scriptEngine.put(entry.getKey(), entry.getValue());
}
Object scriptResult;
try {
scriptResult = scriptEngine.eval(scriptExecutable.getSource());
} catch (ScriptException e) {
throw new RuleExecutorException("Cannot execute script.", e);
}
if (!(scriptResult instanceof Result)) {
throw new RuleExecutorException("Script returned an invalid result type, expected " + Result.class.getName() + " but got " + scriptResult);
}
return Result.class.cast(scriptResult);
}
Aggregations