2626import processing .app .exec .StreamRedirectThread ;
2727import processing .app .ui .Editor ;
2828import processing .core .*;
29+ import processing .data .StringList ;
2930import processing .mode .java .JavaBuild ;
3031
3132import java .awt .GraphicsDevice ;
@@ -113,19 +114,28 @@ public Runner(JavaBuild build, RunnerListener listener) throws SketchException {
113114 }
114115
115116
116- public void launch (boolean presenting ) {
117- if (launchVirtualMachine (presenting )) {
117+ public VirtualMachine launch (String [] args ) {
118+ if (launchVirtualMachine (false , args )) {
118119 generateTrace ();
119120 }
121+ return vm ;
122+ }
123+
124+
125+ public VirtualMachine present (String [] args ) {
126+ if (launchVirtualMachine (true , args )) {
127+ generateTrace ();
128+ }
129+ return vm ;
120130 }
121131
122132
123133 /**
124134 * Simple non-blocking launch of the virtual machine. VM starts suspended.
125135 * @return debuggee VM or null on failure
126136 */
127- public VirtualMachine launchDebug ( ) {
128- if (launchVirtualMachine (false )) { // will return null on failure
137+ public VirtualMachine debug ( String [] args ) {
138+ if (launchVirtualMachine (false , args )) { // will return null on failure
129139 redirectStreams (vm );
130140 }
131141 return vm ;
@@ -153,9 +163,9 @@ public VirtualMachine vm() {
153163 }
154164
155165
156- public boolean launchVirtualMachine (boolean presenting ) {
157- String [] vmParams = getMachineParams ();
158- String [] sketchParams = getSketchParams (presenting );
166+ public boolean launchVirtualMachine (boolean present , String [] args ) {
167+ StringList vmParams = getMachineParams ();
168+ StringList sketchParams = getSketchParams (present , args );
159169// PApplet.printArray(sketchParams);
160170 int port = 8000 + (int ) (Math .random () * 1000 );
161171 String portStr = String .valueOf (port );
@@ -167,13 +177,13 @@ public boolean launchVirtualMachine(boolean presenting) {
167177 String jdwpArg = "-agentlib:jdwp=transport=dt_socket,address=" + portStr + ",server=y,suspend=y" ;
168178
169179 // Everyone works the same under Java 7 (also on OS X)
170- String [] commandArgs = new String [] { Platform .getJavaPath (), jdwpArg };
180+ StringList commandArgs = new StringList ();
181+ commandArgs .append (Platform .getJavaPath ());
182+ commandArgs .append (jdwpArg );
171183
172- commandArgs = PApplet .concat (commandArgs , vmParams );
173- commandArgs = PApplet .concat (commandArgs , sketchParams );
174- // PApplet.println(commandArgs);
175- // commandArg.setValue(commandArgs);
176- launchJava (commandArgs );
184+ commandArgs .append (vmParams );
185+ commandArgs .append (sketchParams );
186+ launchJava (commandArgs .array ());
177187
178188 AttachingConnector connector = (AttachingConnector )
179189 findConnector ("com.sun.jdi.SocketAttach" );
@@ -228,8 +238,8 @@ public boolean launchVirtualMachine(boolean presenting) {
228238 }
229239
230240
231- protected String [] getMachineParams () {
232- ArrayList < String > params = new ArrayList < String > ();
241+ protected StringList getMachineParams () {
242+ StringList params = new StringList ();
233243
234244 //params.add("-Xint"); // interpreted mode
235245 //params.add("-Xprof"); // profiler
@@ -244,73 +254,53 @@ protected String[] getMachineParams() {
244254 for (int i = 0 ; i < pieces .length ; i ++) {
245255 String p = pieces [i ].trim ();
246256 if (p .length () > 0 ) {
247- params .add (p );
257+ params .append (p );
248258 }
249259 }
250260 }
251261
252262// params.add("-Djava.ext.dirs=nuffing");
253263
254264 if (Preferences .getBoolean ("run.options.memory" )) {
255- params .add ("-Xms" + Preferences .get ("run.options.memory.initial" ) + "m" );
256- params .add ("-Xmx" + Preferences .get ("run.options.memory.maximum" ) + "m" );
265+ params .append ("-Xms" + Preferences .get ("run.options.memory.initial" ) + "m" );
266+ params .append ("-Xmx" + Preferences .get ("run.options.memory.maximum" ) + "m" );
257267 }
258268
259269 if (Platform .isMacOS ()) {
260- params .add ("-Xdock:name=" + build .getSketchClassName ());
270+ params .append ("-Xdock:name=" + build .getSketchClassName ());
261271// params.add("-Dcom.apple.mrj.application.apple.menu.about.name=" +
262272// sketch.getMainClassName());
263273 }
264274 // sketch.libraryPath might be ""
265275 // librariesClassPath will always have sep char prepended
266- params .add ("-Djava.library.path=" +
267- build .getJavaLibraryPath () +
268- File .pathSeparator +
269- System .getProperty ("java.library.path" ));
276+ params .append ("-Djava.library.path=" +
277+ build .getJavaLibraryPath () +
278+ File .pathSeparator +
279+ System .getProperty ("java.library.path" ));
270280
271- params .add ("-cp" );
272- params .add (build .getClassPath ());
273- // params.add(sketch.getClassPath() +
274- // File.pathSeparator +
275- // Base.librariesClassPath);
281+ params .append ("-cp" );
282+ params .append (build .getClassPath ());
276283
277284 // enable assertions
278285 // http://dev.processing.org/bugs/show_bug.cgi?id=1188
279- params .add ("-ea" );
286+ params .append ("-ea" );
280287 //PApplet.println(PApplet.split(sketch.classPath, ':'));
281288
282- String outgoing [] = new String [params .size ()];
283- params .toArray (outgoing );
284-
285- // PApplet.println(outgoing);
286- // PApplet.println(PApplet.split(outgoing[0], ":"));
287- // PApplet.println();
288- // PApplet.println("class path");
289- // PApplet.println(PApplet.split(outgoing[2], ":"));
290-
291- return outgoing ;
292- //return (String[]) params.toArray();
293-
294- // System.out.println("sketch class path");
295- // PApplet.println(PApplet.split(sketch.classPath, ';'));
296- // System.out.println();
297- // System.out.println("libraries class path");
298- // PApplet.println(PApplet.split(Base.librariesClassPath, ';'));
299- // System.out.println();
289+ return params ;
300290 }
301291
302292
303- protected String [] getSketchParams (boolean presenting ) {
304- ArrayList < String > params = new ArrayList < String > ();
293+ protected StringList getSketchParams (boolean present , String [] args ) {
294+ StringList params = new StringList ();
305295
306296 // It's dangerous to add your own main() to your code,
307297 // but if you've done it, we'll respect your right to hang yourself.
308298 // http://processing.org/bugs/bugzilla/1446.html
309299 if (build .getFoundMain ()) {
310- params .add (build .getSketchClassName ());
300+ params .append (build .getSketchClassName ());
311301
312302 } else {
313- params .add ("processing.core.PApplet" );
303+ params .append ("processing.core.PApplet" );
314304
315305 // get the stored device index (starts at 1)
316306 int runDisplay = Preferences .getInteger ("run.display" );
@@ -366,8 +356,8 @@ protected String[] getSketchParams(boolean presenting) {
366356 // If sketches are to be shown on the same display as the editor,
367357 // provide the editor location so the sketch's main() can place it.
368358 Point editorLocation = editor .getLocation ();
369- params .add (PApplet .ARGS_EDITOR_LOCATION + "=" +
370- editorLocation .x + "," + editorLocation .y );
359+ params .append (PApplet .ARGS_EDITOR_LOCATION + "=" +
360+ editorLocation .x + "," + editorLocation .y );
371361 } else {
372362 // The sketch's main() will set a location centered on the new
373363 // display. It has to happen in main() because the width/height
@@ -379,37 +369,38 @@ protected String[] getSketchParams(boolean presenting) {
379369// params.add(PApplet.ARGS_LOCATION + "=" + runX + "," + runY);
380370 }
381371 } else {
382- params .add (PApplet .ARGS_LOCATION + "=" +
383- windowLocation .x + "," + windowLocation .y );
372+ params .append (PApplet .ARGS_LOCATION + "=" +
373+ windowLocation .x + "," + windowLocation .y );
384374 }
385- params .add (PApplet .ARGS_EXTERNAL );
375+ params .append (PApplet .ARGS_EXTERNAL );
386376 }
387377
388- params .add (PApplet .ARGS_DISPLAY + "=" + runDisplay );
378+ params .append (PApplet .ARGS_DISPLAY + "=" + runDisplay );
389379
390380
391- if (presenting ) {
392- params .add (PApplet .ARGS_PRESENT );
381+ if (present ) {
382+ params .append (PApplet .ARGS_PRESENT );
393383// if (Preferences.getBoolean("run.present.exclusive")) {
394384// params.add(PApplet.ARGS_EXCLUSIVE);
395385// }
396- params .add (PApplet .ARGS_STOP_COLOR + "=" +
397- Preferences .get ("run.present.stop.color" ));
398- params .add (PApplet .ARGS_WINDOW_COLOR + "=" +
399- Preferences .get ("run.present.bgcolor" ));
386+ params .append (PApplet .ARGS_STOP_COLOR + "=" +
387+ Preferences .get ("run.present.stop.color" ));
388+ params .append (PApplet .ARGS_WINDOW_COLOR + "=" +
389+ Preferences .get ("run.present.bgcolor" ));
400390 }
401391
402392 // There was a PDE X hack that put this after the class name, but it was
403393 // removed for 3.0a6 because it would break the args passed to sketches.
404- params .add (PApplet .ARGS_SKETCH_FOLDER + "=" + build .getSketchPath ());
394+ params .append (PApplet .ARGS_SKETCH_FOLDER + "=" + build .getSketchPath ());
405395
406- params .add (build .getSketchClassName ());
396+ params .append (build .getSketchClassName ());
407397 }
408-
409- // String outgoing[] = new String[params.size()];
410- // params.toArray(outgoing);
411- // return outgoing;
412- return params .toArray (new String [0 ]);
398+ // Add command-line arguments to be given to the sketch itself
399+ if (args != null ) {
400+ params .append (args );
401+ }
402+ // Pass back the whole list
403+ return params ;
413404 }
414405
415406
0 commit comments