File tree Expand file tree Collapse file tree 5 files changed +32
-9
lines changed
src/main/java/org/scijava Expand file tree Collapse file tree 5 files changed +32
-9
lines changed Original file line number Diff line number Diff line change @@ -57,13 +57,13 @@ public class CommandRunner extends AbstractClassRunner {
5757 // -- ClassRunner methods --
5858
5959 @ Override
60- public void run (final Class <?> c ) {
60+ public void run (final Class <?> c , final Object ... args ) {
6161 @ SuppressWarnings ("unchecked" )
6262 final Class <? extends Command > commandClass = (Class <? extends Command >) c ;
6363 final Plugin annotation = c .getAnnotation (Plugin .class );
6464 final CommandInfo info = new CommandInfo (commandClass , annotation );
6565 pluginService .addPlugin (info );
66- commandService .run (info , true );
66+ commandService .run (info , true , args );
6767 }
6868
6969 // -- Typed methods --
Original file line number Diff line number Diff line change @@ -55,9 +55,12 @@ public class MainRunner extends AbstractClassRunner {
5555 // -- ClassRunner methods --
5656
5757 @ Override
58- public void run (final Class <?> c ) throws InvocationTargetException {
58+ public void run (final Class <?> c , final Object ... args )
59+ throws InvocationTargetException
60+ {
61+ final Object [] sArgs = stringify (args );
5962 try {
60- getMain (c ).invoke (null , new Object [] { new String [ 0 ] });
63+ getMain (c ).invoke (null , new Object [] { sArgs });
6164 }
6265 catch (final IllegalArgumentException exc ) {
6366 throw new InvocationTargetException (exc );
@@ -90,4 +93,19 @@ private Method getMain(final Class<?> c) {
9093 }
9194 }
9295
96+ /** Ensures each element is a {@link String}. */
97+ private String [] stringify (final Object ... o ) {
98+ final String [] s ;
99+ if (o == null ) s = null ;
100+ else {
101+ s = new String [o .length ];
102+ for (int i = 0 ; i < o .length ; i ++) {
103+ if (o [i ] == null ) s [i ] = null ;
104+ else if (o [i ] instanceof String ) s [i ] = (String ) o [i ];
105+ else s [i ] = o [i ].toString ();
106+ }
107+ }
108+ return s ;
109+ }
110+
93111}
Original file line number Diff line number Diff line change 5252 */
5353public interface ClassRunner extends HandlerPlugin <Class <?>> {
5454
55- /** Executes the given class. */
56- void run (Class <?> c ) throws InvocationTargetException ;
55+ /** Executes the given class, with the specified arguments . */
56+ void run (Class <?> c , Object ... args ) throws InvocationTargetException ;
5757
5858}
Original file line number Diff line number Diff line change @@ -55,7 +55,9 @@ public class DefaultRunService extends
5555 // -- RunService methods --
5656
5757 @ Override
58- public void run (final Class <?> c ) throws InvocationTargetException {
58+ public void run (final Class <?> c , final Object ... args )
59+ throws InvocationTargetException
60+ {
5961 for (final ClassRunner runner : getInstances ()) {
6062 if (runner .supports (c )) {
6163 runner .run (c );
Original file line number Diff line number Diff line change @@ -45,7 +45,10 @@ public interface RunService extends
4545 HandlerService <Class <?>, ClassRunner >, SciJavaService
4646{
4747
48- /** Executes the given class using the most appropriate handler. */
49- void run (Class <?> c ) throws InvocationTargetException ;
48+ /**
49+ * Executes the given class using the most appropriate handler, passing the
50+ * given arguments to the execution.
51+ */
52+ void run (Class <?> c , Object ... args ) throws InvocationTargetException ;
5053
5154}
You can’t perform that action at this time.
0 commit comments