< prev index next >
src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java
Print this page
rev 50671 : [mq]: validate-modules
@@ -134,11 +134,11 @@
}
/**
* Initialize the module system, returning the boot layer.
*
- * @see java.lang.System#initPhase2()
+ * @see java.lang.System#initPhase2(boolean, boolean)
*/
public static ModuleLayer boot() throws Exception {
// Step 0: Command line options
@@ -211,15 +211,17 @@
Modules.defineModule(null, base.descriptor(), baseUri);
Counters.add("jdk.module.boot.2.defineBaseTime", t2);
- // Step 2a: If --validate-modules is specified then the VM needs to
- // start with only system modules, all other options are ignored.
+ // Step 2a: Scan all modules when --validate-modules specified
if (getAndRemoveProperty("jdk.module.validation") != null) {
- return createBootLayerForValidation();
+ int errors = ModulePathValidator.scanAllModules(System.out);
+ if (errors > 0) {
+ fail("Validation of module path failed");
+ }
}
// Step 3: If resolution is needed then create the module finder and
// the set of root modules to resolve.
@@ -418,30 +420,10 @@
return bootLayer;
}
/**
- * Create a boot module layer for validation that resolves all
- * system modules.
- */
- private static ModuleLayer createBootLayerForValidation() {
- Set<String> allSystem = ModuleFinder.ofSystem().findAll()
- .stream()
- .map(ModuleReference::descriptor)
- .map(ModuleDescriptor::name)
- .collect(Collectors.toSet());
-
- Configuration cf = SharedSecrets.getJavaLangModuleAccess()
- .resolveAndBind(ModuleFinder.ofSystem(),
- allSystem,
- null);
-
- Function<String, ClassLoader> clf = ModuleLoaderMap.mappingFunction(cf);
- return ModuleLayer.empty().defineModules(cf, clf);
- }
-
- /**
* Load/register the modules to the built-in class loaders.
*/
private static void loadModules(Configuration cf,
Function<String, ClassLoader> clf) {
for (ResolvedModule resolvedModule : cf.modules()) {
< prev index next >