changeset 4462:c18249ecb690

8169606: jdeps --list-reduced-deps should not show java.base as all modules require it Reviewed-by: dfuchs
author mchung
date Sat, 12 Nov 2016 09:26:08 -0800
parents 768f685bceb7
children 120957324d6e
files src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Module.java src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ModuleExportsAnalyzer.java test/tools/jdeps/listdeps/ListModuleDeps.java test/tools/jdeps/listdeps/src/hi/Hi.java
diffstat 6 files changed, 79 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java	Fri Nov 11 17:32:21 2016 -0800
+++ b/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/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java	Fri Nov 11 17:32:21 2016 -0800
+++ b/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/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Module.java	Fri Nov 11 17:32:21 2016 -0800
+++ b/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/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ModuleExportsAnalyzer.java	Fri Nov 11 17:32:21 2016 -0800
+++ b/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/test/tools/jdeps/listdeps/ListModuleDeps.java	Fri Nov 11 17:32:21 2016 -0800
+++ b/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/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 {
+}