Search in sources :

Example 21 with ScriptEngineFactory

use of javax.script.ScriptEngineFactory in project hazelcast by hazelcast.

the class HazelcastOSGiScriptEngineTest method putAndGetOverBindingsSuccessfully.

@Test
public void putAndGetOverBindingsSuccessfully() {
    ScriptEngineManager scriptEngineManager = ScriptEngineManagerContext.getScriptEngineManager();
    List<ScriptEngineFactory> engineFactories = scriptEngineManager.getEngineFactories();
    assertNotNull(engineFactories);
    for (ScriptEngineFactory engineFactory : engineFactories) {
        verifyThatBindingsPutAndGetOverBindingsSuccessfully(engineFactory.getScriptEngine());
    }
}
Also used : ScriptEngineFactory(javax.script.ScriptEngineFactory) GroovyScriptEngineFactory(org.codehaus.groovy.jsr223.GroovyScriptEngineFactory) ScriptEngineManager(javax.script.ScriptEngineManager) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with ScriptEngineFactory

use of javax.script.ScriptEngineFactory in project hazelcast by hazelcast.

the class HazelcastOSGiScriptEngineTest method bindingsGetAndSetSuccessfully.

@Test
public void bindingsGetAndSetSuccessfully() {
    ScriptEngineManager scriptEngineManager = ScriptEngineManagerContext.getScriptEngineManager();
    List<ScriptEngineFactory> engineFactories = scriptEngineManager.getEngineFactories();
    assertNotNull(engineFactories);
    for (ScriptEngineFactory engineFactory : engineFactories) {
        verifyThatBindingsGetAndSetSuccessfully(engineFactory.getScriptEngine());
    }
}
Also used : ScriptEngineFactory(javax.script.ScriptEngineFactory) GroovyScriptEngineFactory(org.codehaus.groovy.jsr223.GroovyScriptEngineFactory) ScriptEngineManager(javax.script.ScriptEngineManager) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with ScriptEngineFactory

use of javax.script.ScriptEngineFactory in project camel by apache.

the class ActivatorTest method findScriptEngines.

@Test
public void findScriptEngines() throws IOException {
    Enumeration<URL> urls = getClass().getClassLoader().getResources(Activator.META_INF_SERVICES_DIR + "/" + Activator.SCRIPT_ENGINE_SERVICE_FILE);
    assertThat(urls.hasMoreElements(), is(true));
    while (urls.hasMoreElements()) {
        URL url = urls.nextElement();
        LOG.info("Found {}", url);
        System.out.println("Found: " + url);
        Activator.BundleScriptEngineResolver resolver = new Activator.BundleScriptEngineResolver(mockBundle, url);
        ScriptEngineFactory factory = ReflectionTestUtils.invokeMethod(resolver, "getFactory");
        System.out.println("Factory: " + factory);
        assertNotNull(factory);
    }
}
Also used : ScriptEngineFactory(javax.script.ScriptEngineFactory) URL(java.net.URL) Test(org.junit.Test)

Example 24 with ScriptEngineFactory

use of javax.script.ScriptEngineFactory in project spring-framework by spring-projects.

the class StandardScriptUtils method retrieveEngineByName.

/**
	 * Retrieve a {@link ScriptEngine} from the given {@link ScriptEngineManager}
	 * by name, delegating to {@link ScriptEngineManager#getEngineByName} but
	 * throwing a descriptive exception if not found or if initialization failed.
	 * @param scriptEngineManager the ScriptEngineManager to use
	 * @param engineName the name of the engine
	 * @return a corresponding ScriptEngine (never {@code null})
	 * @throws IllegalArgumentException if no matching engine has been found
	 * @throws IllegalStateException if the desired engine failed to initialize
	 */
public static ScriptEngine retrieveEngineByName(ScriptEngineManager scriptEngineManager, String engineName) {
    ScriptEngine engine = scriptEngineManager.getEngineByName(engineName);
    if (engine == null) {
        Set<String> engineNames = new LinkedHashSet<>();
        for (ScriptEngineFactory engineFactory : scriptEngineManager.getEngineFactories()) {
            List<String> factoryNames = engineFactory.getNames();
            if (factoryNames.contains(engineName)) {
                // If it happens to initialize fine now, alright, but we really expect an exception.
                try {
                    engine = engineFactory.getScriptEngine();
                    engine.setBindings(scriptEngineManager.getBindings(), ScriptContext.GLOBAL_SCOPE);
                } catch (Throwable ex) {
                    throw new IllegalStateException("Script engine with name '" + engineName + "' failed to initialize", ex);
                }
            }
            engineNames.addAll(factoryNames);
        }
        throw new IllegalArgumentException("Script engine with name '" + engineName + "' not found; registered engine names: " + engineNames);
    }
    return engine;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ScriptEngineFactory(javax.script.ScriptEngineFactory) ScriptEngine(javax.script.ScriptEngine)

Example 25 with ScriptEngineFactory

use of javax.script.ScriptEngineFactory in project zaproxy by zaproxy.

the class ExtensionScript method getEngineWrapper.

public ScriptEngineWrapper getEngineWrapper(String name) {
    for (ScriptEngineWrapper sew : this.engineWrappers) {
        if (isSameScriptEngine(name, sew.getEngineName(), sew.getLanguageName())) {
            return sew;
        }
    }
    // Not one we know of, create a default wrapper
    List<ScriptEngineFactory> engines = mgr.getEngineFactories();
    ScriptEngine engine = null;
    for (ScriptEngineFactory e : engines) {
        if (isSameScriptEngine(name, e.getEngineName(), e.getLanguageName())) {
            engine = e.getScriptEngine();
            break;
        }
    }
    if (engine != null) {
        DefaultEngineWrapper dew = new DefaultEngineWrapper(engine);
        this.registerScriptEngineWrapper(dew);
        return dew;
    }
    throw new InvalidParameterException("No such engine: " + name);
}
Also used : InvalidParameterException(java.security.InvalidParameterException) ScriptEngineFactory(javax.script.ScriptEngineFactory) ScriptEngine(javax.script.ScriptEngine)

Aggregations

ScriptEngineFactory (javax.script.ScriptEngineFactory)30 ScriptEngineManager (javax.script.ScriptEngineManager)11 ScriptEngine (javax.script.ScriptEngine)9 Test (org.junit.Test)9 QuickTest (com.hazelcast.test.annotation.QuickTest)8 GroovyScriptEngineFactory (org.codehaus.groovy.jsr223.GroovyScriptEngineFactory)8 ArrayList (java.util.ArrayList)4 URL (java.net.URL)2 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 JSONWriter (org.apache.felix.utils.json.JSONWriter)2 Result (com.buschmais.jqassistant.core.analysis.api.Result)1 RuleExecutorException (com.buschmais.jqassistant.core.rule.api.executor.RuleExecutorException)1 OSQLScriptEngineFactory (com.orientechnologies.orient.core.sql.OSQLScriptEngineFactory)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1