5050import java .util .List ;
5151import java .util .ListIterator ;
5252import java .util .Map ;
53+ import java .util .Objects ;
5354import java .util .Optional ;
5455import java .util .Properties ;
5556import java .util .Set ;
5859import java .util .function .BiFunction ;
5960import java .util .function .Consumer ;
6061import java .util .function .Function ;
62+ import java .util .function .Predicate ;
6163import java .util .jar .Attributes ;
6264import java .util .jar .JarFile ;
6365import java .util .jar .Manifest ;
@@ -1442,31 +1444,25 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
14421444 Function <Path , Path > substituteClassPath = useBundle () ? bundleSupport ::substituteClassPath : Function .identity ();
14431445 List <Path > finalImageClassPath = imagecp .stream ().map (substituteClassPath ).collect (Collectors .toList ());
14441446 Function <Path , Path > substituteModulePath = useBundle () ? bundleSupport ::substituteModulePath : Function .identity ();
1445- List <Path > substitutedModulePath = imagemp .stream ().map (substituteModulePath ).toList ();
1447+ List <Path > substitutedImageModulePath = imagemp .stream ().map (substituteModulePath ).toList ();
14461448
14471449 Map <String , Path > modules = listModulesFromPath (javaExecutable , Stream .concat (mp .stream (), imagemp .stream ()).distinct ().toList ());
14481450 if (!addModules .isEmpty ()) {
1449- List <String > addModulesForBuilderVM = new ArrayList <>();
1450- List <String > addModulesForImage = new ArrayList <>();
14511451
1452+ arguments .add ("-D" + ModuleSupport .PROPERTY_IMAGE_EXPLICITLY_ADDED_MODULES + "=" +
1453+ String .join ("," , addModules ));
1454+
1455+ List <String > addModulesForBuilderVM = new ArrayList <>();
14521456 for (String module : addModules ) {
14531457 Path jarPath = modules .get (module );
14541458 if (jarPath == null ) {
14551459 // boot module
14561460 addModulesForBuilderVM .add (module );
1457- } else {
1458- // non boot module
1459- addModulesForImage .add (module );
14601461 }
14611462 }
14621463
14631464 if (!addModulesForBuilderVM .isEmpty ()) {
1464- arguments .add (DefaultOptionHandler .addModulesOption + "=" + String .join ("," ,
1465- addModulesForBuilderVM ));
1466- }
1467- if (!addModulesForImage .isEmpty ()) {
1468- arguments .add ("-D" + ModuleSupport .PROPERTY_IMAGE_EXPLICITLY_ADDED_MODULES + "=" +
1469- String .join ("," , addModulesForImage ));
1465+ arguments .add (DefaultOptionHandler .addModulesOption + "=" + String .join ("," , addModulesForBuilderVM ));
14701466 }
14711467 }
14721468
@@ -1486,28 +1482,27 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
14861482 * modules from the module-path that are either already installed in the JDK as boot module,
14871483 * or were explicitly added to the builder module-path.
14881484 *
1489- * First compute all jar paths that may remain on the module-path.
1485+ * First compute all module- jar paths that are not on the builder module-path.
14901486 */
1491- Set <Path > retainedModulePaths = modules .entrySet ().stream ()
1492- .filter (( entry ) -> entry . getValue () != null && ! mp . contains ( entry . getValue ()) )
1493- .map (( entry ) -> entry . getValue (). toAbsolutePath ( ))
1487+ Set <Path > nonBuilderModulePaths = modules .values ().stream ()
1488+ .filter (Objects :: nonNull )
1489+ .filter ( Predicate . not ( mp :: contains ))
14941490 .collect (Collectors .toSet ());
14951491
14961492 /*
14971493 * Now we need to filter the substituted module path list for all the modules that may
14981494 * remain on the module-path.
14991495 *
1500- * This should normally not be necessary, as the retainedModulePaths should already be the
1496+ * This should normally not be necessary, as the nonBuilderModulePaths should already be the
15011497 * set of jar files for the image module path. Nevertheless, we use the original definition
15021498 * of the module path to preserve the order of the original module path and as a precaution
15031499 * to protect against --list-modules returning too many modules.
15041500 */
1505- List <Path > finalModulePath = substitutedModulePath .stream ()
1506- .map ((path ) -> path .toAbsolutePath ())
1507- .filter ((path ) -> retainedModulePaths .contains (path ))
1501+ List <Path > finalImageModulePath = substitutedImageModulePath .stream ()
1502+ .filter (nonBuilderModulePaths ::contains )
15081503 .toList ();
15091504
1510- List <String > finalImageBuilderArgs = createImageBuilderArgs (finalImageArgs , finalImageClassPath , finalModulePath );
1505+ List <String > finalImageBuilderArgs = createImageBuilderArgs (finalImageArgs , finalImageClassPath , finalImageModulePath );
15111506
15121507 /* Construct ProcessBuilder command from final arguments */
15131508 List <String > command = new ArrayList <>();
@@ -1584,7 +1579,10 @@ private static Map<String, Path> listModulesFromPath(String javaExecutable, Coll
15841579 if (modulePath .isEmpty ()) {
15851580 return Map .of ();
15861581 }
1587- return callListModules (javaExecutable , List .of ("-p" , modulePath .stream ().map (Path ::toString ).collect (Collectors .joining (File .pathSeparator ))));
1582+ String modulePathEntries = modulePath .stream ()
1583+ .map (Path ::toString )
1584+ .collect (Collectors .joining (File .pathSeparator ));
1585+ return callListModules (javaExecutable , List .of ("-p" , modulePathEntries ));
15881586 }
15891587
15901588 /**
@@ -1615,7 +1613,7 @@ private static Map<String, Path> callListModules(String javaExecutable, List<Str
16151613 Path externalPath = null ;
16161614 if (splitString .length > 1 ) {
16171615 String pathURI = splitString [1 ]; // url: file://path/to/file
1618- externalPath = Path .of (URI .create (pathURI ));
1616+ externalPath = Path .of (URI .create (pathURI )). toAbsolutePath () ;
16191617 }
16201618 result .put (splitModuleNameAndVersion [0 ], externalPath );
16211619 }
0 commit comments