@@ -1529,7 +1529,8 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
15291529 Function <Path , Path > substituteModulePath = useBundle () ? bundleSupport ::substituteModulePath : Function .identity ();
15301530 List <Path > substitutedImageModulePath = imagemp .stream ().map (substituteModulePath ).toList ();
15311531
1532- Map <String , Path > modules = listModulesFromPath (javaExecutable , javaArgs , Stream .concat (mp .stream (), imagemp .stream ()).distinct ().toList ());
1532+ List <String > mainClassArg = config .getGeneratorMainClass ();
1533+ Map <String , Path > modules = listModulesFromPath (javaExecutable , javaArgs , mainClassArg , mp .stream ().distinct ().toList (), imagemp .stream ().distinct ().toList ());
15331534 if (!addModules .isEmpty ()) {
15341535
15351536 arguments .add ("-D" + ModuleSupport .PROPERTY_IMAGE_EXPLICITLY_ADDED_MODULES + "=" +
@@ -1699,34 +1700,41 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
16991700 /**
17001701 * Resolves and lists all modules given a module path.
17011702 *
1702- * @see #callListModules(String, List, List)
1703+ * @see #callListModules(String, List, List, List, List )
17031704 */
1704- private Map <String , Path > listModulesFromPath (String javaExecutable , List <String > javaArgs , List <Path > modulePath ) {
1705+ private Map <String , Path > listModulesFromPath (String javaExecutable , List <String > javaArgs , List <String > mainClassArg , List < Path > modulePath , List < Path > imagemp ) {
17051706 if (modulePath .isEmpty () || !config .modulePathBuild ) {
17061707 return Map .of ();
17071708 }
17081709 String modulePathEntries = modulePath .stream ()
17091710 .map (Path ::toString )
17101711 .collect (Collectors .joining (File .pathSeparator ));
1711- return callListModules (javaExecutable , javaArgs , List .of ("-p" , modulePathEntries ));
1712+ String imagePathEntries = imagemp .stream ()
1713+ .map (Path ::toString )
1714+ .collect (Collectors .joining (File .pathSeparator ));
1715+ List <String > imagempArgs = List .of ("-imagemp" , imagePathEntries );
1716+ List <String > modulePathArgs = List .of ("--module-path" , modulePathEntries );
1717+ return callListModules (javaExecutable , javaArgs , mainClassArg , imagempArgs , modulePathArgs );
17121718 }
17131719
17141720 /**
1715- * Calls <code>java $arguments --list-modules</code> to list all modules and parse the output.
1716- * The output consists of a map with module name as key and {@link Path} to jar file if the
1717- * module is not installed as part of the JDK. If the module is installed as part of the
1721+ * Calls the image generator's <code>--list-modules</code> to list all modules and parses the
1722+ * output. The output consists of a map with module name as key and {@link Path} to jar file if
1723+ * the module is not installed as part of the JDK. If the module is installed as part of the
17181724 * jdk/boot-layer then a <code>null</code> path will be returned.
17191725 * <p>
17201726 * This is a much more robust solution then trying to parse the JDK file structure manually.
17211727 */
1722- private static Map <String , Path > callListModules (String javaExecutable , List <String > javaArgs , List <String > arguments ) {
1728+ private static Map <String , Path > callListModules (String javaExecutable , List <String > javaArgs , List <String > mainClassArg , List < String > imagempArgs , List < String > modulePathArgs ) {
17231729 Process listModulesProcess = null ;
17241730 Map <String , Path > result = new LinkedHashMap <>();
17251731 try {
17261732 var pb = new ProcessBuilder (javaExecutable );
17271733 pb .command ().addAll (javaArgs );
1728- pb .command ().addAll (arguments );
1729- pb .command ().add ("--list-modules" );
1734+ pb .command ().addAll (modulePathArgs );
1735+ pb .command ().addAll (mainClassArg );
1736+ pb .command ().addAll (imagempArgs );
1737+ pb .command ().add ("-H:+ListModules" );
17301738 pb .environment ().clear ();
17311739 listModulesProcess = pb .start ();
17321740
0 commit comments