@@ -1372,21 +1372,24 @@ protected static List<String> createImageBuilderArgs(ArrayList<String> imageArgs
1372
1372
return result ;
1373
1373
}
1374
1374
1375
+ protected static String createVMInvocationArgumentFile (List <String > arguments ) {
1376
+ try {
1377
+ Path argsFile = Files .createTempFile ("vminvocation" , ".args" );
1378
+ String joinedOptions = String .join ("\n " , arguments );
1379
+ Files .write (argsFile , joinedOptions .getBytes ());
1380
+ argsFile .toFile ().deleteOnExit ();
1381
+ return "@" + argsFile ;
1382
+ } catch (IOException e ) {
1383
+ throw showError (e .getMessage ());
1384
+ }
1385
+ }
1386
+
1375
1387
protected static String createImageBuilderArgumentFile (List <String > imageBuilderArguments ) {
1376
1388
try {
1377
- Path argsFile = Files .createTempFile ("native-image" , "args" );
1389
+ Path argsFile = Files .createTempFile ("native-image" , ". args" );
1378
1390
String joinedOptions = String .join ("\0 " , imageBuilderArguments );
1379
1391
Files .write (argsFile , joinedOptions .getBytes ());
1380
- Runtime .getRuntime ().addShutdownHook (new Thread () {
1381
- @ Override
1382
- public void run () {
1383
- try {
1384
- Files .delete (argsFile );
1385
- } catch (IOException e ) {
1386
- System .err .println ("Failed to delete temporary image builder arguments file: " + argsFile .toString ());
1387
- }
1388
- }
1389
- });
1392
+ argsFile .toFile ().deleteOnExit ();
1390
1393
return NativeImageGeneratorRunner .IMAGE_BUILDER_ARG_FILE_OPTION + argsFile .toString ();
1391
1394
} catch (IOException e ) {
1392
1395
throw showError (e .getMessage ());
@@ -1395,37 +1398,46 @@ public void run() {
1395
1398
1396
1399
protected int buildImage (List <String > javaArgs , LinkedHashSet <Path > bcp , LinkedHashSet <Path > cp , LinkedHashSet <Path > mp , ArrayList <String > imageArgs , LinkedHashSet <Path > imagecp ,
1397
1400
LinkedHashSet <Path > imagemp ) {
1398
- /* Construct ProcessBuilder command from final arguments */
1399
- List <String > command = new ArrayList <>();
1400
- command .add (canonicalize (config .getJavaExecutable ()).toString ());
1401
- command .addAll (javaArgs );
1401
+ List <String > arguments = new ArrayList <>();
1402
+ arguments .addAll (javaArgs );
1402
1403
if (!bcp .isEmpty ()) {
1403
- command .add (bcp .stream ().map (Path ::toString ).collect (Collectors .joining (File .pathSeparator , "-Xbootclasspath/a:" , "" )));
1404
+ arguments .add (bcp .stream ().map (Path ::toString ).collect (Collectors .joining (File .pathSeparator , "-Xbootclasspath/a:" , "" )));
1404
1405
}
1405
1406
1406
1407
if (!cp .isEmpty ()) {
1407
- command .addAll (Arrays .asList ("-cp" , cp .stream ().map (Path ::toString ).collect (Collectors .joining (File .pathSeparator ))));
1408
+ arguments .addAll (Arrays .asList ("-cp" , cp .stream ().map (Path ::toString ).collect (Collectors .joining (File .pathSeparator ))));
1408
1409
}
1409
1410
if (!mp .isEmpty ()) {
1410
1411
List <String > strings = Arrays .asList ("--module-path" , mp .stream ().map (Path ::toString ).collect (Collectors .joining (File .pathSeparator )));
1411
- command .addAll (strings );
1412
+ arguments .addAll (strings );
1412
1413
}
1413
1414
1414
1415
if (USE_NI_JPMS ) {
1415
- command .addAll (Arrays .asList ("--module" , DEFAULT_GENERATOR_MODULE_NAME + "/" + DEFAULT_GENERATOR_CLASS_NAME ));
1416
+ arguments .addAll (Arrays .asList ("--module" , DEFAULT_GENERATOR_MODULE_NAME + "/" + DEFAULT_GENERATOR_CLASS_NAME ));
1416
1417
} else {
1417
- command .add (config .getGeneratorMainClass ());
1418
+ arguments .add (config .getGeneratorMainClass ());
1418
1419
}
1419
1420
if (IS_AOT && OS .getCurrent ().hasProcFS ) {
1420
1421
/*
1421
1422
* GR-8254: Ensure image-building VM shuts down even if native-image dies unexpected
1422
1423
* (e.g. using CTRL-C in Gradle daemon mode)
1423
1424
*/
1424
- command .addAll (Arrays .asList (SubstrateOptions .WATCHPID_PREFIX , "" + ProcessProperties .getProcessID ()));
1425
+ arguments .addAll (Arrays .asList (SubstrateOptions .WATCHPID_PREFIX , "" + ProcessProperties .getProcessID ()));
1425
1426
}
1426
1427
List <String > finalImageBuilderArgs = createImageBuilderArgs (imageArgs , imagecp , imagemp );
1427
- List <String > completeCommandList = Stream .concat (command .stream (), finalImageBuilderArgs .stream ()).collect (Collectors .toList ());
1428
+
1429
+ /* Construct ProcessBuilder command from final arguments */
1430
+ List <String > command = new ArrayList <>();
1431
+ command .add (canonicalize (config .getJavaExecutable ()).toString ());
1432
+ List <String > completeCommandList = new ArrayList <>(command );
1433
+ if (config .useJavaModules ()) { // Only in JDK9+ 'java' executable supports @argFiles.
1434
+ command .add (createVMInvocationArgumentFile (arguments ));
1435
+ } else {
1436
+ command .addAll (arguments );
1437
+ }
1428
1438
command .add (createImageBuilderArgumentFile (finalImageBuilderArgs ));
1439
+
1440
+ completeCommandList .addAll (Stream .concat (arguments .stream (), finalImageBuilderArgs .stream ()).collect (Collectors .toList ()));
1429
1441
final String commandLine = SubstrateUtil .getShellCommandString (completeCommandList , true );
1430
1442
if (isDiagnostics ()) {
1431
1443
// write to the diagnostics dir
0 commit comments