136 // --module-path option specified to the launcher 137 ModuleFinder appModulePath = createModulePathFinder("jdk.module.path"); 138 139 // The module finder: [--upgrade-module-path] system [--module-path] 140 ModuleFinder finder = systemModules; 141 if (appModulePath != null) 142 finder = ModuleFinder.compose(finder, appModulePath); 143 144 // The root modules to resolve 145 Set<String> roots = new HashSet<>(); 146 147 // launcher -m option to specify the main/initial module 148 String mainModule = System.getProperty("jdk.module.main"); 149 if (mainModule != null) 150 roots.add(mainModule); 151 152 // additional module(s) specified by --add-modules 153 boolean addAllDefaultModules = false; 154 boolean addAllSystemModules = false; 155 boolean addAllApplicationModules = false; 156 String propValue = getAndRemoveProperty("jdk.module.addmods"); 157 if (propValue != null) { 158 for (String mod: propValue.split(",")) { 159 switch (mod) { 160 case ALL_DEFAULT: 161 addAllDefaultModules = true; 162 break; 163 case ALL_SYSTEM: 164 addAllSystemModules = true; 165 break; 166 case ALL_MODULE_PATH: 167 addAllApplicationModules = true; 168 break; 169 default : 170 roots.add(mod); 171 } 172 } 173 } 174 175 // --limit-modules 176 propValue = getAndRemoveProperty("jdk.module.limitmods"); 177 if (propValue != null) { 178 Set<String> mods = new HashSet<>(); 179 for (String mod: propValue.split(",")) { 180 mods.add(mod); 181 } 182 finder = limitFinder(finder, mods, roots); 183 } 184 185 // If there is no initial module specified then assume that the initial 186 // module is the unnamed module of the application class loader. This 187 // is implemented by resolving "java.se" and all (non-java.*) modules 188 // that export an API. If "java.se" is not observable then all java.* 189 // modules are resolved. 190 if (mainModule == null || addAllDefaultModules) { 191 boolean hasJava = false; 192 if (systemModules.find(JAVA_SE).isPresent()) { 193 // java.se is a system module 194 if (finder == systemModules || finder.find(JAVA_SE).isPresent()) { 195 // java.se is observable 196 hasJava = true; 375 376 /** 377 * Creates a finder from the module path that is the value of the given 378 * system property. 379 */ 380 private static ModuleFinder createModulePathFinder(String prop) { 381 String s = System.getProperty(prop); 382 if (s == null) { 383 return null; 384 } else { 385 String[] dirs = s.split(File.pathSeparator); 386 Path[] paths = new Path[dirs.length]; 387 int i = 0; 388 for (String dir: dirs) { 389 paths[i++] = Paths.get(dir); 390 } 391 return ModuleFinder.of(paths); 392 } 393 } 394 395 396 /** 397 * Process the --add-reads options to add any additional read edges that 398 * are specified on the command-line. 399 */ 400 private static void addExtraReads(Layer bootLayer) { 401 402 // decode the command line options 403 Map<String, Set<String>> map = decode("jdk.module.addreads."); 404 405 for (Map.Entry<String, Set<String>> e : map.entrySet()) { 406 407 // the key is $MODULE 408 String mn = e.getKey(); 409 Optional<Module> om = bootLayer.findModule(mn); 410 if (!om.isPresent()) 411 fail("Unknown module: " + mn); 412 Module m = om.get(); 413 414 // the value is the set of other modules (by name) | 136 // --module-path option specified to the launcher 137 ModuleFinder appModulePath = createModulePathFinder("jdk.module.path"); 138 139 // The module finder: [--upgrade-module-path] system [--module-path] 140 ModuleFinder finder = systemModules; 141 if (appModulePath != null) 142 finder = ModuleFinder.compose(finder, appModulePath); 143 144 // The root modules to resolve 145 Set<String> roots = new HashSet<>(); 146 147 // launcher -m option to specify the main/initial module 148 String mainModule = System.getProperty("jdk.module.main"); 149 if (mainModule != null) 150 roots.add(mainModule); 151 152 // additional module(s) specified by --add-modules 153 boolean addAllDefaultModules = false; 154 boolean addAllSystemModules = false; 155 boolean addAllApplicationModules = false; 156 for (String mod: getExtraAddModules()) { 157 switch (mod) { 158 case ALL_DEFAULT: 159 addAllDefaultModules = true; 160 break; 161 case ALL_SYSTEM: 162 addAllSystemModules = true; 163 break; 164 case ALL_MODULE_PATH: 165 addAllApplicationModules = true; 166 break; 167 default : 168 roots.add(mod); 169 } 170 } 171 172 // --limit-modules 173 String propValue = getAndRemoveProperty("jdk.module.limitmods"); 174 if (propValue != null) { 175 Set<String> mods = new HashSet<>(); 176 for (String mod: propValue.split(",")) { 177 mods.add(mod); 178 } 179 finder = limitFinder(finder, mods, roots); 180 } 181 182 // If there is no initial module specified then assume that the initial 183 // module is the unnamed module of the application class loader. This 184 // is implemented by resolving "java.se" and all (non-java.*) modules 185 // that export an API. If "java.se" is not observable then all java.* 186 // modules are resolved. 187 if (mainModule == null || addAllDefaultModules) { 188 boolean hasJava = false; 189 if (systemModules.find(JAVA_SE).isPresent()) { 190 // java.se is a system module 191 if (finder == systemModules || finder.find(JAVA_SE).isPresent()) { 192 // java.se is observable 193 hasJava = true; 372 373 /** 374 * Creates a finder from the module path that is the value of the given 375 * system property. 376 */ 377 private static ModuleFinder createModulePathFinder(String prop) { 378 String s = System.getProperty(prop); 379 if (s == null) { 380 return null; 381 } else { 382 String[] dirs = s.split(File.pathSeparator); 383 Path[] paths = new Path[dirs.length]; 384 int i = 0; 385 for (String dir: dirs) { 386 paths[i++] = Paths.get(dir); 387 } 388 return ModuleFinder.of(paths); 389 } 390 } 391 392 /** 393 * Returns the set of module names specified via --add-modules options 394 * on the command line 395 */ 396 private static Set<String> getExtraAddModules() { 397 String prefix = "jdk.module.addmods."; 398 int index = 0; 399 400 // the system property is removed after decoding 401 String value = getAndRemoveProperty(prefix + index); 402 if (value == null) { 403 return Collections.emptySet(); 404 } 405 406 Set<String> modules = new HashSet<>(); 407 while (value != null) { 408 for (String s : value.split(",")) { 409 if (s.length() > 0) modules.add(s); 410 } 411 412 index++; 413 value = getAndRemoveProperty(prefix + index); 414 } 415 416 return modules; 417 } 418 419 /** 420 * Process the --add-reads options to add any additional read edges that 421 * are specified on the command-line. 422 */ 423 private static void addExtraReads(Layer bootLayer) { 424 425 // decode the command line options 426 Map<String, Set<String>> map = decode("jdk.module.addreads."); 427 428 for (Map.Entry<String, Set<String>> e : map.entrySet()) { 429 430 // the key is $MODULE 431 String mn = e.getKey(); 432 Optional<Module> om = bootLayer.findModule(mn); 433 if (!om.isPresent()) 434 fail("Unknown module: " + mn); 435 Module m = om.get(); 436 437 // the value is the set of other modules (by name) |