Search in sources :

Example 66 with ScriptEngineManager

use of javax.script.ScriptEngineManager 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;
}
Also used : ScriptEngineFactory(javax.script.ScriptEngineFactory) ScriptEngineManager(javax.script.ScriptEngineManager)

Example 67 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project bytecode-viewer by Konloch.

the class GroovyPluginLaunchStrategy method run.

@Override
public Plugin run(File file) throws Throwable {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("groovy");
    if (engine == null)
        throw new Exception("Cannot find Groovy script engine! Please contact Konloch.");
    Reader reader = new FileReader(file);
    engine.eval(reader);
    return (Plugin) engine.eval("new " + file.getName().replace(".gy", "").replace(".groovy", "") + "();");
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) FileReader(java.io.FileReader) Reader(java.io.Reader) FileReader(java.io.FileReader) ScriptEngine(javax.script.ScriptEngine) Plugin(the.bytecode.club.bytecodeviewer.api.Plugin)

Example 68 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project bytecode-viewer by Konloch.

the class PythonPluginLaunchStrategy method run.

@Override
public Plugin run(File file) throws Throwable {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("python");
    if (engine == null)
        throw new Exception("Cannot find Jython script engine! Please contact Konloch.");
    Reader reader = new FileReader(file);
    engine.eval(reader);
    return (Plugin) engine.eval(file.getName().replace(".py", "").replace(".python", "") + "()");
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) FileReader(java.io.FileReader) Reader(java.io.Reader) FileReader(java.io.FileReader) ScriptEngine(javax.script.ScriptEngine) Plugin(the.bytecode.club.bytecodeviewer.api.Plugin)

Example 69 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project bytecode-viewer by Konloch.

the class RubyPluginLaunchStrategy method run.

@Override
public Plugin run(File file) throws Throwable {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("jruby");
    if (engine == null)
        throw new Exception("Cannot find jRuby script engine! Please contact Konloch.");
    Reader reader = new FileReader(file);
    engine.eval(reader);
    return (Plugin) engine.eval(file.getName().replace(".rb", "").replace(".ruby", "") + ".new");
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) FileReader(java.io.FileReader) Reader(java.io.Reader) FileReader(java.io.FileReader) ScriptEngine(javax.script.ScriptEngine) Plugin(the.bytecode.club.bytecodeviewer.api.Plugin)

Example 70 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project yyl_example by Relucent.

the class BindingsScript method main.

public static void main(String[] args) {
    try {
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
        String script = "print('hello')";
        Bindings bindings = new SimpleBindings();
        if (engine instanceof Compilable) {
            System.out.println("Compiling....");
            Compilable compEngine = (Compilable) engine;
            CompiledScript cs = compEngine.compile(script);
            cs.eval(bindings);
        } else {
            engine.eval(script, bindings);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : CompiledScript(javax.script.CompiledScript) SimpleBindings(javax.script.SimpleBindings) Compilable(javax.script.Compilable) ScriptEngineManager(javax.script.ScriptEngineManager) SimpleBindings(javax.script.SimpleBindings) Bindings(javax.script.Bindings) ScriptEngine(javax.script.ScriptEngine)

Aggregations

ScriptEngineManager (javax.script.ScriptEngineManager)84 ScriptEngine (javax.script.ScriptEngine)46 Test (org.junit.Test)19 ScriptException (javax.script.ScriptException)15 ScriptEngineFactory (javax.script.ScriptEngineFactory)11 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Invocable (javax.script.Invocable)10 IOException (java.io.IOException)8 GroovyScriptEngineFactory (org.codehaus.groovy.jsr223.GroovyScriptEngineFactory)8 Before (org.junit.Before)8 FileReader (java.io.FileReader)7 File (java.io.File)6 Reader (java.io.Reader)6 Bindings (javax.script.Bindings)6 Map (java.util.Map)5 HashMap (java.util.HashMap)3 SimpleBindings (javax.script.SimpleBindings)3 NashornScriptEngine (jdk.nashorn.api.scripting.NashornScriptEngine)3 Plugin (the.bytecode.club.bytecodeviewer.api.Plugin)3 Person (com.winterbe.java8.samples.lambda.Person)2