langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java
changeset 39101 fd8a6392b7ea
parent 38532 24f77d64bb1f
child 40308 274367a99f98
equal deleted inserted replaced
39100:5dc24593e3ae 39101:fd8a6392b7ea
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package com.sun.tools.jdeps;
    26 package com.sun.tools.jdeps;
    27 
    27 
    28 import static com.sun.tools.jdeps.Analyzer.NOT_FOUND;
       
    29 import static com.sun.tools.jdeps.Analyzer.REMOVED_JDK_INTERNALS;
       
    30 import static com.sun.tools.jdeps.Analyzer.Type.*;
    28 import static com.sun.tools.jdeps.Analyzer.Type.*;
    31 import static com.sun.tools.jdeps.JdepsWriter.*;
    29 import static com.sun.tools.jdeps.JdepsWriter.*;
    32 import static com.sun.tools.jdeps.JdepsConfiguration.ALL_MODULE_PATH;
       
    33 
    30 
    34 import java.io.IOException;
    31 import java.io.IOException;
    35 import java.io.PrintWriter;
    32 import java.io.PrintWriter;
    36 import java.lang.module.ResolutionException;
    33 import java.lang.module.ResolutionException;
    37 import java.nio.file.Files;
    34 import java.nio.file.Files;
    38 import java.nio.file.Path;
    35 import java.nio.file.Path;
    39 import java.nio.file.Paths;
    36 import java.nio.file.Paths;
    40 import java.text.MessageFormat;
    37 import java.text.MessageFormat;
    41 import java.util.ArrayList;
    38 import java.util.*;
    42 import java.util.Comparator;
       
    43 import java.util.Deque;
       
    44 import java.util.HashSet;
       
    45 import java.util.List;
       
    46 import java.util.Locale;
       
    47 import java.util.Map;
       
    48 import java.util.MissingResourceException;
       
    49 import java.util.ResourceBundle;
       
    50 import java.util.Set;
       
    51 import java.util.function.Function;
       
    52 import java.util.regex.Pattern;
    39 import java.util.regex.Pattern;
    53 import java.util.stream.Collectors;
    40 import java.util.stream.Collectors;
    54 import java.util.stream.Stream;
    41 import java.util.stream.Stream;
    55 
    42 
    56 /**
    43 /**
   596                 .skippedEntries().stream()
   583                 .skippedEntries().stream()
   597                 .forEach(name -> warning("warn.skipped.entry",
   584                 .forEach(name -> warning("warn.skipped.entry",
   598                                          name, archive.getPathName())));
   585                                          name, archive.getPathName())));
   599 
   586 
   600         if (options.findJDKInternals && !options.nowarning) {
   587         if (options.findJDKInternals && !options.nowarning) {
   601             Map<String, String> jdkInternals = analyzer.dependences()
   588             Map<String, String> jdkInternals = new TreeMap<>();
   602                 .collect(Collectors.toMap(Function.identity(), this::replacementFor));
   589             Set<String> deps = analyzer.dependences();
       
   590             // find the ones with replacement
       
   591             deps.forEach(cn -> replacementFor(cn).ifPresent(
       
   592                 repl -> jdkInternals.put(cn, repl))
       
   593             );
       
   594 
       
   595             if (!deps.isEmpty()) {
       
   596                 log.println();
       
   597                 warning("warn.replace.useJDKInternals", getMessage("jdeps.wiki.url"));
       
   598             }
   603 
   599 
   604             if (!jdkInternals.isEmpty()) {
   600             if (!jdkInternals.isEmpty()) {
   605                 log.println();
   601                 log.println();
   606                 warning("warn.replace.useJDKInternals", getMessage("jdeps.wiki.url"));
   602                 log.format("%-40s %s%n", "JDK Internal API", "Suggested Replacement");
   607 
   603                 log.format("%-40s %s%n", "----------------", "---------------------");
   608                 if (jdkInternals.values().stream().anyMatch(repl -> repl != null)) {
   604                 jdkInternals.entrySet().stream()
   609                     log.println();
   605                     .forEach(e -> {
   610                     log.format("%-40s %s%n", "JDK Internal API", "Suggested Replacement");
   606                         String key = e.getKey();
   611                     log.format("%-40s %s%n", "----------------", "---------------------");
   607                         String[] lines = e.getValue().split("\\n");
   612                         jdkInternals.entrySet().stream()
   608                         for (String s : lines) {
   613                             .filter(e -> e.getValue() != null)
   609                             log.format("%-40s %s%n", key, s);
   614                             .sorted(Map.Entry.comparingByKey())
   610                             key = "";
   615                             .forEach(e -> log.format("%-40s %s%n", e.getKey(), e.getValue()));
   611                         }
   616                 }
   612                     });
   617             }
   613             }
   618 
       
   619         }
   614         }
   620         return ok;
   615         return ok;
   621     }
   616     }
   622 
   617 
   623     private boolean analyzeInverseDeps(JdepsConfiguration config) throws IOException {
   618     private boolean analyzeInverseDeps(JdepsConfiguration config) throws IOException {
   885 
   880 
   886     /**
   881     /**
   887      * Returns the recommended replacement API for the given classname;
   882      * Returns the recommended replacement API for the given classname;
   888      * or return null if replacement API is not known.
   883      * or return null if replacement API is not known.
   889      */
   884      */
   890     private String replacementFor(String cn) {
   885     private Optional<String> replacementFor(String cn) {
   891         String name = cn;
   886         String name = cn;
   892         String value = null;
   887         String value = null;
   893         while (value == null && name != null) {
   888         while (value == null && name != null) {
   894             try {
   889             try {
   895                 value = ResourceBundleHelper.jdkinternals.getString(name);
   890                 value = ResourceBundleHelper.jdkinternals.getString(name);
   897                 // go up one subpackage level
   892                 // go up one subpackage level
   898                 int i = name.lastIndexOf('.');
   893                 int i = name.lastIndexOf('.');
   899                 name = i > 0 ? name.substring(0, i) : null;
   894                 name = i > 0 ? name.substring(0, i) : null;
   900             }
   895             }
   901         }
   896         }
   902         return value;
   897         return Optional.ofNullable(value);
   903     }
   898     }
   904 }
   899 }