< prev index next >

src/jdk.jdeps/share/classes/com/sun/tools/jdeps/DepsAnalyzer.java

Print this page

        

@@ -26,10 +26,11 @@
 package com.sun.tools.jdeps;
 
 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;
 import java.util.List;
 import java.util.Optional;

@@ -89,11 +90,11 @@
 
         // if -include pattern is specified, add the matching archives on
         // 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);
         }
 
         // class path archives
         configuration.classPathArchives().stream()

@@ -159,18 +160,18 @@
      * If --require is set, they should be excluded.
      */
     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(source -> !filter.requiresFilter().contains(source.getName()))
+                .filter(this::include)
                 .filter(source ->
                         source.getDependencies()
                               .map(finder::locationToArchive)
                               .anyMatch(a -> a != source))
                 .collect(Collectors.toSet());

@@ -195,11 +196,10 @@
     private Set<Archive> unresolvedArchives(Stream<Location> locations) {
         return locations.filter(l -> !finder.isParsed(l))
                         .distinct()
                         .map(configuration::findClass)
                         .flatMap(Optional::stream)
-                        .filter(filter::include)
                         .collect(toSet());
     }
 
     /*
      * Recursively analyzes entire module/archives.

@@ -227,20 +227,21 @@
      */
     private void transitiveDeps(int depth) throws IOException {
         Stream<Location> deps = archives.stream()
                                         .flatMap(Archive::getDependencies);
 
+        Collection<Module> modules = configuration.getModules().values();
         Deque<Location> unresolved = deps.collect(Collectors.toCollection(LinkedList::new));
         ConcurrentLinkedDeque<Location> deque = new ConcurrentLinkedDeque<>();
         do {
             Location target;
             while ((target = unresolved.poll()) != null) {
                 if (finder.isParsed(target))
                     continue;
 
                 Archive archive = configuration.findClass(target).orElse(null);
-                if (archive != null && filter.include(archive)) {
+                if (archive != null) {
                     archives.add(archive);
 
                     String name = target.getName();
                     Set<Location> targets = apiOnly
                             ? finder.parseExportedAPIs(archive, name)

@@ -255,10 +256,23 @@
             unresolved = deque;
             deque = new ConcurrentLinkedDeque<>();
         } while (!unresolved.isEmpty() && depth-- > 0);
     }
 
+    /*
+     * Tests if the given archive is requested for analysis.
+     * It includes the root modules specified in --module, --add-modules and
+     * dependences specified in --require
+     */
+    public boolean include(Archive source) {
+        Module module = source.getModule();
+        // skip system module by default
+        return  !module.isSystem()
+                    || configuration.rootModules().contains(source)
+                    || filter.requiresFilter().contains(module.name());
+    }
+
     // ----- for testing purpose -----
 
     public static enum Info {
         REQUIRES,
         REQUIRES_TRANSITIVE,
< prev index next >