src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java
changeset 52650 c16b6cc93272
parent 50738 6cc2dc161c64
--- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java	Wed Nov 21 22:33:33 2018 -0800
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java	Wed Nov 21 22:34:01 2018 -0800
@@ -83,42 +83,27 @@
     private final List<Archive> classpathArchives = new ArrayList<>();
     private final List<Archive> initialArchives = new ArrayList<>();
     private final Set<Module> 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<String> roots,
                                List<Path> classpaths,
                                List<Archive> initialArchives,
-                               Set<String> tokens,
                                Runtime.Version version)
         throws IOException
     {
         trace("root: %s%n", roots);
-
+        trace("initial archives: %s%n", initialArchives);
+        trace("class path: %s%n", classpaths);
         this.system = systemModulePath;
         this.finder = finder;
         this.version = version;
 
-        // build root set for resolution
-        Set<String> 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 +523,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 +533,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);
             }
 
-            return new JdepsConfiguration(systemModulePath,
+
+            // build root set for module resolution
+            Set<String> 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);
+            }
+
+            // resolve the module graph
+            Configuration config = Configuration.empty().resolve(finder, ModuleFinder.of(), mods);
+            return new JdepsConfiguration(config,
+                                          systemModulePath,
                                           finder,
                                           rootModules,
                                           classPaths,
                                           initialArchives,
-                                          tokens,
                                           version);
         }