@@ -461,44 +461,64 @@ protected void failure(String str) {
461
461
testFailed = true ;
462
462
}
463
463
464
+ final List <String > doubleWordArgs = List .of ("-cp" , "-classpath" , "--add-opens" , "--class-path" ,
465
+ "--upgrade-module-path" , "--add-modules" , "-d" , "--add-exports" , "--patch-module" , "--module-path" );
466
+
464
467
private ArgInfo parseArgs (String args []) {
465
468
ArgInfo argInfo = new ArgInfo ();
466
- String mainWrapper = System .getProperty ("main.wrapper" );
467
- if ("Virtual" .equals (mainWrapper )) {
468
- argInfo .targetAppCommandLine = TestScaffold .class .getName () + " " + mainWrapper + " " ;
469
- } else if ("true" .equals (System .getProperty ("test.enable.preview" ))) {
470
- // the test specified @enablePreview.
471
- argInfo .targetVMArgs += "--enable-preview " ;
472
- }
473
-
469
+ // Parse arguments, like java/j* tools command-line arguments.
470
+ // The first argument not-starting with '-' is treated as a classname.
471
+ // The other arguments are split to targetVMArgs targetAppCommandLine correspondingly.
472
+ // The example of args for line '@run driver Frames2Test -Xss4M' is '-Xss4M' 'Frames2Targ'.
473
+ // The result without any wrapper enabled:
474
+ // argInfo.targetAppCommandLine : Frames2Targ
475
+ // argInfo.targetVMArgs : -Xss4M
476
+ // The result with wrapper enabled:
477
+ // argInfo.targetAppCommandLine : TestScaffold Virtual Frames2Targ
478
+ // argInfo.targetVMArgs : -Xss4M
479
+ boolean classNameParsed = false ;
474
480
for (int i = 0 ; i < args .length ; i ++) {
475
- if (args [i ].equals ("-connect" )) {
481
+ String arg = args [i ].trim ();
482
+ if (classNameParsed ) {
483
+ // once classname is read, treat any other arguments as app arguments
484
+ argInfo .targetAppCommandLine += (arg + ' ' );
485
+ continue ;
486
+ }
487
+ if (arg .equals ("-connect" )) {
476
488
i ++;
477
489
argInfo .connectorSpec = args [i ];
478
- } else if (args [ i ] .equals ("-trace" )) {
490
+ } else if (arg .equals ("-trace" )) {
479
491
i ++;
480
492
argInfo .traceFlags = Integer .decode (args [i ]).intValue ();
481
- } else if (args [ i ] .equals ("-redefstart" )) {
493
+ } else if (arg .equals ("-redefstart" )) {
482
494
redefineAtStart = true ;
483
- } else if (args [ i ] .equals ("-redefevent" )) {
495
+ } else if (arg .equals ("-redefevent" )) {
484
496
redefineAtEvents = true ;
485
- } else if (args [ i ] .equals ("-redefasync" )) {
497
+ } else if (arg .equals ("-redefasync" )) {
486
498
redefineAsynchronously = true ;
487
- } else if (args [i ].startsWith ("-J" )) {
488
- argInfo .targetVMArgs += (args [i ].substring (2 ) + ' ' );
489
-
490
- /*
491
- * classpath can span two arguments so we need to handle
492
- * it specially.
493
- */
494
- if (args [i ].equals ("-J-classpath" )) {
499
+ } else if (arg .startsWith ("-J" )) {
500
+ throw new RuntimeException ("-J-option format is not supported. Incorrect arg: " + arg );
501
+ } else if (arg .startsWith ("-" )) {
502
+ argInfo .targetVMArgs += (arg + ' ' );
503
+ if (doubleWordArgs .contains (arg )) {
495
504
i ++;
496
505
argInfo .targetVMArgs += (args [i ] + ' ' );
497
506
}
498
507
} else {
499
- argInfo .targetAppCommandLine += (args [i ] + ' ' );
508
+ classNameParsed = true ;
509
+ argInfo .targetAppCommandLine += (arg + ' ' );
500
510
}
501
511
}
512
+
513
+ // Need to change args to run wrapper using command like 'TestScaffold Virtual <app-name>'
514
+ String mainWrapper = System .getProperty ("main.wrapper" );
515
+ if (mainWrapper != null && !argInfo .targetAppCommandLine .isEmpty ()) {
516
+ argInfo .targetAppCommandLine = TestScaffold .class .getName () + ' '
517
+ + mainWrapper + ' ' + argInfo .targetAppCommandLine ;
518
+ } else if ("true" .equals (System .getProperty ("test.enable.preview" ))) {
519
+ // the test specified @enablePreview.
520
+ argInfo .targetVMArgs += "--enable-preview " ;
521
+ }
502
522
return argInfo ;
503
523
}
504
524
0 commit comments