3535import java .util .Map ;
3636
3737import org .scijava .command .Command ;
38+ import org .scijava .command .CommandInfo ;
3839import org .scijava .command .CommandService ;
3940import org .scijava .plugin .Parameter ;
4041import org .scijava .plugin .Plugin ;
@@ -58,21 +59,29 @@ public class CommandCodeRunner extends AbstractCodeRunner {
5859 public void run (final Object code , final Object ... args )
5960 throws InvocationTargetException
6061 {
61- waitFor (commandService .run (getCommandClass (code ), true , args ));
62+ final Class <? extends Command > c = getCommandClass (code );
63+ if (c != null ) waitFor (commandService .run (c , true , args ));
64+
65+ final CommandInfo info = getCommandInfo (code );
66+ if (info != null ) waitFor (commandService .run (info , true , args ));
6267 }
6368
6469 @ Override
6570 public void run (final Object code , final Map <String , Object > inputMap )
6671 throws InvocationTargetException
6772 {
68- waitFor (commandService .run (getCommandClass (code ), true , inputMap ));
73+ final Class <? extends Command > c = getCommandClass (code );
74+ if (c != null ) waitFor (commandService .run (c , true , inputMap ));
75+
76+ final CommandInfo info = getCommandInfo (code );
77+ if (info != null ) waitFor (commandService .run (info , true , inputMap ));
6978 }
7079
7180 // -- Typed methods --
7281
7382 @ Override
7483 public boolean supports (final Object code ) {
75- return getCommandClass (code ) != null ;
84+ return getCommandClass (code ) != null || getCommandInfo ( code ) != null ;
7685 }
7786
7887 // -- Helper methods --
@@ -86,4 +95,19 @@ private Class<? extends Command> getCommandClass(final Object code) {
8695 return commandClass ;
8796 }
8897
98+ private CommandInfo getCommandInfo (final Object code ) {
99+ if (!(code instanceof String )) return null ;
100+ final String command = (String ) code ;
101+
102+ final CommandInfo info = commandService .getCommand (command );
103+ if (info != null ) return info ;
104+
105+ // command was not a class name; search for command by title instead
106+ for (final CommandInfo ci : commandService .getCommands ()) {
107+ if (command .equals (ci .getTitle ())) return ci ;
108+ }
109+
110+ return null ;
111+ }
112+
89113}
0 commit comments