8169606: jdeps --list-reduced-deps should not show java.base as all modules require it
authormchung
Sat, 12 Nov 2016 09:26:08 -0800
changeset 41998 feae61dc2280
parent 41997 79da2a8f4274
child 41999 dbf796210eff
8169606: jdeps --list-reduced-deps should not show java.base as all modules require it Reviewed-by: dfuchs
langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java
langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java
langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Module.java
langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ModuleExportsAnalyzer.java
langtools/test/tools/jdeps/listdeps/ListModuleDeps.java
langtools/test/tools/jdeps/listdeps/src/hi/Hi.java
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java	Fri Nov 11 17:32:21 2016 -0800
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java	Sat Nov 12 09:26:08 2016 -0800
@@ -89,6 +89,7 @@
                                List<Path> classpaths,
                                List<Archive> initialArchives,
                                boolean allDefaultModules,
+                               boolean allSystemModules,
                                Runtime.Version version)
         throws IOException
     {
@@ -107,6 +108,11 @@
                 roots.isEmpty() || allDefaultModules) {
             mods.addAll(systemModulePath.defaultSystemRoots());
         }
+        if (allSystemModules) {
+            systemModulePath.findAll().stream()
+                .map(mref -> mref.descriptor().name())
+                .forEach(mods::add);
+        }
 
         this.configuration = Configuration.empty()
                 .resolveRequires(finder, ModuleFinder.of(), mods);
@@ -488,6 +494,7 @@
         ModuleFinder appModulePath;
         boolean addAllApplicationModules;
         boolean addAllDefaultModules;
+        boolean addAllSystemModules;
         Runtime.Version version;
 
         public Builder() {
@@ -533,8 +540,7 @@
          * Include all system modules and modules found on modulepath
          */
         public Builder allModules() {
-            systemModulePath.moduleNames()
-                            .forEach(this.rootModules::add);
+            this.addAllSystemModules = true;
             this.addAllApplicationModules = true;
             return this;
         }
@@ -588,6 +594,7 @@
                                           classPaths,
                                           initialArchives,
                                           addAllDefaultModules,
+                                          addAllSystemModules,
                                           version);
         }
 
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java	Fri Nov 11 17:32:21 2016 -0800
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java	Sat Nov 12 09:26:08 2016 -0800
@@ -966,7 +966,8 @@
                                              log).run();
         }
 
-        public boolean allModules() {
+        @Override
+        boolean allModules() {
             return true;
         }
     }
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Module.java	Fri Nov 11 17:32:21 2016 -0800
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Module.java	Sat Nov 12 09:26:08 2016 -0800
@@ -81,7 +81,7 @@
      * Returns module name
      */
     public String name() {
-        return descriptor.name();
+        return descriptor != null ? descriptor.name() : getName();
     }
 
     public boolean isNamed() {
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ModuleExportsAnalyzer.java	Fri Nov 11 17:32:21 2016 -0800
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ModuleExportsAnalyzer.java	Sat Nov 12 09:26:08 2016 -0800
@@ -33,6 +33,7 @@
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import static com.sun.tools.jdeps.Analyzer.NOT_FOUND;
 
@@ -140,20 +141,34 @@
         Set<Module> modules = builder.build().adjacentNodes(root);
 
         // if reduced is set, apply transition reduction
-        Set<Module> reducedSet = reduced ? builder.reduced().adjacentNodes(root)
-                                         : modules;
+        Set<Module> reducedSet;
+        if (reduced) {
+            Set<Module> nodes = builder.reduced().adjacentNodes(root);
+            if (nodes.size() == 1) {
+                // java.base only
+                reducedSet = nodes;
+            } else {
+                // java.base is mandated and can be excluded from the reduced graph
+                reducedSet = nodes.stream()
+                    .filter(m -> !"java.base".equals(m.name()) ||
+                                    jdkinternals.containsKey("java.base"))
+                    .collect(Collectors.toSet());
+            }
+        } else {
+            reducedSet = modules;
+        }
 
         modules.stream()
                .sorted(Comparator.comparing(Module::name))
                .forEach(m -> {
-                if (jdkinternals.containsKey(m)) {
-                    jdkinternals.get(m).stream()
-                        .sorted()
-                        .forEach(pn -> writer.format("   %s/%s%n", m, pn));
-                } else if (reducedSet.contains(m)){
-                    // if the transition reduction is applied, show the reduced graph
-                    writer.format("   %s%n", m);
-                }
+                    if (jdkinternals.containsKey(m)) {
+                        jdkinternals.get(m).stream()
+                            .sorted()
+                            .forEach(pn -> writer.format("   %s/%s%n", m, pn));
+                    } else if (reducedSet.contains(m)){
+                        // if the transition reduction is applied, show the reduced graph
+                        writer.format("   %s%n", m);
+                    }
             });
     }
 
--- a/langtools/test/tools/jdeps/listdeps/ListModuleDeps.java	Fri Nov 11 17:32:21 2016 -0800
+++ b/langtools/test/tools/jdeps/listdeps/ListModuleDeps.java	Sat Nov 12 09:26:08 2016 -0800
@@ -24,7 +24,7 @@
 /*
  * @test
  * @bug 8167057
- * @summary Tests split packages
+ * @summary Tests --list-deps and --list-reduced-deps options
  * @modules java.logging
  *          java.xml
  *          jdk.compiler
@@ -53,6 +53,8 @@
     private static final Path CLASSES_DIR = Paths.get("classes");
     private static final Path LIB_DIR = Paths.get("lib");
 
+    private static final Path HI_CLASS =
+        CLASSES_DIR.resolve("hi").resolve("Hi.class");
     private static final Path FOO_CLASS =
         CLASSES_DIR.resolve("z").resolve("Foo.class");
     private static final Path BAR_CLASS =
@@ -68,6 +70,9 @@
         // compile library
         assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "lib"), LIB_DIR));
 
+        // simple program depends only on java.base
+        assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "hi"), CLASSES_DIR));
+
         // compile classes in unnamed module
         assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "z"),
             CLASSES_DIR,
@@ -117,6 +122,11 @@
                             }
             },
 
+            { HI_CLASS,     new String[] {
+                                "java.base"
+                            }
+            },
+
             { FOO_CLASS,    new String[] {
                                 "java.base",
                                 "java.logging",
@@ -155,9 +165,12 @@
                             }
             },
 
+            { HI_CLASS,     new String[] {
+                                "java.base"
+                            }
+            },
 
             { FOO_CLASS,    new String[] {
-                                "java.base",
                                 "java.sql",
                                 "unnamed module: lib"
                             }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/jdeps/listdeps/src/hi/Hi.java	Sat Nov 12 09:26:08 2016 -0800
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package hi;
+
+public class Hi {
+}