use of javax.script.ScriptEngineManager in project sass-maven-plugin by Jasig.
the class AbstractSassMojo method executeSassScript.
/**
* Execute the SASS Compilation Ruby Script
*/
protected void executeSassScript(String sassScript) throws MojoExecutionException, MojoFailureException {
final Log log = this.getLog();
System.setProperty("org.jruby.embed.localcontext.scope", "threadsafe");
log.debug("Execute SASS Ruby Script:\n" + sassScript);
final ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
final ScriptEngine jruby = scriptEngineManager.getEngineByName("jruby");
try {
CompilerCallback compilerCallback = new CompilerCallback(log);
jruby.getBindings(ScriptContext.ENGINE_SCOPE).put("compiler_callback", compilerCallback);
jruby.eval(sassScript);
if (failOnError && compilerCallback.hadError()) {
throw new MojoFailureException("SASS compilation encountered errors (see above for details).");
}
} catch (final ScriptException e) {
throw new MojoExecutionException("Failed to execute SASS ruby script:\n" + sassScript, e);
}
}
use of javax.script.ScriptEngineManager in project spring-framework by spring-projects.
the class ScriptTemplateView method createEngineFromName.
protected ScriptEngine createEngineFromName() {
if (this.scriptEngineManager == null) {
this.scriptEngineManager = new ScriptEngineManager(getApplicationContext().getClassLoader());
}
ScriptEngine engine = StandardScriptUtils.retrieveEngineByName(this.scriptEngineManager, this.engineName);
loadScripts(engine);
return engine;
}
use of javax.script.ScriptEngineManager in project groovy by apache.
the class JSR223SpecTest method testSimpleExample.
@Test
public void testSimpleExample() throws ScriptException {
// tag::jsr223_init[]
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("groovy");
// end::jsr223_init[]
// tag::jsr223_basic[]
Integer sum = (Integer) engine.eval("(1..10).sum()");
assertEquals(new Integer(55), sum);
// end::jsr223_basic[]
// tag::jsr223_variables[]
engine.put("first", "HELLO");
engine.put("second", "world");
String result = (String) engine.eval("first.toLowerCase() + ' ' + second.toUpperCase()");
assertEquals("hello WORLD", result);
// end::jsr223_variables[]
}
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;
}
use of javax.script.ScriptEngineManager in project java8-tutorial by winterbe.
the class Nashorn1 method main.
public static void main(String[] args) throws Exception {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
engine.eval(new FileReader("res/nashorn1.js"));
Invocable invocable = (Invocable) engine;
Object result = invocable.invokeFunction("fun1", "Peter Parker");
System.out.println(result);
System.out.println(result.getClass());
invocable.invokeFunction("fun2", new Date());
invocable.invokeFunction("fun2", LocalDateTime.now());
invocable.invokeFunction("fun2", new Person());
}
Aggregations