< prev index next >

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

Print this page

        

@@ -355,10 +355,15 @@
                     throw new BadArgs("err.command.set", task.command, opt);
                 }
                 task.command = task.listModuleDeps(CommandOption.PRINT_MODULE_DEPS);
             }
         },
+        new Option(false, "--ignore-missing-deps") {
+            void process(JdepsTask task, String opt, String arg) {
+                task.options.ignoreMissingDeps = true;
+            }
+        },
 
         // ---- Target filtering options ----
         new Option(true, "-p", "-package", "--package") {
             void process(JdepsTask task, String opt, String arg) {
                 task.options.packageNames.add(arg);

@@ -399,10 +404,15 @@
                         task.options.filterSamePackage = false;
                         break;
                 }
             }
         },
+        new Option(false, "--missing-deps") {
+            void process(JdepsTask task, String opt, String arg) {
+                task.options.findMissingDeps = true;
+            }
+        },
 
         // ---- Source filtering options ----
         new Option(true, "-include") {
             void process(JdepsTask task, String opt, String arg) throws BadArgs {
                 task.options.includePattern = Pattern.compile(arg);

@@ -609,10 +619,15 @@
         }
         return new GenModuleInfo(dir, openModule);
     }
 
     private ListModuleDeps listModuleDeps(CommandOption option) throws BadArgs {
+        // no need to record the dependences on the same archive or same package
+        options.filterSameArchive = true;
+        options.filterSamePackage = true;
+        // do transitive dependence analysis
+        options.depth = 0;
         switch (option) {
             case LIST_DEPS:
                 return new ListModuleDeps(option, true, false);
             case LIST_REDUCED_DEPS:
                 return new ListModuleDeps(option, true, true);

@@ -675,20 +690,20 @@
             super(option);
         }
 
         @Override
         boolean checkOptions() {
-            if (options.findJDKInternals) {
+            if (options.findJDKInternals || options.findMissingDeps) {
                 // cannot set any filter, -verbose and -summary option
                 if (options.showSummary || options.verbose != null) {
                     reportError("err.invalid.options", "-summary or -verbose",
-                                "-jdkinternals");
+                        options.findJDKInternals ? "-jdkinternals" : "--missing-deps");
                     return false;
                 }
                 if (options.hasFilter()) {
                     reportError("err.invalid.options", "--package, --regex, --require",
-                                "-jdkinternals");
+                        options.findJDKInternals ? "-jdkinternals" : "--missing-deps");
                     return false;
                 }
             }
             if (options.showSummary) {
                 // -summary cannot use with -verbose option

@@ -713,11 +728,11 @@
          */
         Type getAnalyzerType() {
             if (options.showSummary)
                 return Type.SUMMARY;
 
-            if (options.findJDKInternals)
+            if (options.findJDKInternals || options.findMissingDeps)
                 return Type.CLASS;
 
             // default to package-level verbose
            return options.verbose != null ? options.verbose : PACKAGE;
         }

@@ -923,16 +938,11 @@
                  = new ModuleInfoBuilder(config, inputArgs, dir, openModule);
             boolean ok = builder.run();
 
             if (!ok && !options.nowarning) {
                 reportError("err.missing.dependences");
-                builder.visitMissingDeps(
-                        (origin, originArchive, target, targetArchive) -> {
-                            if (builder.notFound(targetArchive))
-                                log.format("   %-50s -> %-50s %s%n",
-                                    origin, target, targetArchive.getName());
-                        });
+                builder.visitMissingDeps(new SimpleDepVisitor());
             }
             return ok;
         }
 
         private String toPackageName(String name) {

@@ -991,17 +1001,19 @@
         }
 
         @Override
         boolean checkOptions() {
             if (options.showSummary || options.verbose != null) {
-                reportError("err.invalid.options", "-summary or -verbose",
-                            option);
+                reportError("err.invalid.options", "-summary or -verbose", option);
                 return false;
             }
             if (options.findJDKInternals) {
-                reportError("err.invalid.options", "-jdkinternals",
-                            option);
+                reportError("err.invalid.options", "-jdkinternals", option);
+                return false;
+            }
+            if (options.findMissingDeps) {
+                reportError("err.invalid.options", "--missing-deps", option);
                 return false;
             }
 
             if (!inputArgs.isEmpty() && !options.rootModules.isEmpty()) {
                 reportError("err.invalid.arg.for.option", "-m");

@@ -1013,20 +1025,26 @@
             return true;
         }
 
         @Override
         boolean run(JdepsConfiguration config) throws IOException {
-            return new ModuleExportsAnalyzer(config,
+            ModuleExportsAnalyzer analyzer = new ModuleExportsAnalyzer(config,
                                              dependencyFilter(config),
                                              jdkinternals,
                                              reduced,
                                              log,
-                                             separator).run();
+                                                                       separator);
+            boolean ok = analyzer.run(options.depth, options.ignoreMissingDeps);
+            if (!ok) {
+                reportError("err.cant.list.module.deps");
+                log.println();
+                analyzer.visitMissingDeps(new SimpleDepVisitor());
+            }
+            return ok;
         }
     }
 
-
     class GenDotFile extends AnalyzeDeps {
         final Path dotOutputDir;
         GenDotFile(Path dotOutputDir) {
             super(CommandOption.GENERATE_DOT_FILE);
 

@@ -1051,10 +1069,22 @@
                                                    options.showLabel);
             return run(config, writer, type);
         }
     }
 
