org.scijava.script.ScriptModule Java Examples
The following examples show how to use
org.scijava.script.ScriptModule.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReadmeExampleTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testReadmesExample() throws Exception { // extract the example script final File readme = new File("README.md"); final String contents = new String(FileUtils.readFile(readme), "UTF-8"); final String telltale = String.format("```python%n"); final int begin = contents.indexOf(telltale) + telltale.length(); assertTrue(begin > telltale.length()); assertTrue(contents.indexOf(telltale, begin) < 0); final int end = contents.indexOf(String.format("```%n"), begin); assertTrue(end > 0); final String snippet = contents.substring(begin, end); assertTrue(snippet.startsWith("# @ImageJ ij")); final Context context = new Context(); final ScriptService script = context.getService(ScriptService.class); // create mock ImageJ gateway script.addAlias("ImageJ", Mock.class); final ScriptModule module = script.run("op-example.py", snippet, true).get(); assertNotNull(module); module.run(); final Mock ij = context.getService(Mock.class); assertEquals(3, ij.images.size()); assertEquals(11.906, ij.getPixel("sinusoid", 50, 50), 1e-3); assertEquals(100, ij.getPixel("gradient", 50, 50), 1e-3); assertEquals(111.906, ij.getPixel("composite", 50, 50), 1e-3); }
Example #2
Source File: Runner.java From Scripts with GNU General Public License v3.0 | 5 votes |
/** * Runs a script from a jar file. * * @param in * the {@link InputStream} loading the script to be executed * @param filename * the script filename (or at least its extension) * @param inputMap * see {@link ScriptService#run(String, Reader, boolean, Map)} */ public void runScript(final InputStream in, final String filename, final Map<String, Object> inputMap) { if (in == null) { error("Could not find " + filename, IO_ERROR); return; } final Reader reader = new InputStreamReader(in); setLoaded(true); final Future<ScriptModule> fsm = scriptService.run(filename, reader, true, inputMap); if (fsm.isCancelled()) setStatus(WAS_CANCELED); else if (fsm.isDone()) setStatus(WAS_DONE); }