--- old/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java 2018-11-14 16:47:43.000000000 -0800 +++ new/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java 2018-11-14 16:47:42.000000000 -0800 @@ -83,42 +83,25 @@ private final List classpathArchives = new ArrayList<>(); private final List initialArchives = new ArrayList<>(); private final Set rootModules = new HashSet<>(); - private final Configuration configuration; private final Runtime.Version version; - private JdepsConfiguration(SystemModuleFinder systemModulePath, + private JdepsConfiguration(Configuration config, + SystemModuleFinder systemModulePath, ModuleFinder finder, Set roots, List classpaths, List initialArchives, - Set tokens, Runtime.Version version) throws IOException { trace("root: %s%n", roots); - this.system = systemModulePath; this.finder = finder; this.version = version; - // build root set for resolution - Set mods = new HashSet<>(roots); - if (tokens.contains(ALL_SYSTEM)) { - systemModulePath.findAll().stream() - .map(mref -> mref.descriptor().name()) - .forEach(mods::add); - } - - if (tokens.contains(ALL_DEFAULT)) { - mods.addAll(systemModulePath.defaultSystemRoots()); - } - - this.configuration = Configuration.empty() - .resolve(finder, ModuleFinder.of(), mods); - - this.configuration.modules().stream() - .map(ResolvedModule::reference) - .forEach(this::addModuleReference); + config.modules().stream() + .map(ResolvedModule::reference) + .forEach(this::addModuleReference); // packages in unnamed module initialArchives.forEach(archive -> { @@ -538,14 +521,6 @@ .forEach(rootModules::add); } - // add all modules to the root set for unnamed module or set explicitly - boolean unnamed = !initialArchives.isEmpty() || !classPaths.isEmpty(); - if ((unnamed || tokens.contains(ALL_MODULE_PATH)) && appModulePath != null) { - appModulePath.findAll().stream() - .map(mref -> mref.descriptor().name()) - .forEach(rootModules::add); - } - // no archive is specified for analysis // add all system modules as root if --add-modules ALL-SYSTEM is specified if (tokens.contains(ALL_SYSTEM) && rootModules.isEmpty() && @@ -556,16 +531,41 @@ .forEach(rootModules::add); } - if (unnamed && !tokens.contains(ALL_DEFAULT)) { - tokens.add(ALL_SYSTEM); + // add all modules on app module path as roots if ALL-MODULE-PATH is specified + if ((tokens.contains(ALL_MODULE_PATH)) && appModulePath != null) { + appModulePath.findAll().stream() + .map(mref -> mref.descriptor().name()) + .forEach(rootModules::add); + } + + + // build root set for module resolution + Set mods = new HashSet<>(rootModules); + // if archives are specified for analysis, then consider as unnamed module + boolean unnamed = !initialArchives.isEmpty() || !classPaths.isEmpty(); + if (tokens.contains(ALL_DEFAULT)) { + mods.addAll(systemModulePath.defaultSystemRoots()); + } else if (tokens.contains(ALL_SYSTEM) || unnamed) { + // resolve all system modules as unnamed module may reference any class + systemModulePath.findAll().stream() + .map(mref -> mref.descriptor().name()) + .forEach(mods::add); + } + if (unnamed && appModulePath != null) { + // resolve all modules on module path as unnamed module may reference any class + appModulePath.findAll().stream() + .map(mref -> mref.descriptor().name()) + .forEach(mods::add); } - return new JdepsConfiguration(systemModulePath, + // resolve the module graph + Configuration config = Configuration.empty().resolve(finder, ModuleFinder.of(), mods); + return new JdepsConfiguration(config, + systemModulePath, finder, rootModules, classPaths, initialArchives, - tokens, version); }