+    class SimpleDepVisitor implements Analyzer.Visitor {
+        private Archive source;
+        @Override
+        public void visitDependence(String origin, Archive originArchive, String target, Archive targetArchive) {
+            if (source != originArchive) {
+                source = originArchive;
+                log.format("%s%n", originArchive);
+            }
+            log.format("   %-50s -> %-50s %s%n", origin, target, targetArchive.getName());
+        }
+    }
+
     /**
      * Returns a filter used during dependency analysis
      */
     private JdepsFilter dependencyFilter(JdepsConfiguration config) {
         // Filter specified by -filter, -package, -regex, and --require options

@@ -1064,10 +1094,11 @@
         builder.includePattern(options.includePattern);
 
         // target filters
         builder.filter(options.filterSamePackage, options.filterSameArchive);
         builder.findJDKInternals(options.findJDKInternals);
+        builder.findMissingDeps(options.findMissingDeps);
 
         // --require
         if (!options.requires.isEmpty()) {
             options.requires.stream()
                 .forEach(mn -> {

@@ -1156,23 +1187,20 @@
     }
 
     private String version(String key) {
         // key=version:  mm.nn.oo[-milestone]
         // key=full:     mm.mm.oo[-milestone]-build
-        if (ResourceBundleHelper.versionRB == null) {
-            return System.getProperty("java.version");
-        }
         try {
-            return ResourceBundleHelper.versionRB.getString(key);
+            return ResourceBundleHelper.getVersion(key);
         } catch (MissingResourceException e) {
             return getMessage("version.unknown", System.getProperty("java.version"));
         }
     }
 
     static String getMessage(String key, Object... args) {
         try {
-            return MessageFormat.format(ResourceBundleHelper.bundle.getString(key), args);
+            return MessageFormat.format(ResourceBundleHelper.getMessage(key), args);
         } catch (MissingResourceException e) {
             throw new InternalError("Missing message: " + key);
         }
     }
 

@@ -1184,10 +1212,12 @@
         boolean showModule = true;
         boolean showSummary;
         boolean apiOnly;
         boolean showLabel;
         boolean findJDKInternals;
+        boolean findMissingDeps;
+        boolean ignoreMissingDeps;
         boolean nowarning = false;
         Analyzer.Type verbose;
         // default filter references from same package
         boolean filterSamePackage = true;
         boolean filterSameArchive = false;

@@ -1223,10 +1253,11 @@
             return count;
         }
     }
 
     private static class ResourceBundleHelper {
+        static final String LS = System.lineSeparator();
         static final ResourceBundle versionRB;
         static final ResourceBundle bundle;
         static final ResourceBundle jdkinternals;
 
         static {

@@ -1245,10 +1276,25 @@
                 jdkinternals = ResourceBundle.getBundle("com.sun.tools.jdeps.resources.jdkinternals");
             } catch (MissingResourceException e) {
                 throw new InternalError("Cannot find jdkinternals resource bundle");
             }
         }
+
+        static String getMessage(String key) {
+            return bundle.getString(key).replace("\n", LS);
+        }
+
+        static String getVersion(String key) {
+            if (ResourceBundleHelper.versionRB == null) {
+                return System.getProperty("java.version");
+            }
+            return versionRB.getString(key).replace("\n", LS);
+        }
+
+        static String getSuggestedReplacement(String key) {
+            return ResourceBundleHelper.jdkinternals.getString(key).replace("\n", LS);
+        }
     }
 
     /**
      * Returns the recommended replacement API for the given classname;
      * or return null if replacement API is not known.

@@ -1256,11 +1302,11 @@
     private Optional<String> replacementFor(String cn) {
         String name = cn;
         String value = null;
         while (value == null && name != null) {
             try {
-                value = ResourceBundleHelper.jdkinternals.getString(name);
+                value = ResourceBundleHelper.getSuggestedReplacement(name);
             } catch (MissingResourceException e) {
                 // go up one subpackage level
                 int i = name.lastIndexOf('.');
                 name = i > 0 ? name.substring(0, i) : null;
             }
< prev index next >