8171418: Remove jdeps internal --include-system-modules option
authormchung
Mon, 19 Dec 2016 12:30:39 -0800
changeset 42840 dfe1a03d4db4
parent 42839 33f705c03879
child 42841 1768507dae6b
8171418: Remove jdeps internal --include-system-modules option Reviewed-by: dfuchs, lancea
langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/DepsAnalyzer.java
langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/InverseDepsAnalyzer.java
langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java
langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsFilter.java
langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java
langtools/test/tools/jdeps/lib/JdepsUtil.java
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/DepsAnalyzer.java	Mon Dec 19 11:15:01 2016 -0800
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/DepsAnalyzer.java	Mon Dec 19 12:30:39 2016 -0800
@@ -28,6 +28,7 @@
 import com.sun.tools.classfile.Dependency.Location;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Deque;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
@@ -91,7 +92,7 @@
         // classpath to the root archives
         if (filter.hasIncludePattern() || filter.hasTargetFilter()) {
             configuration.getModules().values().stream()
-                .filter(source -> filter.include(source) && filter.matches(source))
+                .filter(source -> include(source) && filter.matches(source))
                 .forEach(this.rootArchives::add);
         }
 
@@ -161,14 +162,14 @@
     Set<Archive> archives() {
         if (filter.requiresFilter().isEmpty()) {
             return archives.stream()
-                .filter(filter::include)
+                .filter(this::include)
                 .filter(Archive::hasDependences)
                 .collect(Collectors.toSet());
         } else {
             // use the archives that have dependences and not specified in --require
             return archives.stream()
-                .filter(filter::include)
-                .filter(source -> !filter.requiresFilter().contains(source))
+                .filter(this::include)
+                .filter(source -> !filter.requiresFilter().contains(source.getName()))
                 .filter(source ->
                         source.getDependencies()
                               .map(finder::locationToArchive)
@@ -197,7 +198,6 @@
                         .distinct()
                         .map(configuration::findClass)
                         .flatMap(Optional::stream)
-                        .filter(filter::include)
                         .collect(toSet());
     }
 
@@ -238,7 +238,7 @@
                     continue;
 
                 Archive archive = configuration.findClass(target).orElse(null);
-                if (archive != null && filter.include(archive)) {
+                if (archive != null) {
                     archives.add(archive);
 
                     String name = target.getName();
@@ -257,6 +257,21 @@
         } while (!unresolved.isEmpty() && depth-- > 0);
     }
 
+    /*
+     * Tests if the given archive is requested for analysis.
+     * It includes the root modules specified in --module, --add-modules
+     * or modules specified on the command line
+     *
+     * This filters system module by default unless they are explicitly
+     * requested.
+     */
+    public boolean include(Archive source) {
+        Module module = source.getModule();
+        // skip system module by default
+        return  !module.isSystem()
+                    || configuration.rootModules().contains(source);
+    }
+
     // ----- for testing purpose -----
 
     public static enum Info {
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/InverseDepsAnalyzer.java	Mon Dec 19 11:15:01 2016 -0800
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/InverseDepsAnalyzer.java	Mon Dec 19 12:30:39 2016 -0800
@@ -140,9 +140,8 @@
             // include all target nodes
             targets().forEach(builder::addNode);
 
-            // transpose the module graph - may filter JDK module
+            // transpose the module graph
             configuration.getModules().values().stream()
-                .filter(filter::include)
                 .forEach(m -> {
                     builder.addNode(m);
                     m.descriptor().requires().stream()
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java	Mon Dec 19 11:15:01 2016 -0800
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsConfiguration.java	Mon Dec 19 12:30:39 2016 -0800
@@ -70,6 +70,7 @@
     // the token for "all modules on the module path"
     public static final String ALL_MODULE_PATH = "ALL-MODULE-PATH";
     public static final String ALL_DEFAULT = "ALL-DEFAULT";
+    public static final String ALL_SYSTEM = "ALL-SYSTEM";
     public static final String MODULE_INFO = "module-info.class";
 
     private final SystemModuleFinder system;
@@ -199,12 +200,10 @@
         return m!= null ? Optional.of(m.descriptor()) : Optional.empty();
     }
 
-    boolean isSystem(Module m) {
-        return system.find(m.name()).isPresent();
-    }
-
     boolean isValidToken(String name) {
-        return ALL_MODULE_PATH.equals(name) || ALL_DEFAULT.equals(name);
+        return ALL_MODULE_PATH.equals(name) ||
+                ALL_DEFAULT.equals(name) ||
+                ALL_SYSTEM.equals(name);
     }
 
     /**
@@ -534,6 +533,9 @@
                     case ALL_DEFAULT:
                         this.addAllDefaultModules = true;
                         break;
+                    case ALL_SYSTEM:
+                        this.addAllSystemModules = true;
+                        break;
                     default:
                         this.rootModules.add(mn);
                 }
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsFilter.java	Mon Dec 19 11:15:01 2016 -0800
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsFilter.java	Mon Dec 19 12:30:39 2016 -0800
@@ -29,11 +29,8 @@
 import com.sun.tools.classfile.Dependency.Location;
 
 import java.util.HashSet;
-import java.util.Optional;
 import java.util.Set;
 import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 /*
  * Filter configured based on the input jdeps option
@@ -59,7 +56,6 @@
     private final boolean filterSameArchive;
     private final boolean findJDKInternals;
     private final Pattern includePattern;
-    private final Pattern includeSystemModules;
 
     private final Set<String> requires;
 
@@ -69,7 +65,6 @@
                         boolean filterSameArchive,
                         boolean findJDKInternals,
                         Pattern includePattern,
-                        Pattern includeSystemModules,
                         Set<String> requires) {
         this.filter = filter;
         this.filterPattern = filterPattern;
@@ -77,7 +72,6 @@
         this.filterSameArchive = filterSameArchive;
         this.findJDKInternals = findJDKInternals;
         this.includePattern = includePattern;
-        this.includeSystemModules = includeSystemModules;
         this.requires = requires;
     }
 
@@ -112,16 +106,8 @@
         return hasTargetFilter();
     }
 
-    public boolean include(Archive source) {
-        Module module = source.getModule();
-        // skip system module by default; or if includeSystemModules is set
-        // only include the ones matching the pattern
-        return  !module.isSystem() || (includeSystemModules != null &&
-            includeSystemModules.matcher(module.name()).matches());
-    }
-
     public boolean hasIncludePattern() {
-        return includePattern != null || includeSystemModules != null;
+        return includePattern != null;
     }
 
     public boolean hasTargetFilter() {
@@ -197,7 +183,6 @@
     }
 
     public static class Builder {
-        static Pattern SYSTEM_MODULE_PATTERN = Pattern.compile("java\\..*|jdk\\..*|javafx\\..*");
         Pattern filterPattern;
         Pattern regex;
         boolean filterSamePackage;
@@ -205,10 +190,11 @@
         boolean findJDKInterals;
         // source filters
         Pattern includePattern;
-        Pattern includeSystemModules;
         Set<String> requires = new HashSet<>();
         Set<String> targetPackages = new HashSet<>();
 
+        public Builder() {};
+
         public Builder packages(Set<String> packageNames) {
             this.targetPackages.addAll(packageNames);
             return this;
@@ -229,8 +215,6 @@
         public Builder requires(String name, Set<String> packageNames) {
             this.requires.add(name);
             this.targetPackages.addAll(packageNames);
-
-            includeIfSystemModule(name);
             return this;
         }
         public Builder findJDKInternals(boolean value) {
@@ -241,17 +225,6 @@
             this.includePattern = regex;
             return this;
         }
-        public Builder includeSystemModules(Pattern regex) {
-            this.includeSystemModules = regex;
-            return this;
-        }
-        public Builder includeIfSystemModule(String name) {
-            if (includeSystemModules == null &&
-                    SYSTEM_MODULE_PATTERN.matcher(name).matches()) {
-                this.includeSystemModules = SYSTEM_MODULE_PATTERN;
-            }
-            return this;
-        }
 
         public JdepsFilter build() {
             Dependency.Filter filter = null;
@@ -266,7 +239,6 @@
                                    filterSameArchive,
                                    findJDKInterals,
                                    includePattern,
-                                   includeSystemModules,
                                    requires);
         }
 
--- a/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java	Mon Dec 19 11:15:01 2016 -0800
+++ b/langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java	Mon Dec 19 12:30:39 2016 -0800
@@ -386,13 +386,6 @@
             }
         },
 
-        // Another alternative to list modules in --add-modules option
-        new HiddenOption(true, "--include-system-modules") {
-            void process(JdepsTask task, String opt, String arg) throws BadArgs {
-                task.options.includeSystemModulePattern = Pattern.compile(arg);
-            }
-        },
-
         new Option(false, "-P", "-profile") {
             void process(JdepsTask task, String opt, String arg) throws BadArgs {
                 task.options.showProfile = true;
@@ -1021,8 +1014,8 @@
 
         // source filters
         builder.includePattern(options.includePattern);
-        builder.includeSystemModules(options.includeSystemModulePattern);
 
+        // target filters
         builder.filter(options.filterSamePackage, options.filterSameArchive);
         builder.findJDKInternals(options.findJDKInternals);
 
@@ -1044,11 +1037,6 @@
         if (options.filterRegex != null)
             builder.filter(options.filterRegex);
 
-        // check if system module is set
-        config.rootModules().stream()
-              .map(Module::name)
-              .forEach(builder::includeIfSystemModule);
-
         return builder.build();
     }
 
@@ -1162,7 +1150,6 @@
         Set<String> packageNames = new HashSet<>();
         Pattern regex;             // apply to the dependences
         Pattern includePattern;
-        Pattern includeSystemModulePattern;
         boolean inverse = false;
         boolean compileTimeView = false;
         String systemModulePath = System.getProperty("java.home");
@@ -1173,8 +1160,7 @@
         Runtime.Version multiRelease;
 
         boolean hasSourcePath() {
-            return !addmods.isEmpty() || includePattern != null ||
-                        includeSystemModulePattern != null;
+            return !addmods.isEmpty() || includePattern != null;
         }
 
         boolean hasFilter() {
--- a/langtools/test/tools/jdeps/lib/JdepsUtil.java	Mon Dec 19 11:15:01 2016 -0800
+++ b/langtools/test/tools/jdeps/lib/JdepsUtil.java	Mon Dec 19 12:30:39 2016 -0800
@@ -147,11 +147,6 @@
             return this;
         }
 
-        public Command includeSystemMoudles(String regex) {
-            filter.includeSystemModules(Pattern.compile(regex));
-            return this;
-        }
-
         public Command apiOnly() {
             this.apiOnly = true;
             return this;