ScriptText scriptText = new ScriptText(scriptName, scriptString); List<ScriptText> scriptTexts = new LinkedList<ScriptText>(); scriptTexts.add(scriptText); ScriptText updatedScriptText = null; for(ScriptText scriptText : installedScripts) { if(scriptText.getFileName().equals(redirectedSubmissionsFile.getCanonicalPath())) { installedScriptText = scriptText; updatedScriptText = new ScriptText(installedScriptText.getFileName(), installedScriptText.getText()+scriptString); } else { updatedScriptText = new ScriptText(redirectedSubmissionsFile.getCanonicalPath(), scriptString);
/** * Deletes rules from Byteman. * * @param scripts * rule scripts to be deleted from Byteman * * @return the results of the deletion * * @throws Exception * if the request failed */ public String deleteScripts(List<ScriptText> scripts) throws Exception { if (scripts == null || scripts.size() == 0) { return ""; } StringBuilder str = new StringBuilder("DELETE\n"); for (ScriptText scriptText : scripts) { str.append("SCRIPT " + scriptText.getFileName() + '\n'); str.append(scriptText.getText()).append('\n'); str.append("ENDSCRIPT\n"); } str.append("ENDDELETE\n"); return submitRequest(str.toString()); }
private ScriptText readScriptText(String filePath, InputStreamReader reader) throws Exception { final char[] readBuffer = new char[4096]; StringBuilder scriptText = new StringBuilder(); try { int read = reader.read(readBuffer); while (read > 0) { scriptText.append(readBuffer, 0, read); read = reader.read(readBuffer); } reader.close(); return new ScriptText(filePath, scriptText.toString()); } catch (IOException e) { throw new Exception("Error reading from rule file: " + filePath, e); } }
/** * Looping through installed scripts and checking if scriptName * is there. If so returns it otherwise returns null. */ private ScriptText findInstalledScript(String scriptName) { for(ScriptText installedScript: installedScripts) { if(installedScript.getFileName().equals(scriptName)) return installedScript; } return null; } }
for (String fileName : scriptFileNames) { String text = rulesByScript.get(fileName); scriptTexts.add(new ScriptText(fileName, text));
/** * Deploys rule scripts into Byteman * * @param scripts * scripts to be deployed to Byteman * * @return the results of the deployment * * @throws Exception * if the request failed */ public String addScripts(List<ScriptText> scripts) throws Exception { if (scripts == null || scripts.size() == 0) { return ""; } StringBuilder str = new StringBuilder("LOAD\n"); for (ScriptText scriptText : scripts) { str.append("SCRIPT " + scriptText.getFileName() + '\n'); str.append(scriptText.getText()).append('\n'); str.append("ENDSCRIPT\n"); } str.append("ENDLOAD\n"); return submitRequest(str.toString()); }
/** * unloads a script previously supplied as a text String * @param clazz the test class * @param testName the test name * @throws Exception if the script text cannot be unloaded */ public static void unloadScriptText(Class<?> clazz, String testName) throws Exception { String className = clazz.getName(); if (testName == null) { testName = ""; } String key = className + "+" + testName; String scriptText = fileTable.remove(key); if (scriptText == null) { throw new Exception("Rule script not found " + key); } Submit submit = new Submit(getHost(), getPort()); if (isBMUnitVerbose()) { System.out.println("BMUnit : unloading text script = " + key); } List<ScriptText> scripts = new ArrayList<ScriptText>(); ScriptText script = new ScriptText(key, scriptText); scripts.add(script); submit.deleteScripts(scripts); }
/** * loads a script supplied as a text String rather than via a file on disk * @param clazz the test class * @param testname the test name * @param scriptText the text of the rule or rules contained in the script * @throws Exception if the script text cannot be loaded */ public static void loadScriptText(Class<?> clazz, String testname, String scriptText) throws Exception { if (BMUnitConfigState.getCurrentConfigState() == null) { throw new Exception("BMUnit : load script file requested with no current configuration " + clazz.getName() + (testname != null ? " " + testname : "")); } String className = clazz.getName(); if (testname == null) { testname = ""; } String key = className + "+" + testname; fileTable.put(key, scriptText); Submit submit = new Submit(getHost(), getPort()); if (isBMUnitVerbose()) { System.out.println("BMUnit : loading text script = " + key); // System.out.println(scriptText); } List<ScriptText> scripts = new ArrayList<ScriptText>(); ScriptText script = new ScriptText(key, scriptText); scripts.add(script); submit.addScripts(scripts); }