public int getNumberOfBricks() { int brickCount = 0; for (Script s : scriptList) { brickCount += s.getBrickList().size(); } return brickCount; }
static void showScript(String fname) { try { ESParser parser = new ESParser(fname); Script script = parser.parse(); PrintWriter pw = new PrintWriter(System.out, true); pw.println("------------------ script AST:"); script.dump(pw); pw.println("------------------ generated CG sequence:"); StringSetGenerator p = new StringSetGenerator(); script.process(p); LinkedHashMap<String, ArrayList<CG>> sections = p.getSections(); for (Map.Entry<String, ArrayList<CG>> e : sections.entrySet()) { ArrayList<CG> queue = e.getValue(); System.out.println(e.getKey() + " {"); for (CG cg : queue) { System.out.print(" "); System.out.println(cg); } System.out.println("}"); System.out.println(); } /** * this only shows the last section List<CG> queue = p.getCGQueue(); for (CG cg : queue) { * System.out.println(cg); } */ } catch (Throwable t) { t.printStackTrace(); } }
private Script getInitScript(SimpleJdbcTemplate template) { Script script = new Script(); for (ChangeSet changeSet : changeSets) { script.append(markAsApplied(changeSet, template)); } return script; }
/** Initializes the script, loading any required dependencies and running the script. */ private void init() { int repos = 0; for (String repo : script.getHeaders("m2repo")) { Map<String, Object> args = Maps.newHashMap(); args.put("name", "repo_" + repos++); args.put("root", repo); args.put("m2compatible", true); Grape.addResolver(args); } for (String dependency : script.getHeaders("dependency")) { String[] parts = dependency.split(":"); if (parts.length >= 3) classLoader.loadDependency(parts[0], parts[1], parts[2]); } ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(classLoader); Script groovyScript = shell.parse(script.getBody(), scriptName); binding.setProperty("log", log); groovyScript.setMetaClass(new ScriptMetaClass(groovyScript.getMetaClass())); groovyScript.setBinding(binding); groovyScript.run(); } catch (CompilationFailedException e) { log.error("Compilation of Groovy script failed: ", e); throw new RuntimeException("Compilation of Groovy script failed", e); } finally { Thread.currentThread().setContextClassLoader(cl); } }
public ClientWriter id(String id, Script... s) throws IOException { if (s == null) return this; for (Script i : s) { i.write(this.getBuffer().append("$('").append(id).append("')").toString(), this); } return this; }
@Override public void reload() { // テーブルヘッダは起動中変更できないので、ファイルは増減させない for (Script script : this.get()) { script.reload(); } }
// find the scripts currently registered for this agent to be run. public void updateSensors(GenericVillager agent) { // get the iterator for this agents scripts Iterator<Script> itr = agent.getSensorScripts().iterator(); bindProxy(agent); while (itr.hasNext()) { Script currentScript = (Script) itr.next(); ArrayList<String> functionsToCall = new ArrayList<String>(); if (currentScript.status == Script.NEW) { functionsToCall.add("onStartSensor"); currentScript.status = Script.RUNNING; } if (currentScript.status == Script.STOPPING) { functionsToCall.add("onStopSensor"); } if (currentScript.status == Script.RUNNING) { functionsToCall.add("onUpdateSensor"); } String[] functions = new String[0]; functions = functionsToCall.toArray(functions); try { // debug: this.scriptprocessor.runScript( cache.getScriptByScriptName(currentScript.getScriptLocation()), functions); } catch (NoSuchMethodException e) { System.err.println( "error while executing an script, identifier:" + currentScript.getScriptLocation()); e.printStackTrace(); } catch (ScriptException e) { System.err.println( "error while executing an script, identifier:" + currentScript.getScriptLocation()); e.printStackTrace(); } } }
private Script parseScriptString(String string) throws Exception { String[] words = string.split("[ \\t\\n]"); UnsafeByteArrayOutputStream out = new UnsafeByteArrayOutputStream(); for (String w : words) { if (w.equals("")) continue; if (w.matches("^-?[0-9]*$")) { // Number long val = Long.parseLong(w); if (val >= -1 && val <= 16) out.write(Script.encodeToOpN((int) val)); else Script.writeBytes( out, Utils.reverseBytes(Utils.encodeMPI(BigInteger.valueOf(val), false))); } else if (w.matches("^0x[0-9a-fA-F]*$")) { // Raw hex data, inserted NOT pushed onto stack: out.write(Hex.decode(w.substring(2))); } else if (w.length() >= 2 && w.startsWith("'") && w.endsWith("'")) { // Single-quoted string, pushed as data. NOTE: this is poor-man's // parsing, spaces/tabs/newlines in single-quoted strings won't work. Script.writeBytes(out, w.substring(1, w.length() - 1).getBytes(Charset.forName("UTF-8"))); } else if (ScriptOpCodes.getOpCode(w) != OP_INVALIDOPCODE) { // opcode, e.g. OP_ADD or OP_1: out.write(ScriptOpCodes.getOpCode(w)); } else if (w.startsWith("OP_") && ScriptOpCodes.getOpCode(w.substring(3)) != OP_INVALIDOPCODE) { // opcode, e.g. OP_ADD or OP_1: out.write(ScriptOpCodes.getOpCode(w.substring(3))); } else { throw new RuntimeException("Invalid Data"); } } return new Script(out.toByteArray()); }
@JSClass public final class Storage { public static Storage LOCAL = new Storage(Script.code("localStorage")); public static Storage SESSION = new Storage(Script.code("sessionStorage")); private final Object js; private Storage(Object js) { this.js = js; } public Optional<String> get(String key) { String s = Script.code(js, ".getItem(", key, ")"); Optional<String> res = Optional.ofNullable(s); return res; } public Optional<String> get(int index) { Optional<String> key = getIndexByKey(index); if (key.isPresent()) return get(key.get()); return Optional.empty(); } public Optional<String> remove(String key) { Optional<String> r = get(key); if (r.isPresent()) Script.code(js, ".removeItem(", key, ")"); return r; } public Optional<String> remove(int index) { Optional<String> key = getIndexByKey(index); if (key.isPresent()) return remove(key.get()); return Optional.empty(); } public Optional<String> getIndexByKey(int index) { return Optional.ofNullable(Script.code(js, ".key(", CastUtil.toObject(index), ")")); } public int size() { return CastUtil.toInt(Script.code(js, ".length")); } public Storage set(String key, String value) { Script.code(js, ".setItem(", key, ",", value, ")"); return this; } public Storage set(int index, String value) { Optional<String> key = getIndexByKey(index); if (key.isPresent()) return set(key.get(), value); return this; } public Storage clear() { Script.code(js, ".clear()"); return this; } }
private void cloneScripts(Sprite cloneSprite) { List<Script> cloneScriptList = new ArrayList<>(); for (Script element : this.scriptList) { Script addElement = element.copyScriptForSprite(cloneSprite); cloneScriptList.add(addElement); } cloneSprite.scriptList = cloneScriptList; }
@And("^this script has a BroadcastWait '(\\w+)' brick$") public void script_has_broadcast_wait_brick(String message) { Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT); Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT); BroadcastWaitBrick brick = new BroadcastWaitBrick(message); script.addBrick(brick); }
@And("^this script has a Wait (\\d+) milliseconds brick$") public void script_has_wait_ms_brick(int millis) { Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT); Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT); WaitBrick brick = new WaitBrick(millis); script.addBrick(brick); }
@And("^this script has a Wait (\\d+.?\\d*) seconds? brick$") public void script_has_wait_s_brick(int seconds) { Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT); Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT); WaitBrick brick = new WaitBrick(seconds * 1000); script.addBrick(brick); }
/** * Test method for {@link de.lab4inf.wrb.Script#setVariable(java.lang.String,double)}. and {@link * de.lab4inf.wrb.WRBScript#getVariable(java.lang.String)}. */ @Test public final void testSetGetVariable() throws Exception { double y, x = 2.78; String key = "XYZ"; script.setVariable(key, x); y = script.getVariable(key); assertEquals(x, y, eps); }
@Test public void testScriptStuff() throws Exception { Handle h = openHandle(); Script s = h.createScript("default-data"); s.execute(); assertEquals(2, h.select("select * from something").size()); }
@Override protected void removed(int entityId) { ScriptComponent sc = mScript.get(entityId); for (Script script : sc.scripts) { script.removed(entityId); } sc.scripts.clear(); }
@Test public void testIp() throws Exception { byte[] bytes = Hex.decode( "41043e96222332ea7848323c08116dddafbfa917b8e37f0bdf63841628267148588a09a43540942d58d49717ad3fabfe14978cf4f0a8b84d2435dad16e9aa4d7f935ac"); Script s = new Script(bytes); assertTrue(s.isSentToRawPubKey()); }
@Override public void update() { // テーブルヘッダは起動中変更できないので、ファイルは増減させない for (Script script : this.get()) { if (script.isUpdated()) { script.reload(); } } }
@Test public void testScriptSig() throws Exception { byte[] sigProgBytes = Hex.decode(sigProg); Script script = new Script(sigProgBytes); // Test we can extract the from address. byte[] hash160 = Utils.sha256hash160(script.getPubKey()); Address a = new Address(params, hash160); assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", a.toString()); }
public static void runShutdownScripts() { for (int i = 0, limit = Outliner.scriptsManager.model.getSize(); i < limit; i++) { Script script = Outliner.scriptsManager.model.get(i); if (script.isShutdownScript()) { runScript(script, SHUTDOWN_SCRIPT); } } }
@And("^this script has a Repeat end brick$") public void script_has_repeat_end_brick() { Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT); Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT); LoopBeginBrick loopBeginBrick = (LoopBeginBrick) Cucumber.get(Cucumber.KEY_LOOP_BEGIN_BRICK); Brick brick = new LoopEndBrick(loopBeginBrick); script.addBrick(brick); }
@And("^this script has a Repeat (\\d+) times brick$") public void script_has_repeat_times_brick(int iterations) { Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT); Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT); Brick brick = new RepeatBrick(new Formula(iterations)); Cucumber.put(Cucumber.KEY_LOOP_BEGIN_BRICK, brick); script.addBrick(brick); }
private Script getMigrationScript(Dialect dialect, SimpleJdbcTemplate template) { Script script = new Script(); for (ChangeSet changeSet : changeSets) { if (!isApplied(changeSet)) { script.append(changeSet.getScript(dialect, template)); script.append(markAsApplied(changeSet, template)); } } return script; }
public int indexOf(String name) { for (int i = 0, limit = scripts.size(); i < limit; i++) { Script script = get(i); if (script.getName().equals(name)) { return i; } } return -1; }
@Override public boolean isUpdated() { // テーブルヘッダは起動中変更できないので、ファイルは増減させない for (Script script : this.get()) { if (script.isUpdated()) { return true; } } return false; }
public ClientWriter select(String selector, Script... s) throws IOException { if (s == null || selector == null) return this; this.writer.write( this.getBuffer().append("$$('").append(selector).append("').each(function(e){").toString()); for (Script i : s) { i.write("e", this); } this.writer.write("});"); return this; }
/* Run the script currently in the editor */ private void runEditorScript() { try { irbOutput.append("[Running editor script (" + currentScript.getName() + ")]\n"); String inspected = currentScript.setContents(sourceEditor.getText().toString()).execute(); irbOutput.append("=> " + inspected + "\n>> "); tabs.setCurrentTab(IRB_TAB); } catch (IOException e) { Toast.makeText(this, "Could not execute script", Toast.LENGTH_SHORT).show(); } }
/* Load script into editor and switch to editor view */ private void editScript(Script script, Boolean switchTab) { try { currentScript = script; fnameTextView.setText(script.getName()); sourceEditor.setText(script.getContents()); if (switchTab) tabs.setCurrentTab(EDITOR_TAB); } catch (IOException e) { Toast.makeText(this, "Could not open " + script.getName(), Toast.LENGTH_SHORT).show(); } }
private static void replaceAll(Script script, List<String> a, List<String> b) { if (script == null) { return; } String s = script.getContent(); for (int i = 0; i < a.size(); i++) { s = s.replaceAll(a.get(i), b.get(i)); } script.setContent(s); }
@Test public void testScriptPubKey() throws Exception { // Check we can extract the to address byte[] pubkeyBytes = Hex.decode(pubkeyProg); Script pubkey = new Script(pubkeyBytes); assertEquals( "DUP HASH160 [33e81a941e64cda12c6a299ed322ddbdd03f8d0e] EQUALVERIFY CHECKSIG", pubkey.toString()); Address toAddr = new Address(params, pubkey.getPubKeyHash()); assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", toAddr.toString()); }