/** Downloads BeanShell or Jython interpreter using a separate thread. */ public void run() { if (downloading || downloadUrl==null) return; downloading = true; boolean ok = Macro_Runner.downloadJar(downloadUrl); downloading = false; }
/** Downloads BeanShell or Jython interpreter using a separate thread. */ public void run() { if (downloading || downloadUrl==null) return; downloading = true; boolean ok = Macro_Runner.downloadJar(downloadUrl); downloading = false; }
private void checkForUpdate(String plugin, String currentVersion) { int slashIndex = plugin.lastIndexOf("/"); if (slashIndex==-1 || !plugin.endsWith(".jar")) return; String className = plugin.substring(slashIndex+1, plugin.length()-4); File f = new File(Prefs.getImageJDir()+"plugins"+File.separator+"jars"+File.separator+className+".jar"); if (!f.exists() || !f.canWrite()) { if (IJ.debugMode) IJ.log("checkForUpdate: jar not found ("+plugin+")"); return; } String version = null; try { Class c = IJ.getClassLoader().loadClass("Compiler"); version = "0.00a"; Method m = c.getDeclaredMethod("getVersion", new Class[0]); version = (String)m.invoke(null, new Object[0]); } catch (Exception e) {} if (version==null) { if (IJ.debugMode) IJ.log("checkForUpdate: class not found ("+className+")"); return; } if (version.compareTo(currentVersion)>=0) { if (IJ.debugMode) IJ.log("checkForUpdate: up to date ("+className+" "+version+")"); return; } boolean ok = Macro_Runner.downloadJar(plugin); if (IJ.debugMode) IJ.log("checkForUpdate: "+className+" "+version+" "+ok); }
private void checkForUpdate(String plugin, String currentVersion) { int slashIndex = plugin.lastIndexOf("/"); if (slashIndex==-1 || !plugin.endsWith(".jar")) return; String className = plugin.substring(slashIndex+1, plugin.length()-4); File f = new File(Prefs.getImageJDir()+"plugins"+File.separator+"jars"+File.separator+className+".jar"); if (!f.exists() || !f.canWrite()) { if (IJ.debugMode) IJ.log("checkForUpdate: jar not found ("+plugin+")"); return; } String version = null; try { Class c = IJ.getClassLoader().loadClass("Compiler"); version = "0.00a"; Method m = c.getDeclaredMethod("getVersion", new Class[0]); version = (String)m.invoke(null, new Object[0]); } catch (Exception e) {} if (version==null) { if (IJ.debugMode) IJ.log("checkForUpdate: class not found ("+className+")"); return; } if (version.compareTo(currentVersion)>=0) { if (IJ.debugMode) IJ.log("checkForUpdate: up to date ("+className+" "+version+")"); return; } boolean ok = Macro_Runner.downloadJar(plugin); if (IJ.debugMode) IJ.log("checkForUpdate: "+className+" "+version+" "+ok); }
/** Runs a BeanShell script on the current thread, passing a string argument, which the script can retrieve using the getArgument() function. Returns, as a string, the last expression evaluated by the script. Uses the plugin at http://imagej.nih.gov/ij/plugins/bsh/ to run the script. */ public static String runBeanShell(String script, String arg) { if (arg==null) arg = ""; Object bsh = IJ.runPlugIn("bsh", ""); if (bsh==null) { boolean ok = downloadJar("/plugins/bsh/BeanShell.jar"); if (ok) bsh = IJ.runPlugIn("bsh", ""); } if (bsh!=null) return runScript(bsh, script, arg); else return null; }
/** Runs a BeanShell script on the current thread, passing a string argument, which the script can retrieve using the getArgument() function. Returns, as a string, the last expression evaluated by the script. Uses the plugin at http://imagej.nih.gov/ij/plugins/bsh/ to run the script. */ public static String runBeanShell(String script, String arg) { if (arg==null) arg = ""; Object bsh = IJ.runPlugIn("bsh", ""); if (bsh==null) { boolean ok = downloadJar("/plugins/bsh/BeanShell.jar"); if (ok) bsh = IJ.runPlugIn("bsh", ""); } if (bsh!=null) return runScript(bsh, script, arg); else return null; }
/** Runs a Python script on the current thread, passing a string argument, which the script can retrieve using the getArgument() function. Returns, as a string, the value of the variable 'result'. For example, a Python script containing the line "result=123" will return the string "123". Uses the plugin at http://imagej.nih.gov/ij/plugins/jython/ to run the script. */ public static String runPython(String script, String arg) { if (arg==null) arg = ""; Object jython = IJ.runPlugIn("Jython", ""); if (jython==null) { boolean ok = downloadJar("/plugins/jython/Jython.jar"); if (ok) jython = IJ.runPlugIn("Jython", ""); } if (jython!=null) return runScript(jython, script, arg); else return null; }
/** Runs a Python script on the current thread, passing a string argument, which the script can retrieve using the getArgument() function. Returns, as a string, the value of the variable 'result'. For example, a Python script containing the line "result=123" will return the string "123". Uses the plugin at http://imagej.nih.gov/ij/plugins/jython/ to run the script. */ public static String runPython(String script, String arg) { if (arg==null) arg = ""; Object jython = IJ.runPlugIn("Jython", ""); if (jython==null) { boolean ok = downloadJar("/plugins/jython/Jython.jar"); if (ok) jython = IJ.runPlugIn("Jython", ""); } if (jython!=null) return runScript(jython, script, arg); else return null; }
void compileAndRun(String path) { if (!open(path, "Compile and Run Plugin...")) return; if (name.endsWith(".class")) { runPlugin(name.substring(0, name.length()-1)); return; } if (!isJavac()) { if (IJ.debugMode) IJ.log("Compiler: javac not found"); if (!checkForUpdateDone) { checkForUpdate("/plugins/compiler/Compiler.jar", "1.48c"); checkForUpdateDone = true; } Object compiler = IJ.runPlugIn("Compiler", dir+name); if (compiler==null) { boolean ok = Macro_Runner.downloadJar("/plugins/compiler/Compiler.jar"); if (ok) IJ.runPlugIn("Compiler", dir+name); } return; } if (compile(dir+name)) runPlugin(name); }
void compileAndRun(String path) { if (!open(path, "Compile and Run Plugin...")) return; if (name.endsWith(".class")) { runPlugin(name.substring(0, name.length()-1)); return; } if (!isJavac()) { if (IJ.debugMode) IJ.log("Compiler: javac not found"); if (!checkForUpdateDone) { checkForUpdate("/plugins/compiler/Compiler.jar", "1.48c"); checkForUpdateDone = true; } Object compiler = IJ.runPlugIn("Compiler", dir+name); if (compiler==null) { boolean ok = Macro_Runner.downloadJar("/plugins/compiler/Compiler.jar"); if (ok) IJ.runPlugIn("Compiler", dir+name); } return; } if (compile(dir+name)) runPlugin(name); }
/** Runs a JavaScript script on the current thread, passing a string argument, which the script can retrieve using the getArgument() function. Returns, as a string, the last expression evaluated by the script. */ public String runJavaScript(String script, String arg) { Object js = null; if (!(IJ.isMacOSX()&&!IJ.is64Bit())) { // Use JavaScript engine built into Java 6 and later. js = IJ.runPlugIn("ij.plugin.JavaScriptEvaluator", ""); } else { js = IJ.runPlugIn("JavaScript", ""); if (js==null) { boolean ok = downloadJar("/download/tools/JavaScript.jar"); if (ok) js = IJ.runPlugIn("JavaScript", ""); } } script = Editor.getJSPrefix(arg)+script; if (IJ.isJava18()) script = "load(\"nashorn:mozilla_compat.js\");" + script; if (js!=null) return runScript(js, script, arg); else return null; }
/** Runs a JavaScript script on the current thread, passing a string argument, which the script can retrieve using the getArgument() function. Returns, as a string, the last expression evaluated by the script. */ public String runJavaScript(String script, String arg) { Object js = null; if (!(IJ.isMacOSX()&&!IJ.is64Bit())) { // Use JavaScript engine built into Java 6 and later. js = IJ.runPlugIn("ij.plugin.JavaScriptEvaluator", ""); } else { js = IJ.runPlugIn("JavaScript", ""); if (js==null) { boolean ok = downloadJar("/download/tools/JavaScript.jar"); if (ok) js = IJ.runPlugIn("JavaScript", ""); } } script = Editor.getJSPrefix(arg)+script; if (IJ.isJava18()) script = "load(\"nashorn:mozilla_compat.js\");" + script; if (js!=null) return runScript(js, script, arg); else return null; }