|
46 | 46 | import java.io.Reader; |
47 | 47 | import java.io.StringReader; |
48 | 48 | import java.io.Writer; |
49 | | -import java.lang.reflect.Method; |
50 | 49 | import java.net.URL; |
51 | 50 | import java.net.URLClassLoader; |
52 | 51 | import java.util.ArrayList; |
|
66 | 65 | import javax.xml.transform.dom.DOMSource; |
67 | 66 | import javax.xml.transform.stream.StreamResult; |
68 | 67 |
|
69 | | -import org.scijava.command.Command; |
70 | | -import org.scijava.command.CommandInfo; |
71 | 68 | import org.scijava.command.CommandService; |
72 | 69 | import org.scijava.plugin.Parameter; |
73 | | -import org.scijava.plugin.Plugin; |
74 | 70 | import org.scijava.plugin.PluginService; |
75 | 71 | import org.scijava.script.AbstractScriptEngine; |
76 | 72 | import org.scijava.util.FileUtils; |
@@ -100,6 +96,9 @@ public class JavaEngine extends AbstractScriptEngine { |
100 | 96 | @Parameter |
101 | 97 | private CommandService commandService; |
102 | 98 |
|
| 99 | + @Parameter |
| 100 | + JavaService javaService; |
| 101 | + |
103 | 102 | @Override |
104 | 103 | public Object eval(String script) throws ScriptException { |
105 | 104 | return eval(new StringReader(script)); |
@@ -168,21 +167,7 @@ public void println(final String line) throws IOException { |
168 | 167 |
|
169 | 168 | // launch main class |
170 | 169 | final Class<?> clazz = classLoader.loadClass(mainClass); |
171 | | - if (Command.class.isAssignableFrom(clazz)) { |
172 | | - final Plugin annotation = clazz.getAnnotation(Plugin.class); |
173 | | - final CommandInfo info = new CommandInfo(mainClass, annotation) { |
174 | | - |
175 | | - @Override |
176 | | - public Class<? extends Command> loadClass() { |
177 | | - return (Class<? extends Command>) clazz; |
178 | | - } |
179 | | - }; |
180 | | - pluginService.addPlugin(info); |
181 | | - commandService.run(info, true); |
182 | | - } else { |
183 | | - Method main = clazz.getMethod("main", new Class[] { String[].class }); |
184 | | - main.invoke(null, new Object[] { new String[0] }); |
185 | | - } |
| 170 | + javaService.run(clazz); |
186 | 171 | } catch (Exception e) { |
187 | 172 | if (err != null) err.close(); |
188 | 173 | if (e instanceof ScriptException) throw (ScriptException)e; |
|
0 commit comments