List of usage examples for javax.script ScriptEngineManager ScriptEngineManager
public ScriptEngineManager()
ScriptEngineManager(Thread.currentThread().getContextClassLoader())
. From source file:tk.elevenk.restfulrobot.testsuite.TestSuite.java
public TestSuite(String name, String baseURL, ArrayList<TestCase> testCases) { this.testCases = testCases; this.baseURL = baseURL; this.name = name; this.engine = new ScriptEngineManager().getEngineByName("javascript"); this.dataPool = new DataPool(); this.reporter = Reporter.getInstance(); }
From source file:org.pentaho.platform.plugin.condition.scriptable.ScriptableCondition.java
public void setListAvailableEngines(final boolean value) { this.listAvailableEngines = value; if (value) {/*from w w w .j ava 2 s . c o m*/ System.out.println("*** DEBUG - Display Script Engine List ***"); ScriptEngineManager manager = new ScriptEngineManager(); List<ScriptEngineFactory> factories = manager.getEngineFactories(); for (ScriptEngineFactory factory : factories) { System.out.println(String.format("Engine %s, Version %s, Language %s, Registered Names: %s", factory.getEngineName(), factory.getEngineVersion(), factory.getLanguageName(), factory.getNames().toString())); } } }
From source file:cc.osint.graphd.script.GScriptEngine.java
public void dumpScriptEngines() throws Exception { ScriptEngineManager mgr = new ScriptEngineManager(); List<ScriptEngineFactory> factories = mgr.getEngineFactories(); for (ScriptEngineFactory factory : factories) { log.info("ScriptEngineFactory Info"); String engName = factory.getEngineName(); String engVersion = factory.getEngineVersion(); String langName = factory.getLanguageName(); String langVersion = factory.getLanguageVersion(); System.out.printf("\tScript Engine: %s (%s)\n", engName, engVersion); List<String> engNames = factory.getNames(); for (String name : engNames) { System.out.printf("\tEngine Alias: %s\n", name); }/* w ww . j av a 2s. c o m*/ System.out.printf("\tLanguage: %s (%s)\n", langName, langVersion); } }
From source file:uk.co.gidley.jmxmonitor.monitoring.MonitoringGroup.java
public MonitoringGroup() { monitorsConfiguration.setThrowExceptionOnMissing(true); expressionsConfiguration.setThrowExceptionOnMissing(true); scriptEngineManager = new ScriptEngineManager(); }
From source file:org.nuxeo.ecm.webengine.scripting.Scripting.java
/** * Lazy init scripting manager to avoid loading script engines when * no scripting is used./*from w w w .j ava 2s . co m*/ * <p> * Javax Scripting is not used by default in WebWengine, * we are using directly the Groovy engine. * This also fixes an annoying pb on Mac in java5 due to AppleScripting * which is failing to register. * * @return the scriptMgr */ public ScriptEngineManager getEngineManager() { if (scriptMgr == null) { scriptMgr = new ScriptEngineManager(); } return scriptMgr; }
From source file:edu.dfci.cccb.mev.deseq.domain.cli.CliRDESeqTest.java
@Test @Ignore//from w ww . j a v a2s . co m public void test() throws Exception { try (InputStream inp = getClass().getResourceAsStream("/test_data.tsv"); ByteArrayOutputStream copy = new ByteArrayOutputStream()) { IOUtils.copy(inp, copy); Dataset dataset = new SimpleDatasetBuilder().setParserFactories(asList(new SuperCsvParserFactory())) .setValueStoreBuilder(new MapBackedValueStoreBuilder()) .build(new MockTsvInput("mock", copy.toString())); Selection experiment = new SimpleSelection("experiment", new Properties(), asList("SA1_06_25_14", "SA2_06_25_14", "SA3_06_25_14", "SA4_006_25_14", "SA5_06_25_14")); Selection control = new SimpleSelection("control", new Properties(), asList("SA10-06-25-14", "SA11_06_25_14", "SA12_06_25_14")); dataset.dimension(COLUMN).selections().put(experiment); dataset.dimension(COLUMN).selections().put(control); DESeq result = new StatelessScriptEngineFileBackedDESeqBuilder() .r(new ScriptEngineManager().getEngineByName("CliR")) .composerFactory(new SuperCsvComposerFactory()).dataset(dataset).control(control) .experiment(experiment).build(); for (Entry e : result.full()) log.debug("Full DESeq entry: " + e); } }
From source file:org.jumpmind.metl.core.runtime.component.Script.java
@Override protected void start() { String importStatements = getComponent().get(IMPORTS); String initScript = getComponent().get(INIT_SCRIPT); String handleMessageScript = getComponent().get(HANDLE_SCRIPT); String methods = getComponent().get(METHODS); String onSuccess = getComponent().get(ON_FLOW_SUCCESS); String onError = getComponent().get(ON_FLOW_ERROR); ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("groovy"); engine.put("component", this); StringBuilder script = new StringBuilder(); try {/*from w w w. ja va2 s . c om*/ script.append(String.format("import %s;\n", ISendMessageCallback.class.getName())); script.append(String.format("import %s;\n", File.class.getName())); script.append(String.format("import %s;\n", FileUtils.class.getName())); script.append(String.format("import static %s.*;\n", FileUtils.class.getName())); script.append(String.format("import %s.*;\n", Message.class.getPackage().getName())); script.append(String.format("import %s;\n", ScriptHelper.class.getName())); script.append(String.format("import %s;\n", EntityDataMessage.class.getName())); script.append(String.format("import %s;\n", TextMessage.class.getName())); script.append(String.format("import %s;\n", ControlMessage.class.getName())); script.append(String.format("import %s;\n", BinaryMessage.class.getName())); script.append(String.format("import %s;\n", MisconfiguredException.class.getName())); script.append(String.format("import %s;\n", AssertException.class.getName())); script.append( String.format("import %s.%s;\n", EntityData.class.getName(), ChangeType.class.getSimpleName())); script.append("import org.jumpmind.db.sql.*;\n"); if (isNotBlank(importStatements)) { script.append(importStatements); } script.append("\n"); script.append(String.format("helper = new %1$s(component) { \n", ScriptHelper.class.getSimpleName())); if (isNotBlank(methods)) { script.append("\n"); script.append(String.format("%s\n", methods)); } if (isNotBlank(initScript)) { script.append("\n"); script.append(String.format(" protected void onInit() { %s \n} \n", initScript)); } if (isNotBlank(handleMessageScript)) { script.append("\n"); script.append(String.format(" protected void onHandle() { %s \n} \n", handleMessageScript)); } if (isNotBlank(onSuccess)) { script.append("\n"); script.append(String.format(" protected void onSuccess() { %s \n} \n", onSuccess)); } if (isNotBlank(onError)) { script.append("\n"); script.append(String.format(" protected void onError(Throwable myError) { %s \n} \n", onError)); } script.append("\n};\n"); log(LogLevel.DEBUG, script.toString()); script.append("helper.onInit();"); engine.eval(script.toString()); this.engine = engine; } catch (ScriptException e) { Throwable rootCause = ExceptionUtils.getRootCause(e); if (rootCause != null) { if (rootCause instanceof RuntimeException) { throw (RuntimeException) rootCause; } else { throw new RuntimeException(rootCause); } } else { throw new RuntimeException(e); } } }
From source file:io.lavagna.service.ApiHooksService.java
public ApiHooksService(ProjectService projectService, CardService cardService, ApiHookQuery apiHookQuery, LabelService labelService, UserService userService, ConfigurationRepository configurationRepository) { this.projectService = projectService; this.cardService = cardService; this.apiHookQuery = apiHookQuery; this.labelService = labelService; this.userService = userService; this.configurationRepository = configurationRepository; engine = (Compilable) new ScriptEngineManager().getEngineByName("javascript"); executor = Executors.newFixedThreadPool(4); }
From source file:JrubyTest.java
/** * //from w w w . j a v a 2 s .c o m */ @Test public void repeatedTitle() throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("jruby"); Reader scriptReader = null; InputStream in = null; try { in = getClass().getClassLoader().getResourceAsStream("test-specifications.xls"); Workbook workbook = load(in); Book book = new Book(workbook); scriptReader = new InputStreamReader( getClass().getClassLoader().getResourceAsStream("test-specification-repeated-title.rb")); if (engine instanceof Compilable) { CompiledScript script = ((Compilable) engine).compile(scriptReader); SimpleBindings bindings = new SimpleBindings(); bindings.put("@book", book); script.eval(bindings); } } finally { IOUtils.closeQuietly(scriptReader); IOUtils.closeQuietly(in); } }
From source file:org.jumpmind.metl.core.runtime.component.Transformer.java
@Override public void handle(Message inputMessage, ISendMessageCallback callback, boolean unitOfWorkBoundaryReached) { if (scriptEngine == null) { ScriptEngineManager factory = new ScriptEngineManager(); scriptEngine = factory.getEngineByName("groovy"); }// www .java 2s . com totalTime = 0; if (inputMessage instanceof EntityDataMessage) { Model inputModel = getComponent().getInputModel(); List<EntityData> inDatas = ((EntityDataMessage) inputMessage).getPayload(); ArrayList<EntityData> outDatas = new ArrayList<EntityData>(inDatas != null ? inDatas.size() : 0); if (inDatas != null) { for (EntityData inData : inDatas) { EntityData outData = new EntityData(); outData.setChangeType(inData.getChangeType()); outDatas.add(outData); Set<String> attributeIds = new HashSet<String>(); Set<ModelEntity> processedEntities = new HashSet<ModelEntity>(); for (String attributeId : inData.keySet()) { ModelAttribute attribute = inputModel.getAttributeById(attributeId); if (attribute != null) { ModelEntity entity = inputModel.getEntityById(attribute.getEntityId()); if (entity != null && !processedEntities.contains(entity)) { List<ModelAttribute> attributes = entity.getModelAttributes(); for (ModelAttribute modelAttribute : attributes) { attributeIds.add(modelAttribute.getId()); } processedEntities.add(entity); } } } for (String attributeId : attributeIds) { String transform = transformsByAttributeId.get(attributeId); Object value = inData.get(attributeId); if (isNotBlank(transform)) { ModelAttribute attribute = inputModel.getAttributeById(attributeId); ModelEntity entity = inputModel.getEntityById(attribute.getEntityId()); ModelAttributeScriptHelper helper = helpers.get(attribute.getId()); if (helper == null) { long ts = System.currentTimeMillis(); scriptEngine.put("entity", entity); scriptEngine.put("attribute", attribute); scriptEngine.put("context", context); try { String importString = "import org.jumpmind.metl.core.runtime.component.ModelAttributeScriptHelper;\n"; String code = String.format( "return new ModelAttributeScriptHelper(context, attribute, entity) { public Object eval() { return %s } }", transform); helper = (ModelAttributeScriptHelper) scriptEngine.eval(importString + code); helpers.put(attribute.getId(), helper); } catch (ScriptException e) { throw new RuntimeException("Unable to evaluate groovy script. Attribute ==> " + attribute.getName() + ". Value ==> " + value.toString() + "." + e.getCause().getMessage(), e); } log.debug("It took " + (System.currentTimeMillis() - ts) + "ms to create class"); } helper.setData(inData); helper.setValue(value); helper.setMessage(inputMessage); long ts = System.currentTimeMillis(); value = helper.eval(); totalTime += (System.currentTimeMillis() - ts); totalCalls++; } if (value != ModelAttributeScriptHelper.REMOVE_ATTRIBUTE) { outData.put(attributeId, value); } } getComponentStatistics().incrementNumberEntitiesProcessed(threadNumber); } } callback.sendEntityDataMessage(null, outDatas); if (totalCalls > 0) { log.debug("It took " + (totalTime / totalCalls) + "ms on average to call eval"); } } else if (inputMessage instanceof ControlMessage) { callback.sendControlMessage(); } }